diff --git a/commands/general/advice.js b/commands/general/advice.js index 8a07d5ad..f72ebc97 100644 --- a/commands/general/advice.js +++ b/commands/general/advice.js @@ -1,5 +1,5 @@ const { Command } = require('discord-akairo'); -const Discord = require('discord.js'); +const { MessageEmbed } = require('discord.js'); const fetch = require('node-fetch'); class AdviceCommand extends Command { @@ -19,8 +19,7 @@ class AdviceCommand extends Command { fetch('http://api.adviceslip.com/advice').then((response) => { return response.json(); }).then((response) => { - const adviceEmbed = new Discord.RichEmbed() - .setColor('#ff9900') + const adviceEmbed = new MessageEmbed() .setColor('#ff9900') .setTitle(response.slip.slip_id) .setDescription(response.slip.advice); diff --git a/commands/general/reddit.js b/commands/general/reddit.js index de27f319..0a9ff9e9 100644 --- a/commands/general/reddit.js +++ b/commands/general/reddit.js @@ -1,5 +1,5 @@ const { Command } = require('discord-akairo'); -const Discord = require('discord.js'); +const { MessageEmbed } = require('discord.js'); const fetch = require('node-fetch'); class RedditCommand extends Command { @@ -39,8 +39,7 @@ class RedditCommand extends Command { } if (response.data.children[i].data.over_18 == true) return message.channel.send('No nsfw'); - const redditEmbed = new Discord.RichEmbed() - .setColor('#ff9900') + const redditEmbed = new MessageEmbed() .setColor('#ff9900') .setTitle(response.data.children[i].data.title) .setImage(response.data.children[i].data.url) .setURL('https://reddit.com' + response.data.children[i].data.permalink) diff --git a/commands/utility/ping.js b/commands/utility/ping.js index f46743e7..d496f218 100644 --- a/commands/utility/ping.js +++ b/commands/utility/ping.js @@ -16,7 +16,7 @@ class PingCommand extends Command { async exec(message) { return message.util.reply('Pong!').then(sent => { const timeDiff = (sent.editedAt || sent.createdAt) - (message.editedAt || message.createdAt); - const text = `šŸ”‚\u2000**RTT**: ${timeDiff} ms\nšŸ’Ÿ\u2000**Heartbeat**: ${Math.round(this.client.ping)} ms`; + const text = `šŸ”‚\u2000**PING**: ${timeDiff} ms`; return message.util.reply(`Pong!\n${text}`); }); } diff --git a/commands/utility/server.js b/commands/utility/server.js index 1de95ccd..9c7658ae 100644 --- a/commands/utility/server.js +++ b/commands/utility/server.js @@ -1,4 +1,5 @@ const { Command } = require('discord-akairo'); +const { MessageEmbed } = require('discord.js'); class ServerCommand extends Command { constructor() { @@ -15,19 +16,17 @@ class ServerCommand extends Command { } async exec(message) { - const customresponse = require(`../tag/${message.guild.id}.json`); + const customresponse = require(`../../tag/${message.guild.id}.json`); var count = Object.keys(customresponse).length; - - - const addEmbed = { - color: 0x0099ff, - title: 'Stats of the server', - thumbnail: { - url: `${message.guild.iconURL}`, - }, - description: `Member: **${message.guild.memberCount}** \nChannel number: **${message.guild.channels.size}**\nGuild created at **${message.guild.createdAt}**\nOwner: **${message.guild.owner}**\nTag number: **${count}**`, - }; + const addEmbed = new MessageEmbed() + .setColor('#0099ff') + .setTitle('Stats of the server') + .setAuthor(message.author.username) + .setDescription(`Member: **${message.guild.memberCount}** \nChannel number: **${message.guild.channels.size}**\nGuild created at **${message.guild.createdAt}**\nOwner: **${message.guild.owner}**\nTag number: **${count}**`) + .setTimestamp(); + + message.channel.send({ embed: addEmbed }); } diff --git a/commands/utility/taglist.js b/commands/utility/taglist.js index 0927a7d1..e9505282 100644 --- a/commands/utility/taglist.js +++ b/commands/utility/taglist.js @@ -1,5 +1,5 @@ const { Command } = require('discord-akairo'); -const Discord = require('discord.js'); +const { MessageEmbed } = require('discord.js'); const reload = require('auto-reload'); const fs = require('fs'); @@ -31,8 +31,7 @@ class taglistCommand extends Command { let json = JSON.stringify(data); json = json.replace(/[{}'\\]+/g, ''); json = json.replace(/,+/g, '\n'); - const tagEmbed = new Discord.RichEmbed() - .setColor('#ff9900') + const tagEmbed = new MessageEmbed() .setColor('#ff9900') .setTitle('Tags list') .setDescription(`Trigger:Response\n\n${json}`) .setFooter(`You have ${count} tags on this server`); diff --git a/commands/utility/translate.js b/commands/utility/translate.js index d1142c07..6b85f7be 100644 --- a/commands/utility/translate.js +++ b/commands/utility/translate.js @@ -1,5 +1,5 @@ const { Command } = require('discord-akairo'); -const Discord = require('discord.js'); +const { MessageEmbed } = require('discord.js'); const fetch = require('node-fetch'); const { yandexAPI } = require('../../config.json'); @@ -8,11 +8,13 @@ class TranslationCommand extends Command { super('translation', { aliases: ['translation', 'trn'], category: 'utility', - split: 'sticky', args: [ { id: 'language', - type: 'string', + type: ['az','ml','sq','mt','am','mk','en','mi','ar','mr','hy','mhr','af','mn','eu','de','ba','ne','be','no','bn','pa','my','pap','bg','fa','bs','pl','cy','pt','hu','ro','vi','ru','ht','ceb','gl','sr','nl','si','mrj','sk','el','sl','ka','sw','gu','su','da','tg','he','th','yi','tl','id','ta','ga','tt','it','te','is','tr','es','udm','kk','uz','kn','uk','ca','ur','ky','fi','zh','fr','ko','hi','xh','hr','km','cs','lo','sv','la','gd','lv','et','lt','eo','lb','jv','mg','ja','ms'], + prompt: { + retry: 'That\'s not a valid language! try again.' + }, default: 'en' }, { @@ -23,7 +25,7 @@ class TranslationCommand extends Command { description: { content: 'Translate what you send in your desired language. You can find the language code here: https://tech.yandex.com/translate/doc/dg/concepts/api-overview-docpage/', usage: '[language code] [Text to translate]', - examples: ['fr What are we doing today?', 'en Que faisons-nous aujourd\'hui?'] + examples: ['fr "What are we doing today?"', 'en "Que faisons-nous aujourd\'hui?"'] } }); } @@ -43,7 +45,7 @@ class TranslationCommand extends Command { return message.channel.send('An error has occured'); - const translationEmbed = new Discord.RichEmbed() + const translationEmbed = new MessageEmbed() .setColor('#0099ff') .setTitle('Asked for the following translation:') .setAuthor(message.author.username) diff --git a/commands/utility/updoot.js b/commands/utility/updoot.js index 6a739c2e..35e5f094 100644 --- a/commands/utility/updoot.js +++ b/commands/utility/updoot.js @@ -1,4 +1,5 @@ const { Command } = require('discord-akairo'); +const { MessageEmbed } = require('discord.js'); class UpdootCommand extends Command { constructor() { @@ -15,17 +16,14 @@ class UpdootCommand extends Command { } async exec(message) { - const upDoot = { - color: 0x93C54B, - title: 'Vote for my bot', - url: 'https://discordbots.org/bot/377563711927484418/vote', - description: 'You can vote for my bot if you think the bot is awesome!', - timestamp: new Date(), - footer: { - text: 'Thanks for the updoots', - icon_url: 'https://cdn.discordapp.com/avatars/377563711927484418/1335d202aa466dbeaa4ed2e4b616484a.png?size=2048', - }, - }; + const upDoot = new MessageEmbed() + .setColor('#0099ff') + .setTitle('Vote for my bot') + .setURL('https://discordbots.org/bot/377563711927484418/vote') + .setAuthor(message.author.username) + .setDescription('You can vote for my bot if you think the bot is awesome!') + .setTimestamp() + .setFooter('Thanks for the updoots', 'https://cdn.discordapp.com/avatars/377563711927484418/1335d202aa466dbeaa4ed2e4b616484a.png?size=2048'); message.channel.send({ embed: upDoot }); } diff --git a/index.js b/index.js index f21e4a57..7db9c31a 100644 --- a/index.js +++ b/index.js @@ -1,33 +1,49 @@ -const { AkairoClient } = require('discord-akairo'); -const { token, prefix, ownerID, statsChannel } = require('./config.json'); +const { AkairoClient, CommandHandler, InhibitorHandler, ListenerHandler } = require('discord-akairo'); +const { token, prefix, ownerID } = require('./config.json'); -const client = new AkairoClient({ - ownerID: ownerID, - prefix: prefix, - allowMention: true, - handleEdits: true, - emitters: { - process - }, - commandUtil: true, - commandUtilLifetime: 600000, - commandDirectory: './commands/', - inhibitorDirectory: './inhibitors/', - listenerDirectory: './listeners/' -}, { - disableEveryone: true -}); -// Ready messages dosent work on the listeners event for some reasons -client.on('ready', async () => { - // Send stats to the console - console.log(`\x1b[32mLogged in as \x1b[34m${client.user.tag}\x1b[0m! (\x1b[33m${client.user.id}\x1b[0m)`); - console.log(`Ready to serve in \x1b[33m${client.channels.size}\x1b[0m channels on \x1b[33m${client.guilds.size}\x1b[0m servers, for a total of \x1b[33m${client.users.size}\x1b[0m users. \x1b${client.readyAt}\x1b[0m`); - // Send stats to the 'stats' channel in the support server if its not the test bot - if (client.user.id == 377563711927484418) { - const channel = client.channels.get(statsChannel); - channel.send(`Ready to serve in ${client.channels.size} channels on ${client.guilds.size} servers, for a total of ${client.users.size} users. ${client.readyAt}`); - client.user.setActivity(`${prefix} feedback to tell me what you think of the bot! | ${prefix} help`); } -}); +class hahaYesClient extends AkairoClient { + constructor() { + super({ + ownerID: ownerID, + }, { + disableEveryone: true + }); + this.commandHandler = new CommandHandler(this, { + directory: './commands/', + prefix: prefix, + commandUtil: true, + commandUtilLifetime: 600000, + allowMention: true, + handleEdits: true, + }); + + this.inhibitorHandler = new InhibitorHandler(this, { + directory: './inhibitors/', + emitters: { + process + }, + }); + + this.listenerHandler = new ListenerHandler(this, { + directory: './listeners/' + }); + + this.listenerHandler.setEmitters({ + commandHandler: this.commandHandler, + inhibitorHandler: this.inhibitorHandler, + listenerHandler: this.listenerHandler + }); + + this.commandHandler.useInhibitorHandler(this.inhibitorHandler); + this.commandHandler.useListenerHandler(this.listenerHandler); + + this.listenerHandler.loadAll(); + this.inhibitorHandler.loadAll(); + this.commandHandler.loadAll(); + } +} + +const client = new hahaYesClient(); client.login(token); \ No newline at end of file diff --git a/listeners/UnhandledRejection.js b/listeners/UnhandledRejection.js deleted file mode 100644 index e141f3d2..00000000 --- a/listeners/UnhandledRejection.js +++ /dev/null @@ -1,16 +0,0 @@ -const { Listener } = require('discord-akairo'); - -class UnhandledRejectionListener extends Listener { - constructor() { - super('unhandledRejection', { - eventName: 'unhandledRejection', - emitter: 'process' - }); - } - - exec(error) { - console.error(error); - } -} - -module.exports = UnhandledRejectionListener; \ No newline at end of file diff --git a/listeners/guildCreate.js b/listeners/guildCreate.js index 4b33e68f..c20b9f2c 100644 --- a/listeners/guildCreate.js +++ b/listeners/guildCreate.js @@ -1,5 +1,5 @@ const { Listener } = require('discord-akairo'); -const Discord = require('discord.js'); +const { MessageEmbed } = require('discord.js'); const { statsChannel } = require('../config.json'); @@ -14,7 +14,7 @@ class guildCreateListener extends Listener { async exec(guild) { console.log(`${guild.name}\n${guild.memberCount} users\nOwner: ${guild.owner.user.username}\nOwner ID: ${guild.owner}`); const channel = this.client.channels.get(statsChannel); - const addEmbed = new Discord.RichEmbed() + const addEmbed = new MessageEmbed() .setColor('#52e80d') .setTitle('Someone added me ! YAY :D') .setURL('https://www.youtube.com/watch?v=6n3pFFPSlW4') diff --git a/listeners/guildDelete.js b/listeners/guildDelete.js index d2e884da..c6ba9741 100644 --- a/listeners/guildDelete.js +++ b/listeners/guildDelete.js @@ -1,5 +1,5 @@ const { Listener } = require('discord-akairo'); -const Discord = require('discord.js'); +const { MessageEmbed } = require('discord.js'); const { statsChannel } = require('../config.json'); @@ -15,7 +15,7 @@ class guildCreateListener extends Listener { console.log(`***BOT KICKED***\n${guild.name}\n${guild.memberCount} users\nOwner: ${guild.owner.user.username}\nOwner ID: ${guild.owner}\n***BOT KICKED***`); const channel = this.client.channels.get(statsChannel); - const kickEmbed = new Discord.RichEmbed() + const kickEmbed = new MessageEmbed() .setColor('#FF0000') .setTitle('They kicked me out :(') .setURL('https://www.youtube.com/watch?v=6n3pFFPSlW4') diff --git a/listeners/messageReactionAdd.js b/listeners/messageReactionAdd.js index 27095825..4c2e247e 100644 --- a/listeners/messageReactionAdd.js +++ b/listeners/messageReactionAdd.js @@ -1,5 +1,5 @@ const { Listener } = require('discord-akairo'); -const Discord = require('discord.js'); +const { MessageEmbed } = require('discord.js'); const reload = require('auto-reload'); class MessageReactionAddListener extends Listener { @@ -18,11 +18,11 @@ class MessageReactionAddListener extends Listener { let starboardChannel = reload(`../starboard/${reaction.message.guild.id}.json`); const channel = this.client.channels.get(starboardChannel['starboard']); - const starEmbed = new Discord.RichEmbed() - .setColor() - .setDescription(messageContent) - .setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL) - .setTimestamp() + const starEmbed = new MessageEmbed() + .setColor() + .setDescription(messageContent) + .setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL) + .setTimestamp(); channel.send({ embed: starEmbed}); return channel.send(`From: ${reaction.message.channel}\n${messageAttachments}`); @@ -31,11 +31,11 @@ class MessageReactionAddListener extends Listener { let shameboardChannel = reload(`../starboard/${message.guild.id}.json`); const channel = client.channels.get(shameboardChannel['shameboard']); - const starEmbed = new Discord.RichEmbed() - .setColor() - .setDescription(messageContent) - .setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL) - .setTimestamp() + const starEmbed = new MessageEmbed() + .setColor() + .setDescription(messageContent) + .setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL) + .setTimestamp(); try { channel.send({ embed: starEmbed}); diff --git a/listeners/ready.js b/listeners/ready.js new file mode 100644 index 00000000..a5b8d45b --- /dev/null +++ b/listeners/ready.js @@ -0,0 +1,26 @@ +const { Listener } = require('discord-akairo'); +const { prefix, statsChannel } = require('../config.json'); + + +class ReadyListener extends Listener { + constructor() { + super('ready', { + emitter: 'client', + event: 'ready' + }); + } + + async exec() { + // Send stats to the console + console.log(`\x1b[32mLogged in as \x1b[34m${this.client.user.tag}\x1b[0m! (\x1b[33m${this.client.user.id}\x1b[0m)`); + console.log(`Ready to serve in \x1b[33m${this.client.channels.size}\x1b[0m channels on \x1b[33m${this.client.guilds.size}\x1b[0m servers, for a total of \x1b[33m${this.client.users.size}\x1b[0m users. \x1b${this.client.readyAt}\x1b[0m`); + // Send stats to the 'stats' channel in the support server if its not the test bot + if (this.client.user.id == 377563711927484418) { + const channel = this.client.channels.get(statsChannel); + channel.send(`Ready to serve in ${this.client.channels.size} channels on ${this.client.guilds.size} servers, for a total of ${this.client.users.size} users. ${this.client.readyAt}`); + this.client.user.setActivity(`${prefix} feedback to tell me what you think of the bot! | ${prefix} help`); + } + } +} + +module.exports = ReadyListener; \ No newline at end of file