Reduce duplicate code in subreddit commands

This commit is contained in:
Dragon Fire
2020-06-08 16:15:19 -04:00
parent 7ff1de7539
commit 5d6557ff76
7 changed files with 22 additions and 51 deletions
+1 -10
View File
@@ -1,6 +1,4 @@
const SubredditCommandBase = require('../../structures/commands/Subreddit');
const { MessageEmbed } = require('discord.js');
const { shorten, formatNumberK } = require('../../util/Util');
module.exports = class SubredditCommand extends SubredditCommandBase {
constructor(client) {
@@ -25,14 +23,7 @@ module.exports = class SubredditCommand extends SubredditCommandBase {
}
generateText(post, subreddit, icon) {
const embed = new MessageEmbed()
.setColor(0xFF4500)
.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(`${formatNumberK(post.score)}`);
const embed = this.makeEmbed(post, subreddit, icon);
if (post.thumbnail && post.thumbnail !== 'self' && post.post_hint !== 'image') {
embed.setThumbnail(post.thumbnail);
}