mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Reduce duplicate code in subreddit commands
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
const SubredditCommand = require('../../structures/commands/Subreddit');
|
const SubredditCommand = require('../../structures/commands/Subreddit');
|
||||||
const { MessageEmbed } = require('discord.js');
|
|
||||||
const { formatNumberK } = require('../../util/Util');
|
|
||||||
|
|
||||||
module.exports = class AwwnimeCommand extends SubredditCommand {
|
module.exports = class AwwnimeCommand extends SubredditCommand {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -18,13 +16,6 @@ module.exports = class AwwnimeCommand extends SubredditCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateText(post, subreddit, icon) {
|
generateText(post, subreddit, icon) {
|
||||||
return new MessageEmbed()
|
return this.makeEmbed(post, subreddit, icon);
|
||||||
.setColor(0xFF4500)
|
|
||||||
.setAuthor(`r/${subreddit}`, icon, `https://www.reddit.com/r/${subreddit}/`)
|
|
||||||
.setTitle(post.title)
|
|
||||||
.setImage(post.post_hint === 'image' ? post.url : null)
|
|
||||||
.setURL(`https://www.reddit.com${post.permalink}`)
|
|
||||||
.setTimestamp(post.created_utc * 1000)
|
|
||||||
.setFooter(`⬆ ${formatNumberK(post.ups)}`);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const SubredditCommand = require('../../structures/commands/Subreddit');
|
const SubredditCommand = require('../../structures/commands/Subreddit');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { list } = require('../../util/Util');
|
||||||
const { list, formatNumberK } = require('../../util/Util');
|
|
||||||
const subreddits = require('../../assets/json/hentai');
|
const subreddits = require('../../assets/json/hentai');
|
||||||
|
|
||||||
module.exports = class HentaiCommand extends SubredditCommand {
|
module.exports = class HentaiCommand extends SubredditCommand {
|
||||||
@@ -36,13 +35,6 @@ module.exports = class HentaiCommand extends SubredditCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateText(post, subreddit, icon) {
|
generateText(post, subreddit, icon) {
|
||||||
return new MessageEmbed()
|
return this.makeEmbed(post, subreddit, icon);
|
||||||
.setColor(0xFF4500)
|
|
||||||
.setAuthor(`r/${subreddit}`, icon, `https://www.reddit.com/r/${subreddit}/`)
|
|
||||||
.setTitle(post.title)
|
|
||||||
.setImage(post.post_hint === 'image' ? post.url : null)
|
|
||||||
.setURL(`https://www.reddit.com${post.permalink}`)
|
|
||||||
.setTimestamp(post.created_utc * 1000)
|
|
||||||
.setFooter(`⬆ ${formatNumberK(post.ups)}`);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const SubredditCommand = require('../../structures/commands/Subreddit');
|
const SubredditCommand = require('../../structures/commands/Subreddit');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { list } = require('../../util/Util');
|
||||||
const { list, formatNumberK } = require('../../util/Util');
|
|
||||||
const subreddits = require('../../assets/json/meme');
|
const subreddits = require('../../assets/json/meme');
|
||||||
|
|
||||||
module.exports = class MemeCommand extends SubredditCommand {
|
module.exports = class MemeCommand extends SubredditCommand {
|
||||||
@@ -28,13 +27,6 @@ module.exports = class MemeCommand extends SubredditCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateText(post, subreddit, icon) {
|
generateText(post, subreddit, icon) {
|
||||||
return new MessageEmbed()
|
return this.makeEmbed(post, subreddit, icon);
|
||||||
.setColor(0xFF4500)
|
|
||||||
.setAuthor(`r/${subreddit}`, icon, `https://www.reddit.com/r/${subreddit}/`)
|
|
||||||
.setTitle(post.title)
|
|
||||||
.setImage(post.post_hint === 'image' ? post.url : null)
|
|
||||||
.setURL(`https://www.reddit.com${post.permalink}`)
|
|
||||||
.setTimestamp(post.created_utc * 1000)
|
|
||||||
.setFooter(`⬆ ${formatNumberK(post.ups)}`);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const SubredditCommand = require('../../structures/commands/Subreddit');
|
const SubredditCommand = require('../../structures/commands/Subreddit');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { list } = require('../../util/Util');
|
||||||
const { list, formatNumberK } = require('../../util/Util');
|
|
||||||
const subreddits = require('../../assets/json/porn');
|
const subreddits = require('../../assets/json/porn');
|
||||||
|
|
||||||
module.exports = class PornCommand extends SubredditCommand {
|
module.exports = class PornCommand extends SubredditCommand {
|
||||||
@@ -37,13 +36,6 @@ module.exports = class PornCommand extends SubredditCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateText(post, subreddit, icon) {
|
generateText(post, subreddit, icon) {
|
||||||
return new MessageEmbed()
|
return this.makeEmbed(post, subreddit, icon);
|
||||||
.setColor(0xFF4500)
|
|
||||||
.setAuthor(`r/${subreddit}`, icon, `https://www.reddit.com/r/${subreddit}/`)
|
|
||||||
.setTitle(post.title)
|
|
||||||
.setImage(post.post_hint === 'image' ? post.url : null)
|
|
||||||
.setURL(`https://www.reddit.com${post.permalink}`)
|
|
||||||
.setTimestamp(post.created_utc * 1000)
|
|
||||||
.setFooter(`⬆ ${formatNumberK(post.ups)}`);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
const SubredditCommandBase = require('../../structures/commands/Subreddit');
|
const SubredditCommandBase = require('../../structures/commands/Subreddit');
|
||||||
const { MessageEmbed } = require('discord.js');
|
|
||||||
const { shorten, formatNumberK } = require('../../util/Util');
|
|
||||||
|
|
||||||
module.exports = class SubredditCommand extends SubredditCommandBase {
|
module.exports = class SubredditCommand extends SubredditCommandBase {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
@@ -25,14 +23,7 @@ module.exports = class SubredditCommand extends SubredditCommandBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateText(post, subreddit, icon) {
|
generateText(post, subreddit, icon) {
|
||||||
const embed = new MessageEmbed()
|
const embed = this.makeEmbed(post, subreddit, icon);
|
||||||
.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)}`);
|
|
||||||
if (post.thumbnail && post.thumbnail !== 'self' && post.post_hint !== 'image') {
|
if (post.thumbnail && post.thumbnail !== 'self' && post.post_hint !== 'image') {
|
||||||
embed.setThumbnail(post.thumbnail);
|
embed.setThumbnail(post.thumbnail);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "116.8.1",
|
"version": "116.8.2",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
const Command = require('../Command');
|
const Command = require('../Command');
|
||||||
|
const { MessageEmbed } = require('discord.js');
|
||||||
|
const { formatNumberK, shorten } = require('../../util/Util');
|
||||||
|
|
||||||
module.exports = class SubredditCommand extends Command {
|
module.exports = class SubredditCommand extends Command {
|
||||||
constructor(client, info) {
|
constructor(client, info) {
|
||||||
@@ -34,6 +36,17 @@ module.exports = class SubredditCommand extends Command {
|
|||||||
throw new Error('The generateText method is required.');
|
throw new Error('The generateText method is required.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
makeEmbed(post, subreddit, icon) {
|
||||||
|
return 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.ups)}`);
|
||||||
|
}
|
||||||
|
|
||||||
async random(subreddit, nsfw) {
|
async random(subreddit, nsfw) {
|
||||||
let icon = null;
|
let icon = null;
|
||||||
const { body } = await request
|
const { body } = await request
|
||||||
|
|||||||
Reference in New Issue
Block a user