Reddit and Thug Life

This commit is contained in:
Daniel Odendahl Jr
2017-07-24 05:15:08 +00:00
parent 72a9aa351d
commit eb886d822b
6 changed files with 101 additions and 1 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

+48
View File
@@ -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!`);
}
}
};
+50
View File
@@ -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;
}
}
};
+1
View File
@@ -50,6 +50,7 @@
<li>NPM</li>
<li>osu!</li>
<li>Recipe Puppy</li>
<li>Reddit</li>
<li>Rule34</li>
<li>SoundCloud</li>
<li>Urban Dictionary</li>
+1
View File
@@ -47,6 +47,7 @@
<li>NPM</li>
<li>osu!</li>
<li>Recipe Puppy</li>
<li>Reddit</li>
<li>Rule34</li>
<li>SoundCloud</li>
<li>Urban Dictionary</li>
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "27.4.0",
"version": "27.5.0",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {