summaryrefslogtreecommitdiff
path: root/server/src/commands/fun/Onion.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/commands/fun/Onion.ts')
-rw-r--r--server/src/commands/fun/Onion.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/server/src/commands/fun/Onion.ts b/server/src/commands/fun/Onion.ts
new file mode 100644
index 0000000..e056ec7
--- /dev/null
+++ b/server/src/commands/fun/Onion.ts
@@ -0,0 +1,35 @@
+import { Command } from 'discord-akairo';
+import { Message } from 'discord.js';
+import { stripIndents } from 'common-tags';
+import RSS from 'rss-parser';
+
+export default class OnionFun extends Command {
+ public constructor() {
+ super('onion', {
+ aliases: ['onion', 'theonion', 'the-onion'],
+ category: 'fun',
+ description: {
+ content: 'Gives you a random Onion article.',
+ usage: '',
+ examples: [
+ ''
+ ]
+ },
+ ratelimit: 3
+ });
+ }
+
+ public async exec(msg: Message): Promise<Message> {
+ const parser = new RSS();
+ const feed = await parser.parseURL('https://www.theonion.com/rss').catch(err => {
+ console.error(err);
+ return msg.reply('Woops, there was an error regarding the (http://numbersapi.com) API.');
+ });
+ //@ts-ignore
+ const article = feed.items[Math.floor(Math.random() * feed.items.length)];
+ return msg.reply(stripIndents`
+ ${article.title}
+ ${article.link}
+ `);
+ }
+} \ No newline at end of file