Illegal, Karen, better ping

This commit is contained in:
Daniel Odendahl Jr
2018-03-19 22:41:40 +00:00
parent 3842db73a1
commit 1877c53674
8 changed files with 92 additions and 6 deletions
+1 -2
View File
@@ -15,8 +15,7 @@ module.exports = class FaceAnalyzeCommand extends Command {
{
key: 'face',
prompt: 'What face do you want to scan?',
type: 'image',
default: msg => msg.author.displayAvatarURL({ format: 'png', size: 512 })
type: 'image'
}
]
});
+60
View File
@@ -0,0 +1,60 @@
const { Command } = require('discord.js-commando');
const { createCanvas, loadImage, registerFont } = require('canvas');
const { stripIndents } = require('common-tags');
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 {
constructor(client) {
super(client, {
name: 'illegal',
aliases: ['is-now-illegal', 'trump', 'first-order-of-business'],
group: 'image-edit',
memberName: 'illegal',
description: 'Makes President Trump make your text illegal.',
throttling: {
usages: 1,
duration: 10
},
clientPermissions: ['ATTACH_FILES'],
args: [
{
key: 'text',
prompt: 'What should the text of the bill be?',
type: 'string',
parse: text => text.toUpperCase()
},
{
key: 'isOrAre',
label: 'is or are',
prompt: 'Should the text use is or are?',
type: 'string',
default: 'is',
validate: isOrAre => {
if (['is', 'are'].includes(isOrAre.toLowerCase())) return true;
return 'Invalid is or are, please enter either is or are.';
},
parse: isOrAre => isOrAre.toUpperCase()
}
]
});
}
async run(msg, { text, isOrAre }) {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'illegal.png'));
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(base, 0, 0);
ctx.rotate(7 * (Math.PI / 180));
ctx.font = '37px Noto';
ctx.fillText(stripIndents`
${shortenText(ctx, text, 215)}
${isOrAre} NOW
ILLEGAL.
`, 690, 350);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'illegal.png' }] });
}
};
+24
View File
@@ -0,0 +1,24 @@
const { Command } = require('discord.js-commando');
const { randomFromImgurAlbum } = require('../../util/Util');
module.exports = class KarenCommand extends Command {
constructor(client) {
super(client, {
name: 'karen',
aliases: ['ayaya'],
group: 'random',
memberName: 'karen',
description: 'Responds with a random image of Karen.',
clientPermissions: ['ATTACH_FILES']
});
}
async run(msg) {
try {
const karen = await randomFromImgurAlbum('3oLAP');
return msg.say({ files: [karen] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+2 -2
View File
@@ -21,8 +21,8 @@ module.exports = class HTTPCatCommand extends Command {
async run(msg, { code }) {
try {
const { body, text } = await snekfetch.get(`https://http.cat/${code}.jpg`);
if (text.startsWith('<!DOCTYPE html>')) return msg.say('Could not find any results.');
const { body, headers } = await snekfetch.get(`https://http.cat/${code}.jpg`);
if (headers['content-type'] === 'text/html') return msg.say('Could not find any results.');
return msg.say({ files: [{ attachment: body, name: `${code}.jpg` }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+2 -1
View File
@@ -15,8 +15,9 @@ module.exports = class PingCommand extends Command {
async run(msg) {
const message = await msg.say('Pinging...');
const ping = Math.round(message.createdTimestamp - msg.createdTimestamp);
return message.edit(stripIndents`
🏓 Pong! \`${Math.round(message.createdTimestamp - msg.createdTimestamp)}ms\`
🏓 P${'o'.repeat(Math.ceil(ping / 100))}ng! \`${ping}ms\`
Heartbeat: \`${Math.round(this.client.ping)}ms\`
`);
}