Add r/subreddit pattern match to subreddit

This commit is contained in:
Dragon Fire
2020-03-25 14:17:56 -04:00
parent f4a0ce4242
commit 9de12642fa
2 changed files with 6 additions and 3 deletions
+4 -2
View File
@@ -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;
}
};
+2 -1
View File
@@ -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);