Demotivational Poster Command

This commit is contained in:
Daniel Odendahl Jr
2017-11-10 13:55:25 +00:00
parent e103d71c50
commit 79bed46c1d
8 changed files with 87 additions and 5 deletions
+1
View File
@@ -12,3 +12,4 @@
*.png binary
*.mp3 binary
*.ttf binary
*.otf binary
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

+4 -1
View File
@@ -1,9 +1,12 @@
const { Command } = require('discord.js-commando');
const { createCanvas, loadImage } = require('canvas');
const { createCanvas, loadImage, registerFont } = require('canvas');
const snekfetch = require('snekfetch');
const path = require('path');
const { randomRange } = require('../../util/Util');
const { version } = require('../../package');
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto.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 CardCommand extends Command {
constructor(client) {
@@ -0,0 +1,69 @@
const { Command } = require('discord.js-commando');
const { createCanvas, loadImage, registerFont } = require('canvas');
const snekfetch = require('snekfetch');
const path = require('path');
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto.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 DemotivationalPosterCommand extends Command {
constructor(client) {
super(client, {
name: 'demotivational-poster',
aliases: ['demotivational'],
group: 'avatar-edit',
memberName: 'demotivational-poster',
description: 'Draws a user\'s avatar and the text you specify as a demotivational poster.',
throttling: {
usages: 1,
duration: 15
},
clientPermissions: ['ATTACH_FILES'],
args: [
{
key: 'title',
prompt: 'What should the title of the poster be?',
type: 'string'
},
{
key: 'text',
prompt: 'What should the text of the poster be?',
type: 'string'
},
{
key: 'user',
prompt: 'Which user would you like to edit the avatar of?',
type: 'user',
default: ''
}
]
});
}
async run(msg, { title, text, user }) {
if (!user) user = msg.author;
const avatarURL = user.displayAvatarURL({
format: 'png',
size: 1024
});
try {
const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'demotivational-poster.png'));
const { body } = await snekfetch.get(avatarURL);
const avatar = await loadImage(body);
const canvas = createCanvas(base.width, base.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(avatar, 68, -57, 612, 612);
ctx.drawImage(base, 0, 0);
ctx.textAlign = 'center';
ctx.font = '60px Noto';
ctx.fillStyle = 'aquamarine';
ctx.fillText(title, 375, 468);
ctx.font = '27px Noto';
ctx.fillStyle = 'white';
ctx.fillText(text, 375, 540);
return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'demotivational-poster.png' }] });
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+4 -1
View File
@@ -1,7 +1,10 @@
const { Command } = require('discord.js-commando');
const { createCanvas, loadImage } = require('canvas');
const { createCanvas, loadImage, registerFont } = require('canvas');
const snekfetch = require('snekfetch');
const path = require('path');
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto.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 SteamCardCommand extends Command {
constructor(client) {
+4 -1
View File
@@ -1,7 +1,10 @@
const { Command } = require('discord.js-commando');
const { createCanvas, loadImage } = require('canvas');
const { createCanvas, loadImage, registerFont } = require('canvas');
const snekfetch = require('snekfetch');
const path = require('path');
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto.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 SteamNowPlayingCommand extends Command {
constructor(client) {
+4 -1
View File
@@ -1,8 +1,11 @@
const { Command } = require('discord.js-commando');
const { createCanvas, loadImage } = require('canvas');
const { createCanvas, loadImage, registerFont } = require('canvas');
const { stripIndents } = require('common-tags');
const path = require('path');
const texts = require('../../assets/json/be-like-bill');
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Noto.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 BeLikeBillCommand extends Command {
constructor(client) {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "54.0.1",
"version": "54.1.0",
"description": "Your personal server companion.",
"main": "XiaoBot.js",
"scripts": {