Illegal is now a GIF

This commit is contained in:
Daniel Odendahl Jr
2018-04-11 22:26:14 +00:00
parent 5c1d5f33c2
commit fb2f7feb15
3 changed files with 24 additions and 29 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 616 KiB

+23 -28
View File
@@ -1,11 +1,6 @@
const { Command } = require('discord.js-commando'); const { Command } = require('discord.js-commando');
const { createCanvas, loadImage, registerFont } = require('canvas'); const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags'); const { wait } = require('../../util/Util');
const path = require('path');
const { shortenText } = require('../../util/Canvas');
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Regular.ttf'), { family: 'Noto' });
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-CJK.otf'), { family: 'Noto' });
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto-Emoji.ttf'), { family: 'Noto' });
module.exports = class IllegalCommand extends Command { module.exports = class IllegalCommand extends Command {
constructor(client) { constructor(client) {
@@ -25,32 +20,32 @@ module.exports = class IllegalCommand extends Command {
key: 'text', key: 'text',
prompt: 'What should the text of the bill be?', prompt: 'What should the text of the bill be?',
type: 'string', type: 'string',
validate: text => {
if (/^[a-zA-Z0-9 ]+$/g.test(text) && text.length > 11) return true;
return 'Invalid text, please enter 10 or fewer basic unicode characters (A-Z, 0-9).';
},
parse: text => text.toUpperCase() parse: text => text.toUpperCase()
},
{
key: 'verb',
prompt: 'Should the text use is, are, or am?',
type: 'string',
default: 'IS',
oneOf: ['is', 'are', 'am'],
parse: verb => verb.toUpperCase()
} }
] ]
}); });
} }
async run(msg, { text, verb }) { async run(msg, { text }) {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'illegal.png')); try {
const canvas = createCanvas(base.width, base.height); await snekfetch
const ctx = canvas.getContext('2d'); .post('https://is-now-illegal.firebaseio.com/queue/tasks.json')
ctx.drawImage(base, 0, 0); .send({
ctx.rotate(7 * (Math.PI / 180)); task: 'gif',
ctx.font = '45px Noto'; word: text
ctx.fillText(stripIndents` });
${shortenText(ctx, text, 200)} await msg.say('Trump is busy signing the bill, please wait 5 seconds...');
${verb} NOW await wait(5000);
ILLEGAL. const { body } = await snekfetch
`, 750, 290); .get(`https://is-now-illegal.firebaseio.com/gifs/${text}.json`);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'illegal.png' }] }); if (!body) return msg.reply('Trump failed to sign the bill.');
return msg.say({ files: [body.url] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
} }
}; };
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "71.2.0", "version": "72.0.0",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {