diff --git a/assets/images/steam-now-playing.PNG b/assets/images/steam-now-playing.PNG new file mode 100644 index 00000000..db79b440 Binary files /dev/null and b/assets/images/steam-now-playing.PNG differ diff --git a/commands/avatar-edit/steam-now-playing.js b/commands/avatar-edit/steam-now-playing.js new file mode 100644 index 00000000..f7cfd07e --- /dev/null +++ b/commands/avatar-edit/steam-now-playing.js @@ -0,0 +1,65 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage, registerFont } = require('canvas'); +const snekfetch = require('snekfetch'); +const path = require('path'); + +module.exports = class SteamNowPlayingCommand extends Command { + constructor(client) { + super(client, { + name: 'steam-now-playing', + aliases: ['now-playing'], + group: 'avatar-edit', + memberName: 'steam-now-playing', + description: 'Draws a user\'s avatar and the game of your choice over a Steam "now playing" notification.', + guildOnly: true, + throttling: { + usages: 1, + duration: 30 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'game', + prompt: 'Which game would you like the user to be playing?', + type: 'string', + validate: game => { + if (game.length < 25) return true; + return 'Please keep the game under 25 characters.'; + } + }, + { + key: 'member', + prompt: 'Which user would you like to be playing the game?', + type: 'member', + default: '' + } + ] + }); + } + + async run(msg, args) { + const { game } = args; + const member = args.member || msg.member; + const avatarURL = member.user.displayAvatarURL({ + format: 'png', + size: 128 + }); + try { + registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'Roboto.ttf'), { family: 'Roboto' }); + const canvas = createCanvas(239, 73); + const ctx = canvas.getContext('2d'); + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'steam-now-playing.png')); + const { body } = await snekfetch.get(avatarURL); + const avatar = await loadImage(body); + ctx.drawImage(base, 0, 0); + ctx.drawImage(avatar, 21, 21, 32, 32); + ctx.fillStyle = '#90ba3c'; + ctx.font = '10px Roboto'; + ctx.fillText(member.displayName, 63, 16); + ctx.fillText(game, 63, 42); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'steam-now-playing.png' }] }); + } catch (err) { + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 81063bbb..2dbd04ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "38.3.0", + "version": "38.4.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {