diff options
Diffstat (limited to 'src/commands/fun/subreddit.ts')
| -rw-r--r-- | src/commands/fun/subreddit.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/commands/fun/subreddit.ts b/src/commands/fun/subreddit.ts new file mode 100644 index 0000000..a9369d2 --- /dev/null +++ b/src/commands/fun/subreddit.ts @@ -0,0 +1,46 @@ +import { Command, CommandoMessage } from 'discord.js-commando'; +import SubredditCommandBase from '../../models/commands/Subreddit.js' +import { shorten, formatNumber } from '../../utils/Util.js' +import { MessageEmbed } from 'discord.js'; + +module.exports = class SubredditFun extends SubredditCommandBase { + constructor(client) { + super(client, { + name: 'subreddit', + aliases: ['r/', 'sub', 'reddit'], + patterns: [/^r\/(.+)/i], + group: 'fun', + memberName: 'subreddit', + description: 'Replies with a random post from a specified subreddit.', + args: [ + { + key: 'sSub', + prompt: 'Which subreddit would you like to get a post from?', + type: 'string', + parse: subreddit => encodeURIComponent(subreddit) + } + ], + examples: ['uwu!say hi'], + throttling: { + usages: 5, + duration: 30 + }, + userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'], + clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'] + }); + } + generateText(post, subreddit, icon) { + const embed = new MessageEmbed() + .setColor(0xFFCC4D) + .setAuthor(`r/${subreddit}`, icon, `https://www.reddit.com/r/${subreddit}/`) + .setTitle(shorten(post.title, 256)) + .setImage(post.post_hint === 'image' ? post.url : null) + .setURL(`https://www.reddit.com${post.permalink}`) + .setTimestamp(post.created_utc * 1000) + .setFooter(`⬆ ${formatNumber(post.score)}`); + if (post.thumbnail && post.thumbnail !== 'self' && post.post_hint !== 'image') { + embed.setThumbnail(post.thumbnail); + } + return embed; + } +};
\ No newline at end of file |