From 9de12642fa6e5af7645d9c0d1137a6c300b7116e Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 25 Mar 2020 14:17:56 -0400 Subject: [PATCH] Add r/subreddit pattern match to subreddit --- commands/random-res/subreddit.js | 6 ++++-- structures/commands/Subreddit.js | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/commands/random-res/subreddit.js b/commands/random-res/subreddit.js index f1ddfb65..5ca7469d 100644 --- a/commands/random-res/subreddit.js +++ b/commands/random-res/subreddit.js @@ -11,6 +11,7 @@ module.exports = class SubredditCommand extends SubredditCommandBase { memberName: 'subreddit', description: 'Responds with a random post from a subreddit.', clientPermissions: ['EMBED_LINKS'], + patterns: [/^r\/(.+)/i], getIcon: true, args: [ { @@ -24,14 +25,15 @@ module.exports = class SubredditCommand extends SubredditCommandBase { } generateText(post, subreddit, icon) { - return new MessageEmbed() + const embed = new MessageEmbed() .setColor(0xFF4500) .setAuthor(`r/${subreddit}`, icon, `https://www.reddit.com/r/${subreddit}/`) .setTitle(post.title) .setImage(post.post_hint === 'image' ? post.url : null) - .setThumbnail(post.post_hint === 'image' ? null : post.thumbnail) .setURL(`https://www.reddit.com${post.permalink}`) .setTimestamp(post.created_utc * 1000) .setFooter(`⬆ ${formatNumber(post.score)}`); + if (post.thumbnail && post.post_hint !== 'image') embed.setThumbnail(post.thumbnail); + return embed; } }; diff --git a/structures/commands/Subreddit.js b/structures/commands/Subreddit.js index cc1ddbc0..4b50e07c 100644 --- a/structures/commands/Subreddit.js +++ b/structures/commands/Subreddit.js @@ -16,7 +16,8 @@ module.exports = class SubredditCommand extends Command { }); } - async run(msg, { subreddit }) { + async run(msg, { subreddit }, fromPattern) { + if (fromPattern) subreddit = msg.patternMatches[1]; if (!subreddit) subreddit = typeof this.subreddit === 'function' ? this.subreddit() : this.subreddit; try { const post = await this.random(subreddit, msg.channel.nsfw);