diff --git a/.gitattributes b/.gitattributes index 452325b0..2dfb771f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12,3 +12,4 @@ *.png binary *.mp3 binary *.ttf binary +*.otf binary diff --git a/assets/images/demotivational-poster.png b/assets/images/demotivational-poster.png new file mode 100644 index 00000000..22a360de Binary files /dev/null and b/assets/images/demotivational-poster.png differ diff --git a/commands/avatar-edit/card.js b/commands/avatar-edit/card.js index a6edb72a..0b877f13 100644 --- a/commands/avatar-edit/card.js +++ b/commands/avatar-edit/card.js @@ -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) { diff --git a/commands/avatar-edit/demotivational-poster.js b/commands/avatar-edit/demotivational-poster.js new file mode 100644 index 00000000..208cd655 --- /dev/null +++ b/commands/avatar-edit/demotivational-poster.js @@ -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!`); + } + } +}; diff --git a/commands/avatar-edit/steam-card.js b/commands/avatar-edit/steam-card.js index 7246f621..ba79a3e0 100644 --- a/commands/avatar-edit/steam-card.js +++ b/commands/avatar-edit/steam-card.js @@ -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) { diff --git a/commands/avatar-edit/steam-now-playing.js b/commands/avatar-edit/steam-now-playing.js index 93c7c8f5..7eba9ca1 100644 --- a/commands/avatar-edit/steam-now-playing.js +++ b/commands/avatar-edit/steam-now-playing.js @@ -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) { diff --git a/commands/image-edit/be-like-bill.js b/commands/image-edit/be-like-bill.js index 5c959c45..5ff6cd54 100644 --- a/commands/image-edit/be-like-bill.js +++ b/commands/image-edit/be-like-bill.js @@ -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) { diff --git a/package.json b/package.json index 3e1a4c0a..c23c1013 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "54.0.1", + "version": "54.1.0", "description": "Your personal server companion.", "main": "XiaoBot.js", "scripts": {