diff --git a/assets/images/thug-life.png b/assets/images/thug-life.png new file mode 100644 index 00000000..d95fa794 Binary files /dev/null and b/assets/images/thug-life.png differ diff --git a/commands/avatar-edit/thug-life.js b/commands/avatar-edit/thug-life.js new file mode 100644 index 00000000..7e409df3 --- /dev/null +++ b/commands/avatar-edit/thug-life.js @@ -0,0 +1,48 @@ +const Command = require('../../structures/Command'); +const { createCanvas, loadImage } = require('canvas'); +const snekfetch = require('snekfetch'); +const path = require('path'); + +module.exports = class ThugLifeCommand extends Command { + constructor(client) { + super(client, { + name: 'thug-life', + group: 'avatar-edit', + memberName: 'thug-life', + description: 'Draws "Thug Life" over a user\'s avatar.', + throttling: { + usages: 1, + duration: 30 + }, + clientPermissions: ['ATTACH_FILES'], + args: [ + { + key: 'user', + prompt: 'Which user would you like to edit the avatar of?', + type: 'user', + default: '' + } + ] + }); + } + + async run(msg, args) { + const user = args.user || msg.author; + const avatarURL = user.displayAvatarURL({ + format: 'png', + size: 256 + }); + try { + const canvas = createCanvas(256, 256); + const ctx = canvas.getContext('2d'); + const base = await loadImage(path.join(__dirname, '..', '..', 'assets', 'images', 'thug-life.png')); + const { body } = await snekfetch.get(avatarURL); + const avatar = await loadImage(body); + ctx.drawImage(avatar, 0, 0); + ctx.drawImage(base, 28, 204, 200, 42); + return msg.say({ files: [{ attachment: canvas.toBuffer(), name: 'thug-life.png' }] }); + } catch (err) { + return msg.say(`Oh no, the image generation failed: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/search/reddit.js b/commands/search/reddit.js new file mode 100644 index 00000000..120fcf6b --- /dev/null +++ b/commands/search/reddit.js @@ -0,0 +1,50 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); + +module.exports = class RedditCommand extends Command { + constructor(client) { + super(client, { + name: 'reddit', + group: 'search', + memberName: 'reddit', + description: 'Gets a random recent post from a subreddit.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'subreddit', + prompt: 'What subreddit would you like to get data for?', + type: 'string' + } + ] + }); + } + + async run(msg, args) { + try { + const { subreddit } = args; + const { body } = await snekfetch + .get(`https://www.reddit.com/r/${subreddit}/new.json`) + .query({ sort: 'new' }); + const post = body.data.children[Math.floor(Math.random() * body.data.children.length)].data; + if (!msg.channel.nsfw && post.over_18) return msg.say('This post is only viewable in NSFW Channels.'); + const embed = new MessageEmbed() + .setColor(0xFF4500) + .setAuthor('Reddit', 'https://i.imgur.com/V6hXniU.png') + .setURL(`https://www.reddit.com${post.permalink}`) + .setTitle(post.title) + .setDescription(`[View URL Here](${post.url})`) + .setThumbnail(post.thumbnail !== 'self' ? post.thumbnail : null) + .addField('❯ Upvotes', + post.ups, true) + .addField('❯ Downvotes', + post.downs, true) + .addField('❯ Score', + post.score, true); + return msg.embed(embed); + } catch (err) { + if (err.status === 404) return msg.say('Subreddit Not Found.'); + else throw err; + } + } +}; diff --git a/html/carbonfeat.html b/html/carbonfeat.html index 2334dd01..e6cd8dd8 100644 --- a/html/carbonfeat.html +++ b/html/carbonfeat.html @@ -50,6 +50,7 @@
  • NPM
  • osu!
  • Recipe Puppy
  • +
  • Reddit
  • Rule34
  • SoundCloud
  • Urban Dictionary
  • diff --git a/html/discordbots.html b/html/discordbots.html index ed01629a..d159575a 100644 --- a/html/discordbots.html +++ b/html/discordbots.html @@ -47,6 +47,7 @@
  • NPM
  • osu!
  • Recipe Puppy
  • +
  • Reddit
  • Rule34
  • SoundCloud
  • Urban Dictionary
  • diff --git a/package.json b/package.json index 4a5b803c..2f07734a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "27.4.0", + "version": "27.5.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {