diff --git a/src/class/Command.ts b/src/class/Command.ts index 7fc00f5..7a2e5c5 100644 --- a/src/class/Command.ts +++ b/src/class/Command.ts @@ -68,8 +68,10 @@ export default class Command { case 4: return member.roles.some((r) => ['701454780828221450', '701454855952138300', '662163685439045632'].includes(r)); case 5: - return member.roles.some((r) => ['701454855952138300', '662163685439045632'].includes(r)); + return member.roles.some((r) => ['455972169449734144', '701454780828221450', '701454855952138300', '662163685439045632'].includes(r)); case 6: + return member.roles.some((r) => ['701454855952138300', '662163685439045632'].includes(r)); + case 7: return member.roles.includes('662163685439045632'); default: return false; diff --git a/src/commands/mdn.ts b/src/commands/mdn.ts new file mode 100644 index 0000000..95e2a54 --- /dev/null +++ b/src/commands/mdn.ts @@ -0,0 +1,65 @@ +import { Message } from 'eris'; +import axios from 'axios'; +import { Client, Command, RichEmbed } from '../class'; + +export default class MDN extends Command { + constructor(client: Client) { + super(client); + this.name = 'mdn'; + this.description = 'Get information from mdn about JavaScript.'; + this.usage = 'mdn [.property/.method]'; + this.permissions = 0; + this.guildOnly = false; + this.enabled = true; + this.aliases = ['js']; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return this.client.commands.get('help').run(message, [this.name]); + args[0] = args[0].replace('.', '.prototype.'); + args[0] = args[0].replace('#', '.prototype.'); + + let res; + try { + res = await axios.get(`https://mdn.pleb.xyz/search?q=${args[0]}`); + } catch (err) { + this.error(message.channel, 'Please try again later, something unexpected happened.'); + return this.client.util.handleError(err, message, this); + } + const { data } = res; + if (!data || !data.Title || !data.Summary || !data.URL) return this.error(message.channel, 'Could not find information. Try something else.'); + + // Do not touch to the next block of code. Don't even look at it. your brain could stop working + data.Summary = data.Summary.replace(//g, ''); + data.Summary = data.Summary.replace(/<\/strong><\/code>/g, ''); + data.Summary = data.Summary.replace(/|<\/code>/g, '`'); + data.Summary = data.Summary.replace(`/|<\/strong>/g, '**');` + const url = data.Summary.match(//); + if (url !== null) { + url[0] = url[0].replace('/, `[${name[0]}](https://developer.mozilla.org${url[0]})`); + } + + const embed = new RichEmbed(); + embed.setAuthor('Mozilla Developer Network', 'https://i.imgur.com/DFGXabG.png', 'https://developer.mozilla.org/en-US'); + embed.setTitle(data.Title); + embed.setDescription(data.Summary); + embed.setURL(`developer.mozilla.org${data.URL}`); + embed.setColor(0x066fad); + embed.setFooter(this.client.user.username, this.client.user.avatarURL); + embed.setTimestamp(); + + return message.channel.createMessage({ embed }); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +}