Make ping quotes sequential but shuffled
This commit is contained in:
parent
f9d57ab0b6
commit
b3898a498b
@ -18,19 +18,23 @@ import { SlashCommand } from '../../../interfaces/index.js';
|
||||
import DiscordClient from '../../../DiscordClient.js';
|
||||
import InvokerWrapper from '../../wrappers/InvokerWrapper.js';
|
||||
import Quotes from '../../../../constants/Quotes.js';
|
||||
import Util from '../../../../utilities/Util.js';
|
||||
|
||||
class PingCommand extends SlashCommand
|
||||
{
|
||||
|
||||
#index: number;
|
||||
#quotes: string[][];
|
||||
constructor (client: DiscordClient)
|
||||
{
|
||||
|
||||
super(client, {
|
||||
name: 'ping',
|
||||
description: 'Ping? Pong!',
|
||||
moduleName: 'utility',
|
||||
});
|
||||
|
||||
this.#index = 0;
|
||||
this.#quotes = [ ...Quotes ];
|
||||
Util.shuffle(this.#quotes);
|
||||
}
|
||||
|
||||
async execute (invoker: InvokerWrapper)
|
||||
@ -39,11 +43,16 @@ class PingCommand extends SlashCommand
|
||||
const number = (ping / 40);
|
||||
const repeat = number > 1 ? number : 1;
|
||||
|
||||
const index = Math.floor(Quotes.length * Math.random());
|
||||
const [ quote, author ] = Quotes[index];
|
||||
if (this.#index >= this.#quotes.length)
|
||||
{
|
||||
this.#index = 0;
|
||||
Util.shuffle(this.#quotes);
|
||||
}
|
||||
|
||||
const index = this.#index++;
|
||||
const [ quote, author ] = this.#quotes[index];
|
||||
return invoker.reply(`P${'o'.repeat(repeat)}ng! \`${ping}ms\`\n\n> ${quote.replaceAll('\n', '\n> ')}\n\\- *${author}*`, { emoji: 'success' });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default PingCommand;
|
@ -196,6 +196,28 @@ class Util
|
||||
throw error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuffles array in place
|
||||
* @date 3/25/2024 - 11:25:09 AM
|
||||
*
|
||||
* @static
|
||||
* @template T
|
||||
* @param {T[]} array
|
||||
* @returns {T[]}
|
||||
*/
|
||||
static shuffle<T> (array: T[]): T[]
|
||||
{
|
||||
let current = array.length;
|
||||
let random = 0;
|
||||
while (current > 0)
|
||||
{
|
||||
random = Math.floor(Math.random() * current);
|
||||
current--;
|
||||
[ array[current], array[random] ] = [ array[random], array[current] ];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
static paginate (items: Array<unknown>, page = 1, pageLength = 10)
|
||||
{
|
||||
const maxPage = Math.ceil(items.length / pageLength);
|
||||
|
Loading…
Reference in New Issue
Block a user