mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-21 05:54:33 +02:00
Get memes from reddit
This commit is contained in:
+20
-7
@@ -1,19 +1,32 @@
|
|||||||
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
|
const Command = require('../../structures/Command');
|
||||||
const { POSTER_ALBUM_ID } = process.env;
|
const request = require('node-superfetch');
|
||||||
|
const { stripIndents } = require('common-tags');
|
||||||
|
const subreddits = ['memes', 'surrealmemes', 'MemeEconomy', 'wholesomememes', 'tumblr', 'me_irl', 'blessedimages'];
|
||||||
|
|
||||||
module.exports = class MemeCommand extends ImgurAlbumCommand {
|
module.exports = class MemeCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'meme',
|
name: 'meme',
|
||||||
group: 'random',
|
group: 'random',
|
||||||
memberName: 'meme',
|
memberName: 'meme',
|
||||||
description: 'Responds with a random meme.',
|
description: 'Responds with a random meme.',
|
||||||
clientPermissions: ['ATTACH_FILES'],
|
clientPermissions: ['ATTACH_FILES']
|
||||||
albumID: POSTER_ALBUM_ID
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
generateText() {
|
async run(msg) {
|
||||||
return '';
|
const subreddit = subreddits[Math.floor(Math.random() * subreddits.length)];
|
||||||
|
try {
|
||||||
|
const { body } = await request.get(`https://www.reddit.com/r/${subreddit}/hot.json`);
|
||||||
|
const posts = body.data.children.filter(post => post.data && post.data.post_hint === 'image' && post.data.url);
|
||||||
|
if (!posts.length) return msg.reply(`I couldn't fetch any images from r/${subreddit}...`);
|
||||||
|
const post = posts[Math.floor(Math.random() * posts.length)];
|
||||||
|
return msg.say(stripIndents`
|
||||||
|
**r/${subreddit}** ${post.title}
|
||||||
|
${post.url}
|
||||||
|
`);
|
||||||
|
} catch (err) {
|
||||||
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "90.0.2",
|
"version": "90.0.3",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user