From 2ae3b34476205bf43ce733568990c4afe5fa884a Mon Sep 17 00:00:00 2001 From: loicbersier Date: Wed, 26 Jun 2019 02:52:05 +0200 Subject: [PATCH] 4chan (only work on nsfw channel!) --- commands/fun/4chan.js | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 commands/fun/4chan.js diff --git a/commands/fun/4chan.js b/commands/fun/4chan.js new file mode 100644 index 00000000..578d6039 --- /dev/null +++ b/commands/fun/4chan.js @@ -0,0 +1,58 @@ +const { Command } = require('discord-akairo'); +const { MessageEmbed } = require('discord.js'); +const fetch = require('node-fetch'); + +class FourchanCommand extends Command { + constructor() { + super('4chan', { + aliases: ['4chan'], + category: 'fun', + + args: [ + { + id: 'board', + type: 'string', + prompt: { + start: 'Wich board do you want to browse?', + }, + match: 'rest' + } + ], + description: { + content: 'Send random images from a 4chan board of your choosing (only in nsfw channel)', + usage: '[board]', + examples: ['vg'] + } + }); + } + + async exec(message, args) { + if (!message.channel.nsfw) return message.channel.send('Sorry, this command only work in nsfw channel!'); + + if (!args.board) return; + + fetch(`https://a.4cdn.org/${args.board}/1.json`).then((response) => { + return response.json(); + }).then((response) => { + if (!response.threads) + return message.channel.send('Not a valid board'); + + let i = Math.floor((Math.random() * response.threads.length)); + + let description = response.threads[i].posts[0].com.replace(/(<([^>]+)>)/ig,''); + description += decodeURI(description); + + const FourchanEmbed = new MessageEmbed() + .setColor('#ff9900') + .setTitle(`${response.threads[i].posts[0].name} | ${response.threads[i].posts[0].no}`) + .setDescription(description) + .setImage(`https://i.4cdn.org/${args.board}/${response.threads[i].posts[0].tim}${response.threads[i].posts[0].ext}`) + .setURL(`https://boards.4chan.org/${args.board}/thread/${response.threads[i].posts[0].no}/${response.threads[i].posts[0].semantic_url}`) + .setFooter(`${args.board} | ${response.threads[i].posts[0].now}`) + .setTimestamp(); + + message.channel.send(FourchanEmbed); + }); + } +} +module.exports = FourchanCommand; \ No newline at end of file