My own custom yoda command

This commit is contained in:
Dragon Fire
2024-03-24 21:04:07 -04:00
parent bde997e275
commit 3c3ff6ccaa
3 changed files with 57 additions and 2 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ module.exports = class BronySpeakCommand extends Command {
constructor(client) {
super(client, {
name: 'brony-speak',
aliases: ['pony-speak', 'my-little-pony-speak', 'mlp-speak'],
aliases: ['pony-speak', 'my-little-pony-speak', 'mlp-speak', 'brony'],
group: 'edit-text',
memberName: 'brony-speak',
description: 'Converts text to brony speak.',
+55
View File
@@ -0,0 +1,55 @@
const Command = require('../../framework/Command');
const { firstUpperCase } = require('../../util/Util');
const pivots = ['is', 'be', 'will', 'show', 'do', 'try', 'are', 'teach', 'have', 'am'];
const ends = ['Hmmmmm.', 'Herh herh herh.', 'Yes, hmmm?'];
module.exports = class YodaCommand extends Command {
constructor(client) {
super(client, {
name: 'yoda',
group: 'edit-text',
memberName: 'yoda',
description: 'Converts text to Yoda speak.',
args: [
{
key: 'text',
prompt: 'What text would you like to convert to yoda speak?',
type: 'string'
}
]
});
}
run(msg, { text }) {
return msg.say(this.yodaSpeak(text));
}
yodaSpeak(text) {
const sentences = text.split(/\?|!|\./);
const newSentences = [];
for (const sentence of sentences) {
const trimmed = sentence.trim();
const breaks = trimmed.split(',');
const newBreaks = [];
for (const broke of breaks) {
let newText = [];
const pivoted = [];
const words = broke.split(' ');
for (let i = 0; i < words.length; i++) {
const clean = words[i].toLowerCase().replace(/[^a-z]/, '').trim();
if (pivots.includes(clean)) {
const fixed = newText.slice(i - 1);
newText.splice(-i);
pivoted.push(fixed, clean);
} else {
newText.push(clean);
}
}
newText = newText.map((word, i) => i === 0 ? firstUpperCase(word) : word);
newBreaks.push(`${newText.join(' ').trim()} ${pivoted.join(' ').trim()}`);
}
newSentences.push(newBreaks.join(', ').trim());
}
return `${newSentences.join('. ').trim()} ${ends[Math.floor(Math.random() * ends.length)]}`;
}
};
+1 -1
View File
@@ -33,7 +33,7 @@ module.exports = class UsElectionCommand extends Command {
canidate => `**${canidate.name}:** ${canidate.score} (${canidate.percentChange} in last day)`
);
return msg.say(stripIndents`
__**Chances of Winning the ${year} US Presidential Election (According to Betting Markets):**__
__**Chances of Winning the ${year} US Election:**__
${list.join('\n')}
_More detailed information is available at <https://electionbettingodds.com/>._