From 1691870d2b9184f2d93cb2bd212c91116e2db8f6 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sat, 23 Sep 2017 20:02:01 +0000 Subject: [PATCH] 5 New Commands --- commands/avatar-edit/pixelize.js | 46 ++++++++++++++++++++++++++ commands/random-res/security-key.js | 17 ++++++++++ commands/roleplay/tackle.js | 35 ++++++++++++++++++++ commands/search/ip-info.js | 50 +++++++++++++++++++++++++++++ commands/search/safebooru.js | 45 ++++++++++++++++++++++++++ package.json | 3 +- 6 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 commands/avatar-edit/pixelize.js create mode 100644 commands/random-res/security-key.js create mode 100644 commands/roleplay/tackle.js create mode 100644 commands/search/ip-info.js create mode 100644 commands/search/safebooru.js diff --git a/commands/avatar-edit/pixelize.js b/commands/avatar-edit/pixelize.js new file mode 100644 index 00000000..f0236782 --- /dev/null +++ b/commands/avatar-edit/pixelize.js @@ -0,0 +1,46 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const snekfetch = require('snekfetch'); + +module.exports = class PixelizeCommand extends Command { + constructor(client) { + super(client, { + name: 'pixelize', + group: 'avatar-edit', + memberName: 'pixelize', + description: 'Draws a user\'s avatar pixelized.', + 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: 64 + }); + try { + const canvas = createCanvas(256, 256); + const ctx = canvas.getContext('2d'); + const { body } = await snekfetch.get(avatarURL); + const avatar = await loadImage(body); + ctx.imageSmoothingEnabled = false; + ctx.drawImage(avatar, 0, 0, 256, 256); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'pixelize.png' }] }); + } catch (err) { + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/random-res/security-key.js b/commands/random-res/security-key.js new file mode 100644 index 00000000..331a2053 --- /dev/null +++ b/commands/random-res/security-key.js @@ -0,0 +1,17 @@ +const Command = require('../../structures/Command'); +const crypto = require('crypto'); + +module.exports = class SecurityKeyCommand extends Command { + constructor(client) { + super(client, { + name: 'security-key', + group: 'random-res', + memberName: 'security-key', + description: 'Generates a random security key.' + }); + } + + run(msg) { + return msg.say(crypto.randomBytes(15).toString('hex')); + } +}; diff --git a/commands/roleplay/tackle.js b/commands/roleplay/tackle.js new file mode 100644 index 00000000..8908449c --- /dev/null +++ b/commands/roleplay/tackle.js @@ -0,0 +1,35 @@ +const Command = require('../../structures/Command'); +const { stripIndents } = require('common-tags'); +const gifs = [ + 'https://i.imgur.com/wXShFlF.gif', + 'https://i.imgur.com/bpBz27N.gif', + 'https://i.imgur.com/61vX6F6.gif', + 'https://i.imgur.com/6zv7HP5.gif', + 'https://i.imgur.com/ExYfGm8.gif' +]; + +module.exports = class TackleCommand extends Command { + constructor(client) { + super(client, { + name: 'tackle', + aliases: ['glomp', 'tackle-hug'], + group: 'roleplay', + memberName: 'tackle', + description: 'Tackles a user.', + args: [ + { + key: 'user', + prompt: 'What user do you want to roleplay with?', + type: 'user' + } + ] + }); + } + + run(msg, { user }) { + return msg.say(stripIndents` + **${msg.author.username}** *tackles* **${user.username}** + ${gifs[Math.floor(Math.random() * gifs.length)]} + `); + } +}; diff --git a/commands/search/ip-info.js b/commands/search/ip-info.js new file mode 100644 index 00000000..d4928c51 --- /dev/null +++ b/commands/search/ip-info.js @@ -0,0 +1,50 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); + +module.exports = class IPInfoCommand extends Command { + constructor(client) { + super(client, { + name: 'ip-info', + group: 'search', + memberName: 'ip-info', + description: 'Gets data for an IP address.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'ip', + prompt: 'Which IP would you like to get information on?', + type: 'string', + parse: ip => encodeURIComponent(ip) + } + ] + }); + } + + async run(msg, { ip }) { + try { + const { body } = await snekfetch + .get(`https://ipinfo.io/${ip}/json`); + const embed = new MessageEmbed() + .setColor(0x9797FF) + .setURL(`https://ipinfo.io/${ip}`) + .setTitle(body.ip) + .addField('❯ Hostname', + body.hostname, true) + .addField('❯ Location', + body.loc, true) + .addField('❯ Organization', + body.org, true) + .addField('❯ City', + `${body.city} (${body.postal})`, true) + .addField('❯ Region', + body.region, true) + .addField('❯ Country', + body.country, true); + return msg.embed(embed); + } catch (err) { + if (err.status === 404) return msg.say('Could not find any results.'); + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/search/safebooru.js b/commands/search/safebooru.js new file mode 100644 index 00000000..9649c56e --- /dev/null +++ b/commands/search/safebooru.js @@ -0,0 +1,45 @@ +const Command = require('../../structures/Command'); +const snekfetch = require('snekfetch'); +const { xml2json } = require('xml-js'); +const { stripIndents } = require('common-tags'); + +module.exports = class SafebooruCommand extends Command { + constructor(client) { + super(client, { + name: 'safebooru', + group: 'search', + memberName: 'safebooru', + description: 'Searches Safebooru for your query.', + args: [ + { + key: 'query', + prompt: 'What image would you like to search for?', + type: 'string', + default: '' + } + ] + }); + } + + async run(msg, { query }) { + try { + const { text } = await snekfetch + .get('https://safebooru.org/index.php') + .query({ + page: 'dapi', + s: 'post', + q: 'index', + tags: query + }); + const parsed = xml2json(text, { compact: true }); + if (parsed.posts.count === '0' || !parsed.posts.post.length) return msg.say('Could not find any results.'); + const posts = msg.channel.nsfw ? parsed.posts.post : parsed.posts.post.filter(post => post.rating === 's'); + return msg.say(stripIndents` + ${query ? `Results for ${query}:` : 'Random Image:'} + https:${posts[Math.floor(Math.random() * posts.length)].file_url} + `); + } catch (err) { + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 04cca2e7..02f830f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "42.5.1", + "version": "42.6.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { @@ -44,6 +44,7 @@ "sequelize": "^4.10.2", "snekfetch": "^3.3.1", "uws": "^8.14.1", + "xml-js": "^1.4.2", "zalgolize": "^1.2.4" }, "devDependencies": {