summaryrefslogtreecommitdiff
path: root/src/models
diff options
context:
space:
mode:
author8cy <[email protected]>2020-04-29 04:36:14 -0700
committer8cy <[email protected]>2020-04-29 04:36:14 -0700
commit68d32ab1fa9c79e848038ca1c451e7d8f368531b (patch)
tree6142669ecc054e8a94bad4723dc6fb5c83f8cee1 /src/models
parentThe Return, v8.2.0 (diff)
downloaddep-core-68d32ab1fa9c79e848038ca1c451e7d8f368531b.tar.xz
dep-core-68d32ab1fa9c79e848038ca1c451e7d8f368531b.zip
Cerasus, v9.0.0
basically just add an insane amount of things - all new animal commands - waifu cmds - change/ move clientid, invite, uwufy, support, howify, say, pfp - add ip, security key, vote, datefacts, githubzen, fmk, fml, offsptring, facts, rate, opinion, onion, quantum coin, rolldie, romannumerals, russianrullete, smashorpass, spoiler, sub - minecraft cmds - SERVER check cmds - lewd cmds - roleplay commands - fun commands and games - utils
Diffstat (limited to 'src/models')
-rw-r--r--src/models/Command.ts16
-rw-r--r--src/models/commands/Subreddit.ts64
2 files changed, 80 insertions, 0 deletions
diff --git a/src/models/Command.ts b/src/models/Command.ts
new file mode 100644
index 0000000..a6d6700
--- /dev/null
+++ b/src/models/Command.ts
@@ -0,0 +1,16 @@
+import { Command } from 'discord.js-commando';
+
+module.exports = class UwufierCommand extends Command {
+ constructor(client, info) {
+ super(client, info);
+
+ this.argsSingleQuotes = info.argsSingleQuotes || false;
+ this.throttling = info.throttling || { usages: 1, duration: 2 };
+ this.credit = info.credit || [];
+ this.credit.push({
+ name: 'Dragon Fire',
+ url: 'https://github.com/dragonfire535',
+ reason: 'Code'
+ });
+ }
+} \ No newline at end of file
diff --git a/src/models/commands/Subreddit.ts b/src/models/commands/Subreddit.ts
new file mode 100644
index 0000000..ff58a71
--- /dev/null
+++ b/src/models/commands/Subreddit.ts
@@ -0,0 +1,64 @@
+import { CommandoMessage } from 'discord.js-commando';
+import Command from '../Command.js'
+import request from 'node-superfetch'
+import emoji from 'emoji-random'
+
+module.exports = class SubredditCommand extends Command {
+ constructor(client, info) {
+ super(client, info);
+
+ this.subreddit = info.subreddit;
+ this.postType = info.postType ? Array.isArray(info.postType) ? info.postType : [info.postType] : null;
+ this.getIcon = info.getIcon || false;
+ this.credit.push({
+ name: 'Reddit',
+ url: 'https://www.reddit.com/',
+ reason: 'API',
+ reasonURL: 'https://www.reddit.com/dev/api/'
+ });
+ }
+
+ async run(msg: CommandoMessage, { 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);
+ if (!post) return msg.reply('Could not find any results. ' + emoji.random());
+ return msg.say(this.generateText(post.post, post.origin, post.icon));
+ } catch (err) {
+ if (err.status === 403) return msg.reply('This subreddit is private. ' + emoji.random());
+ if (err.status === 404) return msg.reply('Could not find any results. ' + emoji.random());
+ return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
+ }
+ }
+
+ generateText() {
+ throw new Error('The generateText method is required.');
+ }
+
+ async random(subreddit, nsfw) {
+ let icon = null;
+ const { body } = await request
+ .get(`https://www.reddit.com/r/${subreddit}/hot.json`)
+ .query({ limit: 100 });
+ if (!body.data.children.length) return null;
+ const posts = body.data.children.filter(post => {
+ if (!post.data) return false;
+ if (!nsfw && post.data.over_18) return false;
+ return (this.postType ? this.postType.includes(post.data.post_hint) : true) && post.data.url && post.data.title;
+ });
+ if (!posts.length) return null;
+ if (this.getIcon) icon = await this.fetchIcon(subreddit);
+ return {
+ origin: subreddit,
+ post: posts[Math.floor(Math.random() * posts.length)].data,
+ icon
+ };
+ }
+
+ async fetchIcon(subreddit) {
+ const { body } = await request.get(`https://www.reddit.com/r/${subreddit}/about.json`);
+ if (!body.data.icon_img && !body.data.community_icon) return 'https://i.imgur.com/DSBOK0P.png';
+ return body.data.icon_img || body.data.community_icon;
+ }
+}; \ No newline at end of file