mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-11 11:21:16 +02:00
Improve cow-say, add cow-think
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const cowsay = require('cowsay');
|
||||
const cowList = require('cowsay/lib/cows');
|
||||
const { list } = require('../../util/Util');
|
||||
const cows = cowList.listSync();
|
||||
cows.push('random');
|
||||
|
||||
module.exports = class CowSayCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -8,28 +12,37 @@ module.exports = class CowSayCommand extends Command {
|
||||
group: 'text-edit',
|
||||
memberName: 'cow-say',
|
||||
description: 'Makes a cow say your text.',
|
||||
details: `**Types**: ${cows.join(', ')}`,
|
||||
args: [
|
||||
{
|
||||
key: 'text',
|
||||
prompt: 'What text would you like the cow to say?',
|
||||
type: 'string',
|
||||
max: 1500
|
||||
},
|
||||
{
|
||||
key: 'type',
|
||||
prompt: `What type of cow would you like to use? Either ${list(cows, 'or')}.`,
|
||||
type: 'string',
|
||||
default: 'default',
|
||||
validate: type => {
|
||||
if (cows.includes(type.toLowerCase()) || type.toLowerCase() === 'cow') return true;
|
||||
return `Invalid type, please enter either ${list(cows, 'or')}.`;
|
||||
},
|
||||
parse: type => {
|
||||
if (type.toLowerCase() === 'cow') return 'default';
|
||||
return type.toLowerCase();
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { text }) {
|
||||
try {
|
||||
const { body } = await request
|
||||
.get('http://cowsay.morecode.org/say')
|
||||
.query({
|
||||
message: text,
|
||||
format: 'json'
|
||||
});
|
||||
return msg.code(null, body.cow);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
run(msg, { text, type }) {
|
||||
return msg.code(null, cowsay.say({
|
||||
text,
|
||||
f: type,
|
||||
r: type === 'random'
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const cowsay = require('cowsay');
|
||||
const cowList = require('cowsay/lib/cows');
|
||||
const { list } = require('../../util/Util');
|
||||
const cows = cowList.listSync();
|
||||
cows.push('random');
|
||||
|
||||
module.exports = class CowThinkCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'cow-think',
|
||||
group: 'text-edit',
|
||||
memberName: 'cow-think',
|
||||
description: 'Makes a cow think your text.',
|
||||
details: `**Types**: ${cows.join(', ')}`,
|
||||
args: [
|
||||
{
|
||||
key: 'text',
|
||||
prompt: 'What text would you like the cow to think?',
|
||||
type: 'string',
|
||||
max: 1500
|
||||
},
|
||||
{
|
||||
key: 'type',
|
||||
prompt: `What type of cow would you like to use? Either ${list(cows, 'or')}.`,
|
||||
type: 'string',
|
||||
default: 'default',
|
||||
validate: type => {
|
||||
if (cows.includes(type.toLowerCase()) || type.toLowerCase() === 'cow') return true;
|
||||
return `Invalid type, please enter either ${list(cows, 'or')}.`;
|
||||
},
|
||||
parse: type => {
|
||||
if (type.toLowerCase() === 'cow') return 'default';
|
||||
return type.toLowerCase();
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { text, type }) {
|
||||
return msg.code(null, cowsay.think({
|
||||
text,
|
||||
f: type,
|
||||
r: type === 'random'
|
||||
}));
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user