UNPKG

image-reddit-generator

Version:

A module for generate image of a reddit posts (space, fox, cat etc...)

61 lines (46 loc) 1.99 kB
const { EventEmitter } = require('events'); const { MessageEmbed } = require('discord.js'); const fetch = require("node-fetch") module.exports = class RedditImage extends EventEmitter { /** * Instancie la classe 'Drop'; obligatoire par la suite * @constructor * @param {Discord.Client} client - Représente le client */ constructor(client) { super() if(!client) throw new Error("Un Discord Client doit être précisé."); this.client = client; }; /** * Create a embed with reddit image * @param {message} message * @param {options} object * @param {args} object */ async create(message, options, args) { if(!message) throw new Error("Vous devez donner un message (paramètre de votre événement)"); if(typeof options !== "object") throw new Error("Les options doivent être dans un objet."); if(!options.ruleschannel) throw new Error("Une option \`ruleschannel\` est nécessaire)"); if(typeof options.ruleschannel !== "string") throw new Error("L'option \"ruleschannel\" doit être de type String.") let url = `https://www.reddit.com/r/${options.ruleschannel}/about.json` await fetch(url, {headers: {Authorization: `fA-srx2u-9kZZaxRt1qOgR7jJZPdHw`}}) .then(res => res.json()) .then(body => { console.log(body) if(body === undefined) { const embed = new MessageEmbed() .setTitle("**Règle de ce channel Reddit !**") .setDescription("Je n'ai rien trouvé") .setColor("RANDOM") message.channel.send(embed) } else { const embed = new MessageEmbed() .setTitle("**Règle de channel reddit !**") .addField(`**Langue**`, `**${res.body.description_html}**`) .setColor("RANDOM") message.channel.send(embed) } }) } }