mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
My own custom yoda command
This commit is contained in:
@@ -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.',
|
||||
|
||||
@@ -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)]}`;
|
||||
}
|
||||
};
|
||||
@@ -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/>._
|
||||
|
||||
Reference in New Issue
Block a user