mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Fix lots of code dupe
This commit is contained in:
@@ -20,7 +20,8 @@ module.exports = class GenderCommand extends Command {
|
||||
{
|
||||
key: 'name',
|
||||
prompt: 'What name do you want to determine the gender of?',
|
||||
type: 'string'
|
||||
type: 'string',
|
||||
max: 20
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
@@ -53,13 +53,7 @@ module.exports = class AceAttorneyCommand extends Command {
|
||||
prompt: `What character do you want to use? Either ${list(Object.keys(characters), 'or')}.`,
|
||||
type: 'string',
|
||||
oneOf: Object.values(characters).reduce((a, b) => a.concat(b)),
|
||||
parse: character => {
|
||||
for (const [id, arr] of Object.entries(characters)) {
|
||||
if (!arr.includes(character.toLowerCase())) continue;
|
||||
return id;
|
||||
}
|
||||
return character.toLowerCase();
|
||||
}
|
||||
parse: character => character.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'quote',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const gm = require('gm').subClass({ imageMagick: true });
|
||||
const request = require('node-superfetch');
|
||||
const { magikToBuffer } = require('../../util/Util');
|
||||
|
||||
module.exports = class CharcoalCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -38,20 +39,11 @@ module.exports = class CharcoalCommand extends Command {
|
||||
const magik = gm(body);
|
||||
magik.charcoal(1);
|
||||
magik.setFormat('png');
|
||||
const attachment = await this.toBuffer(magik);
|
||||
const attachment = await magikToBuffer(magik);
|
||||
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||
return msg.say({ files: [{ attachment, name: 'sketch.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
toBuffer(magik) {
|
||||
return new Promise((res, rej) => {
|
||||
magik.toBuffer((err, buffer) => {
|
||||
if (err) return rej(err);
|
||||
return res(buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const gm = require('gm').subClass({ imageMagick: true });
|
||||
const request = require('node-superfetch');
|
||||
const { magikToBuffer } = require('../../util/Util');
|
||||
|
||||
module.exports = class EmbossCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -38,20 +39,11 @@ module.exports = class EmbossCommand extends Command {
|
||||
const magik = gm(body);
|
||||
magik.emboss();
|
||||
magik.setFormat('png');
|
||||
const attachment = await this.toBuffer(magik);
|
||||
const attachment = await magikToBuffer(magik);
|
||||
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||
return msg.say({ files: [{ attachment, name: 'emboss.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
toBuffer(magik) {
|
||||
return new Promise((res, rej) => {
|
||||
magik.toBuffer((err, buffer) => {
|
||||
if (err) return rej(err);
|
||||
return res(buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const gm = require('gm').subClass({ imageMagick: true });
|
||||
const request = require('node-superfetch');
|
||||
const { magikToBuffer } = require('../../util/Util');
|
||||
|
||||
module.exports = class ImplodeCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -45,20 +46,11 @@ module.exports = class ImplodeCommand extends Command {
|
||||
const magik = gm(body);
|
||||
magik.implode(level / 100);
|
||||
magik.setFormat('png');
|
||||
const attachment = await this.toBuffer(magik);
|
||||
const attachment = await magikToBuffer(magik);
|
||||
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||
return msg.say({ files: [{ attachment, name: 'implode.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
toBuffer(magik) {
|
||||
return new Promise((res, rej) => {
|
||||
magik.toBuffer((err, buffer) => {
|
||||
if (err) return rej(err);
|
||||
return res(buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const gm = require('gm').subClass({ imageMagick: true });
|
||||
const request = require('node-superfetch');
|
||||
const { magikToBuffer } = require('../../util/Util');
|
||||
|
||||
module.exports = class LiquidRescaleCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -41,20 +42,11 @@ module.exports = class LiquidRescaleCommand extends Command {
|
||||
magik.out('50%');
|
||||
magik.implode(0.25);
|
||||
magik.setFormat('png');
|
||||
const attachment = await this.toBuffer(magik);
|
||||
const attachment = await magikToBuffer(magik);
|
||||
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||
return msg.say({ files: [{ attachment, name: 'liquid-rescale.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
toBuffer(magik) {
|
||||
return new Promise((res, rej) => {
|
||||
magik.toBuffer((err, buffer) => {
|
||||
if (err) return rej(err);
|
||||
return res(buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const gm = require('gm').subClass({ imageMagick: true });
|
||||
const request = require('node-superfetch');
|
||||
const { list } = require('../../util/Util');
|
||||
const { list, magikToBuffer } = require('../../util/Util');
|
||||
const types = ['uniform', 'gaussian', 'multiplicative', 'impulse', 'laplacian', 'poisson'];
|
||||
|
||||
module.exports = class NoiseCommand extends Command {
|
||||
@@ -48,20 +48,11 @@ module.exports = class NoiseCommand extends Command {
|
||||
const magik = gm(body);
|
||||
magik.noise(type);
|
||||
magik.setFormat('png');
|
||||
const attachment = await this.toBuffer(magik);
|
||||
const attachment = await magikToBuffer(magik);
|
||||
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||
return msg.say({ files: [{ attachment, name: 'noise.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
toBuffer(magik) {
|
||||
return new Promise((res, rej) => {
|
||||
magik.toBuffer((err, buffer) => {
|
||||
if (err) return rej(err);
|
||||
return res(buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const gm = require('gm').subClass({ imageMagick: true });
|
||||
const request = require('node-superfetch');
|
||||
const { magikToBuffer } = require('../../util/Util');
|
||||
|
||||
module.exports = class OilPaintingCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -39,20 +40,11 @@ module.exports = class OilPaintingCommand extends Command {
|
||||
const magik = gm(body);
|
||||
magik.paint(5);
|
||||
magik.setFormat('png');
|
||||
const attachment = await this.toBuffer(magik);
|
||||
const attachment = await magikToBuffer(magik);
|
||||
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||
return msg.say({ files: [{ attachment, name: 'old-painting.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
toBuffer(magik) {
|
||||
return new Promise((res, rej) => {
|
||||
magik.toBuffer((err, buffer) => {
|
||||
if (err) return rej(err);
|
||||
return res(buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const gm = require('gm').subClass({ imageMagick: true });
|
||||
const request = require('node-superfetch');
|
||||
const { magikToBuffer } = require('../../util/Util');
|
||||
|
||||
module.exports = class SketchCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -41,20 +42,11 @@ module.exports = class SketchCommand extends Command {
|
||||
magik.out('-sketch');
|
||||
magik.out('0x20+120');
|
||||
magik.setFormat('png');
|
||||
const attachment = await this.toBuffer(magik);
|
||||
const attachment = await magikToBuffer(magik);
|
||||
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||
return msg.say({ files: [{ attachment, name: 'sketch.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
toBuffer(magik) {
|
||||
return new Promise((res, rej) => {
|
||||
magik.toBuffer((err, buffer) => {
|
||||
if (err) return rej(err);
|
||||
return res(buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const gm = require('gm').subClass({ imageMagick: true });
|
||||
const request = require('node-superfetch');
|
||||
const { magikToBuffer } = require('../../util/Util');
|
||||
|
||||
module.exports = class SquishCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -50,20 +51,11 @@ module.exports = class SquishCommand extends Command {
|
||||
magik.out('-liquid-rescale');
|
||||
magik.out(command);
|
||||
magik.setFormat('png');
|
||||
const attachment = await this.toBuffer(magik);
|
||||
const attachment = await magikToBuffer(magik);
|
||||
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||
return msg.say({ files: [{ attachment, name: 'squish.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
toBuffer(magik) {
|
||||
return new Promise((res, rej) => {
|
||||
magik.toBuffer((err, buffer) => {
|
||||
if (err) return rej(err);
|
||||
return res(buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const gm = require('gm').subClass({ imageMagick: true });
|
||||
const request = require('node-superfetch');
|
||||
const { magikToBuffer } = require('../../util/Util');
|
||||
|
||||
module.exports = class SwirlCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -45,20 +46,11 @@ module.exports = class SwirlCommand extends Command {
|
||||
const magik = gm(body);
|
||||
magik.swirl(degrees);
|
||||
magik.setFormat('png');
|
||||
const attachment = await this.toBuffer(magik);
|
||||
const attachment = await magikToBuffer(magik);
|
||||
if (Buffer.byteLength(attachment) > 8e+6) return msg.reply('Resulting image was above 8 MB.');
|
||||
return msg.say({ files: [{ attachment, name: 'swirl.png' }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
toBuffer(magik) {
|
||||
return new Promise((res, rej) => {
|
||||
magik.toBuffer((err, buffer) => {
|
||||
if (err) return rej(err);
|
||||
return res(buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const { createCanvas, registerFont } = require('canvas');
|
||||
const path = require('path');
|
||||
const { reactIfAble } = require('../../util/Util');
|
||||
const { wrapText } = require('../../util/Canvas');
|
||||
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'OPTIKorinna-Agency.otf'), { family: 'Korinna' });
|
||||
|
||||
@@ -47,9 +48,7 @@ module.exports = class JeopardyCommand extends Command {
|
||||
const connection = msg.guild ? this.client.voice.connections.get(msg.guild.id) : null;
|
||||
if (connection) {
|
||||
connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'jeopardy.mp3'));
|
||||
if (msg.channel.permissionsFor(this.client.user).has(['ADD_REACTIONS', 'READ_MESSAGE_HISTORY'])) {
|
||||
await msg.react('🔉');
|
||||
}
|
||||
await reactIfAble(msg, this.client.user, '🔉');
|
||||
}
|
||||
await msg.reply(`The category is: **${question.category.title.toUpperCase()}**. 30 seconds, good luck.`, {
|
||||
files: [{ attachment: clueCard, name: 'clue-card.png' }]
|
||||
|
||||
@@ -107,7 +107,7 @@ module.exports = class WhosThatPokemonCommand extends Command {
|
||||
ctx.font = '60px Pokemon';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'bottom';
|
||||
ctx.lineWidth = 10;
|
||||
ctx.lineWidth = 8;
|
||||
ctx.strokeStyle = '#3c5aa6';
|
||||
ctx.strokeText(pokemon.name, 362, 158, 240);
|
||||
ctx.fillStyle = '#ffcb05';
|
||||
|
||||
@@ -14,8 +14,8 @@ module.exports = class RandomUserCommand extends Command {
|
||||
run(msg) {
|
||||
if (msg.channel.type === 'dm') {
|
||||
const members = [this.client.user, msg.channel.recipient];
|
||||
return msg.say(`I choose ${members[Math.floor(Math.random() * members.length)].username}!`);
|
||||
return msg.say(`I choose ${members[Math.floor(Math.random() * members.length)].tag}!`);
|
||||
}
|
||||
return msg.say(`I choose ${msg.guild.members.cache.random().displayName}!`);
|
||||
return msg.say(`I choose ${msg.guild.members.cache.random().user.tag}!`);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const path = require('path');
|
||||
const { reactIfAble } = require('../../util/Util');
|
||||
const sounds = require('../../assets/json/airhorn');
|
||||
|
||||
module.exports = class AirhornCommand extends Command {
|
||||
@@ -34,9 +35,7 @@ module.exports = class AirhornCommand extends Command {
|
||||
}
|
||||
const airhorn = sounds[Math.floor(Math.random() * sounds.length)];
|
||||
connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'airhorn', airhorn));
|
||||
if (msg.channel.permissionsFor(this.client.user).has(['ADD_REACTIONS', 'READ_MESSAGE_HISTORY'])) {
|
||||
await msg.react('🔉');
|
||||
}
|
||||
await reactIfAble(msg, this.client.user, '🔉');
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const { Readable } = require('stream');
|
||||
const { reactIfAble } = require('../../util/Util');
|
||||
const { LOADING_EMOJI_ID } = process.env;
|
||||
|
||||
module.exports = class DECTalkCommand extends Command {
|
||||
@@ -54,18 +55,15 @@ module.exports = class DECTalkCommand extends Command {
|
||||
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
|
||||
}
|
||||
try {
|
||||
if (msg.channel.permissionsFor(this.client.user).has(['ADD_REACTIONS', 'READ_MESSAGE_HISTORY'])) {
|
||||
await msg.react(LOADING_EMOJI_ID);
|
||||
}
|
||||
await reactIfAble(msg, this.client.user, LOADING_EMOJI_ID, '💬');
|
||||
const { body } = await request
|
||||
.get('http://tts.cyzon.us/tts')
|
||||
.query({ text });
|
||||
connection.play(Readable.from([body]));
|
||||
if (msg.channel.permissionsFor(this.client.user).has(['ADD_REACTIONS', 'READ_MESSAGE_HISTORY'])) {
|
||||
await msg.react('🔉');
|
||||
}
|
||||
await reactIfAble(msg, this.client.user, '🔉');
|
||||
return null;
|
||||
} catch (err) {
|
||||
await reactIfAble(msg, this.client.user, '⚠️');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const path = require('path');
|
||||
const { list } = require('../../util/Util');
|
||||
const { list, reactIfAble } = require('../../util/Util');
|
||||
const sounds = require('../../assets/json/soundboard');
|
||||
|
||||
module.exports = class SoundboardCommand extends Command {
|
||||
@@ -69,9 +69,7 @@ module.exports = class SoundboardCommand extends Command {
|
||||
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
|
||||
}
|
||||
connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', 'soundboard', sound));
|
||||
if (msg.channel.permissionsFor(this.client.user).has(['ADD_REACTIONS', 'READ_MESSAGE_HISTORY'])) {
|
||||
await msg.react('🔉');
|
||||
}
|
||||
await reactIfAble(msg, this.client.user, '🔉');
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const { Readable } = require('stream');
|
||||
const { list } = require('../../util/Util');
|
||||
const { list, reactIfAble } = require('../../util/Util');
|
||||
const voices = require('../../assets/json/vocodes');
|
||||
const { LOADING_EMOJI_ID } = process.env;
|
||||
|
||||
@@ -52,9 +52,7 @@ module.exports = class VocodesCommand extends Command {
|
||||
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
|
||||
}
|
||||
try {
|
||||
if (msg.channel.permissionsFor(this.client.user).has(['ADD_REACTIONS', 'READ_MESSAGE_HISTORY'])) {
|
||||
await msg.react(LOADING_EMOJI_ID);
|
||||
}
|
||||
await reactIfAble(msg, this.client.user, LOADING_EMOJI_ID, '💬');
|
||||
const { body } = await request
|
||||
.post('https://mumble.stream/speak_spectrogram')
|
||||
.send({
|
||||
@@ -62,11 +60,10 @@ module.exports = class VocodesCommand extends Command {
|
||||
text
|
||||
});
|
||||
connection.play(Readable.from([Buffer.from(body.audio_base64, 'base64')]));
|
||||
if (msg.channel.permissionsFor(this.client.user).has(['ADD_REACTIONS', 'READ_MESSAGE_HISTORY'])) {
|
||||
await msg.react('🔉');
|
||||
}
|
||||
await reactIfAble(msg, this.client.user, '🔉');
|
||||
return null;
|
||||
} catch (err) {
|
||||
await reactIfAble(msg, this.client.user, '⚠️');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "119.34.5",
|
||||
"version": "119.34.6",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -162,6 +162,15 @@ module.exports = class Util {
|
||||
return today;
|
||||
}
|
||||
|
||||
static magikToBuffer(magik) {
|
||||
return new Promise((res, rej) => {
|
||||
magik.toBuffer((err, buffer) => {
|
||||
if (err) return rej(err);
|
||||
return res(buffer);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static embedURL(title, url, display) {
|
||||
return `[${title}](${url.replaceAll(')', '%29')}${display ? ` "${display}"` : ''})`;
|
||||
}
|
||||
@@ -172,6 +181,18 @@ module.exports = class Util {
|
||||
return str;
|
||||
}
|
||||
|
||||
static async reactIfAble(msg, user, emoji, fallbackEmoji) {
|
||||
if (fallbackEmoji && !msg.channel.permissionsFor(user).has('USE_EXTERNAL_EMOJIS')) emoji = fallbackEmoji;
|
||||
if (msg.channel.permissionsFor(user).has(['ADD_REACTIONS', 'READ_MESSAGE_HISTORY'])) {
|
||||
try {
|
||||
await msg.react(emoji);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static async verify(channel, user, { time = 30000, extraYes = [], extraNo = [] } = {}) {
|
||||
const filter = res => {
|
||||
const value = res.content.toLowerCase();
|
||||
|
||||
Reference in New Issue
Block a user