diff --git a/assets/images/photograph.png b/assets/images/photograph.png new file mode 100644 index 00000000..b8d535ab Binary files /dev/null and b/assets/images/photograph.png differ diff --git a/commands/avatar-edit/photograph.js b/commands/avatar-edit/photograph.js new file mode 100644 index 00000000..fed160fd --- /dev/null +++ b/commands/avatar-edit/photograph.js @@ -0,0 +1,50 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const snekfetch = require('snekfetch'); +const path = require('path'); + +module.exports = class PhotographCommand extends Command { + constructor(client) { + super(client, { + name: 'photograph', + group: 'avatar-edit', + memberName: 'photograph', + description: 'Draws a user\'s avatar over a photograph.', + throttling: { + usages: 1, + duration: 15 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'user', + prompt: 'Which user would you like to edit the avatar of?', + type: 'user', + default: '' + } + ] + }); + } + + async run(msg, { user }) { + if (!user) user = msg.author; + const avatarURL = user.displayAvatarURL({ + format: 'png', + size: 256 + }); + try { + const canvas = createCanvas(625, 417); + const ctx = canvas.getContext('2d'); + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'photograph.png')); + const { body } = await snekfetch.get(avatarURL); + const avatar = await loadImage(body); + ctx.drawImage(base, 0, 0); + ctx.rotate(-8.21 * (Math.PI / 180)); + ctx.drawImage(avatar, 96, 83, 175, 175); + ctx.rotate(8.21 * (Math.PI / 180)); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'photograph.png' }] }); + } catch (err) { + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/image-edit/robohash.js b/commands/image-edit/robohash.js new file mode 100644 index 00000000..ad939e17 --- /dev/null +++ b/commands/image-edit/robohash.js @@ -0,0 +1,25 @@ +const Command = require('../../structures/Command'); + +module.exports = class RobohashCommand extends Command { + constructor(client) { + super(client, { + name: 'robohash', + group: 'image-edit', + memberName: 'robohash', + description: 'Creates a robot based on the text you provide.', + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'text', + prompt: 'What text should be used for generation?', + type: 'string', + parse: text => encodeURIComponent(text) + } + ] + }); + } + + run(msg, { text }) { + return msg.say({ files: [`https://robohash.org/${text}`] }); + } +}; diff --git a/commands/random/gender.js b/commands/random/gender.js new file mode 100644 index 00000000..3972ddff --- /dev/null +++ b/commands/random/gender.js @@ -0,0 +1,32 @@ +const Command = require('../../structures/Command'); +const snekfetch = require('snekfetch'); + +module.exports = class GenderCommand extends Command { + constructor(client) { + super(client, { + name: 'gender', + group: 'random', + memberName: 'gender', + description: 'Determines the gender of name.', + args: [ + { + key: 'name', + prompt: 'What name do you want to determine the gender of?', + type: 'string' + } + ] + }); + } + + async run(msg, { name }) { + try { + const { body } = await snekfetch + .get('https://api.genderize.io/') + .query({ name }); + if (!body.gender) return msg.say(`I have no idea what gender ${body.name} is.`); + return msg.say(`I'm ${Math.round(body.probability * 100)}% sure ${body.name} is a ${body.gender} name.`); + } catch (err) { + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/search/derpibooru.js b/commands/search/derpibooru.js new file mode 100644 index 00000000..caa18201 --- /dev/null +++ b/commands/search/derpibooru.js @@ -0,0 +1,41 @@ +const Command = require('../../structures/Command'); +const snekfetch = require('snekfetch'); + +module.exports = class DerpibooruCommand extends Command { + constructor(client) { + super(client, { + name: 'derpibooru', + aliases: ['my-little-pony-image', 'mlp-image'], + group: 'search', + memberName: 'derpibooru', + description: 'Searches Derpibooru for your query.', + args: [ + { + key: 'query', + prompt: 'What image would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + try { + const search = await snekfetch + .get('https://derpibooru.org/search.json') + .query({ + q: query, + random_image: 1 + }); + if (!search.body) return msg.say('Could not find any results.'); + const { body } = await snekfetch + .get(`https://derpibooru.org/images/${search.body.id}.json`); + if (!msg.channel.nsfw && body.tags.includes('suggestive')) { + return msg.say('This image is only viewable in NSFW channels.'); + } + return msg.say(`https:${body.representations.large}`); + } catch (err) { + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/search/japanese-dictionary.js b/commands/search/japanese-dictionary.js new file mode 100644 index 00000000..77382946 --- /dev/null +++ b/commands/search/japanese-dictionary.js @@ -0,0 +1,40 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); + +module.exports = class JapaneseDictionaryCommand extends Command { + constructor(client) { + super(client, { + name: 'japanese-dictionary', + aliases: ['japanese-define', 'define-japanese', 'define-jpn', 'jpn-define', 'jisho'], + group: 'search', + memberName: 'define', + description: 'Defines a word, but with Japanese.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'query', + prompt: 'What would you like to define?', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + try { + const { body } = await snekfetch + .get('http://jisho.org/api/v1/search/words') + .query({ keyword: query }); + if (!body.data.length) return msg.say('Could not find any results.'); + const data = body.data[0]; + const embed = new MessageEmbed() + .setColor(0x9797FF) + .setTitle(data.japanese[0].word) + .setDescription(data.senses[0].english_definitions.join(', ')); + return msg.embed(embed); + } catch (err) { + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index b7a79573..d1256993 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "42.10.1", + "version": "42.11.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {