diff --git a/.eslintrc.json b/.eslintrc.json index 82ca605..73bee58 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -16,10 +16,6 @@ "error", "tab" ], - "linebreak-style": [ - "error", - "windows" - ], "quotes": [ "error", "single" diff --git a/.gitignore b/.gitignore index 2c3f6c8..666e3f8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,11 +4,8 @@ node_modules node_modules\ .vscode video.mp4 -json/autoresponse.json json/blacklist.json json/customresponse.json -tag/* -starboard/* tts.mp3 ttsvc.mp3 -package.json +starboard/487640086859743232.json diff --git a/commands/admin/tag.js b/commands/admin/tag.js index 6324c2e..8d6f946 100644 --- a/commands/admin/tag.js +++ b/commands/admin/tag.js @@ -37,7 +37,7 @@ class TagCommand extends Command { fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) { if (err) { - fs.writeFile(`./tag/${message.guild.id}.json`, `{'${trigger}':'${response}'}`, function (err) { + fs.writeFile(`./tag/${message.guild.id}.json`, `{"${trigger}":"${response}"}`, function (err) { if (err) { console.log(err); @@ -49,7 +49,6 @@ class TagCommand extends Command { json = JSON.stringify(customresponse); //convert it back to json fs.writeFile(`./tag/${message.guild.id}.json`, json, 'utf8', function (err) { if (err) { - return console.log(err); } }); diff --git a/commands/general/advice.js b/commands/general/advice.js index 8a07d5a..c4fd9d7 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,7 +19,7 @@ class AdviceCommand extends Command { fetch('http://api.adviceslip.com/advice').then((response) => { return response.json(); }).then((response) => { - const adviceEmbed = new Discord.RichEmbed() + const adviceEmbed = new MessageEmbed() .setColor('#ff9900') .setTitle(response.slip.slip_id) .setDescription(response.slip.advice); diff --git a/commands/general/clap.js b/commands/general/clap.js index 732d80c..4869cb4 100644 --- a/commands/general/clap.js +++ b/commands/general/clap.js @@ -21,6 +21,8 @@ class ClapCommand extends Command { } async exec(message, args) { + if (!args.text) + return; let clap = args.text.replace(/ /g, ' šŸ‘ '); message.delete(); message.channel.send(`${clap} šŸ‘`); diff --git a/commands/general/emotesay.js b/commands/general/emotesay.js index b90295d..413fbc5 100644 --- a/commands/general/emotesay.js +++ b/commands/general/emotesay.js @@ -23,6 +23,8 @@ class EmotesayCommand extends Command { async exec(message, args) { let text = args.text; + if (!text) + return; message.delete(); let emojiArray = []; diff --git a/commands/general/reddit.js b/commands/general/reddit.js index de27f31..ad23aea 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 { @@ -11,7 +11,7 @@ class RedditCommand extends Command { args: [ { id: 'sub', - type: 'string' + type: 'string', } ], description: { @@ -25,6 +25,8 @@ class RedditCommand extends Command { async exec(message, args) { let sub = args.sub; let i, a; + if (!sub) + return; fetch('https://www.reddit.com/r/' + sub + '.json?limit=100').then((response) => { return response.json(); @@ -39,8 +41,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/general/say.js b/commands/general/say.js index 71ee8f4..534f865 100644 --- a/commands/general/say.js +++ b/commands/general/say.js @@ -15,13 +15,15 @@ class SayCommand extends Command { description: { content: 'Repeat what you say but can also replace ', usage: '[text]', - examples: ['[member] is a big [adverbs] [verb]'] + examples: ['[member] is a big [adverb] [verb]'] } }); } async exec(message, args) { let text = args.text; + if (!text) + return; // Load all the different files const verb = require('../../dictionary/verbs.json'); diff --git a/commands/general/sayd.js b/commands/general/sayd.js index 6a360e4..3585a7e 100644 --- a/commands/general/sayd.js +++ b/commands/general/sayd.js @@ -23,6 +23,8 @@ class SaydCommand extends Command { async exec(message, args) { let text = args.text; + if (!text) + return; // Load all the different files const verb = require('../../dictionary/verbs.json'); diff --git a/commands/images/idubbbz.js b/commands/images/idubbbz.js index 9c8569a..b340774 100644 --- a/commands/images/idubbbz.js +++ b/commands/images/idubbbz.js @@ -12,7 +12,8 @@ class IdubbbzCommand extends Command { args: [ { id: 'text', - type: 'string' + type: 'string', + default: 'nigger fagget' }, { id: 'image', diff --git a/commands/images/idubbbzpaint.js b/commands/images/idubbbzpaint.js index e2cd914..f1fd833 100644 --- a/commands/images/idubbbzpaint.js +++ b/commands/images/idubbbzpaint.js @@ -11,7 +11,8 @@ class IdubbbzPaintCommand extends Command { args: [ { id: 'text', - type: 'string' + type: 'string', + default: 'Perfection' }, { id: 'image', diff --git a/commands/utility/avatar.js b/commands/utility/avatar.js index 39de925..d434058 100644 --- a/commands/utility/avatar.js +++ b/commands/utility/avatar.js @@ -20,10 +20,10 @@ class AvatarCommand extends Command { } async exec(message, args) { - if (!args.user) // While these kind of statments work you really should use {} - return message.channel.send(`Your avatar:\n${message.author.displayAvatarURL}`); + if (!args.user) + return message.channel.send(`Your avatar:\n${message.author.displayAvatarURL()}`); else - return message.channel.send(`${args.user.username}'s avatar:\n${args.user.displayAvatarURL}`); + return message.channel.send(`${args.user.username}'s avatar:\n${args.user.displayAvatarURL()}`); } } diff --git a/commands/utility/credit.js b/commands/utility/credit.js new file mode 100644 index 0000000..0c4f04c --- /dev/null +++ b/commands/utility/credit.js @@ -0,0 +1,21 @@ +const { Command } = require('discord-akairo'); + +class creditCommand extends Command { + constructor() { + super('credit', { + aliases: ['credit'], + category: 'utility', + description: { + content: 'Show credits for the bot', + usage: '(optional) [@user]', + examples: ['', '@user'] + } + }); + } + + async exec(message) { + message.channel.send('Thanks to Tina the Cyclops girl#0064 for inspiring me making a bot,\nThanks to discord.js team for making discord.js\nThanks to 1computer1 for making discord-akairo and the help command'); + } +} + +module.exports = creditCommand; \ No newline at end of file diff --git a/commands/utility/invite.js b/commands/utility/invite.js index 79a94ae..aa3f75d 100644 --- a/commands/utility/invite.js +++ b/commands/utility/invite.js @@ -15,7 +15,7 @@ class InviteCommand extends Command { } async exec(message) { - message.channel.send('Check your dm') + message.channel.send('Check your dm'); return message.author.send(`You can add me from here: https://discordapp.com/oauth2/authorize?client_id=${this.client.user.id}&scope=bot&permissions=0\nYou can also join my support server over here: ${supportServer} come and say hi :)`); } } diff --git a/commands/utility/ping.js b/commands/utility/ping.js index f46743e..d496f21 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 1de95cc..9c7658a 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/stats.js b/commands/utility/stats.js index 9113caf..b649f2d 100644 --- a/commands/utility/stats.js +++ b/commands/utility/stats.js @@ -1,4 +1,6 @@ const { Command } = require('discord-akairo'); +const { MessageEmbed } = require('discord.js'); +const reload = require('auto-reload'); class StatsCommand extends Command { constructor() { @@ -14,6 +16,13 @@ class StatsCommand extends Command { } async exec(message) { + const autoresponse = reload('../../json/autoresponse.json'); + let autoresponseStatus; + if (autoresponse[message.channel.id] == undefined || autoresponse[message.channel.id] == 'disable') + autoresponseStatus = 'disabled'; + else if (autoresponse[message.channel.id] == 'enable') + autoresponseStatus = 'enabled'; + let totalSeconds = (this.client.uptime / 1000); let days = Math.floor(totalSeconds / 86400); let hours = Math.floor(totalSeconds / 3600); @@ -21,7 +30,21 @@ class StatsCommand extends Command { let minutes = Math.floor(totalSeconds / 60); let seconds = totalSeconds.toFixed(0) % 60; let uptime = `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`; - return message.channel.send(`Servers: \`${this.client.guilds.size}\`\nChannels: \`${this.client.channels.size}\`\nUsers: \`${this.client.users.size}\`\nBot uptime: \`${uptime}\``); + const used = process.memoryUsage().heapUsed / 1024 / 1024; + + const statsEmbed = new MessageEmbed() + .setColor('#0099ff') + .setTitle('Bot stats') + .setAuthor('Haha yes') + .addField('Servers', this.client.guilds.size, true) + .addField('Channels', this.client.channels.size, true) + .addField('Users', this.client.users.size, true) + .addField('Uptime', uptime, true) + .addField('Ram usage', `${Math.round(used * 100) / 100} MB`, true) + .addField('Autoresponse in this channel',autoresponseStatus,true) + .setTimestamp(); + + return message.channel.send(statsEmbed); } } diff --git a/commands/utility/taglist.js b/commands/utility/taglist.js index 4321282..9bba8cc 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'); @@ -18,10 +18,13 @@ class taglistCommand extends Command { } async exec(message) { - let customresponse = reload(`../../tag/${message.guild.id}.json`); - let count = Object.keys(customresponse).length; - - + try { + var customresponse = reload(`../../tag/${message.guild.id}.json`); + var count = Object.keys(customresponse).length; + } catch (err) { + message.channel.send('An error has occured, do you have any tags on the server?'); + console.error(err); + } await fs.readFile(`./tag/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) { if (err) { console.log(err); @@ -31,7 +34,7 @@ class taglistCommand extends Command { let json = JSON.stringify(data); json = json.replace(/[{}'\\]+/g, ''); json = json.replace(/,+/g, '\n'); - const tagEmbed = new Discord.RichEmbed() + const tagEmbed = new MessageEmbed() .setColor('#ff9900') .setTitle('Tags list') .setDescription(`Trigger:Response\n\n${json}`) @@ -40,7 +43,6 @@ class taglistCommand extends Command { message.channel.send(tagEmbed); }); - message.channel.send('An error has occured, do you have any tags on the server?'); } } diff --git a/commands/utility/translate.js b/commands/utility/translate.js index d1142c0..6b85f7b 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 6a739c2..35e5f09 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 f21e4a5..579f034 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: 60000, + 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/json/autoresponse.json b/json/autoresponse.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/json/autoresponse.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/json/starboard.json b/json/starboard.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/json/starboard.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/listeners/UnhandledRejection.js b/listeners/UnhandledRejection.js deleted file mode 100644 index e141f3d..0000000 --- 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/commandblocked.js b/listeners/commandblocked.js index fc92a05..6fed8c7 100644 --- a/listeners/commandblocked.js +++ b/listeners/commandblocked.js @@ -4,7 +4,7 @@ class CommandBlockedListener extends Listener { constructor() { super('commandBlocked', { emitter: 'commandHandler', - eventName: 'commandBlocked' + event: 'commandBlocked' }); } diff --git a/listeners/guildCreate.js b/listeners/guildCreate.js index 4b33e68..aba2096 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'); @@ -7,14 +7,14 @@ class guildCreateListener extends Listener { constructor() { super('guildCreate', { emitter: 'client', - eventName: 'guildCreate' + event: 'guildCreate' }); } 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 d2e884d..7c993c5 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'); @@ -7,7 +7,7 @@ class guildCreateListener extends Listener { constructor() { super('guildDelete', { emitter: 'client', - eventName: 'guildDelete' + event: 'guildDelete' }); } @@ -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/message.js b/listeners/message.js index 95040f3..2085e02 100644 --- a/listeners/message.js +++ b/listeners/message.js @@ -4,20 +4,26 @@ const reactObject = require('../json/react.json'); const imgResponseObject = require('../json/imgreply.json'); const reload = require('auto-reload'); -class MessageListener extends Listener { +class messageListener extends Listener { constructor() { super('message', { emitter: 'client', - eventName: 'message' + event: 'message' }); } async exec(message) { let autoresponse = reload('../json/autoresponse.json'); let message_content = message.content.toLowerCase(); - + let customresponse = reload(`../tag/${message.guild.id}.json`); + if (message.author.bot) return; { - + + // User autoresponse + if(customresponse[message_content]) { + message.channel.send(customresponse[message_content]); + } + // If autoresponse is enable send the response if(autoresponse[message.channel.id] == 'enable') { // Reply with images as attachement @@ -38,14 +44,9 @@ class MessageListener extends Listener { } else if (message_content.includes('jeff')) { message.react('496028845967802378'); } - } - let customresponse = reload(`../tag/${message.guild.id}.json`); - // User autoresponse - if(customresponse[message_content]) { - message.channel.send(customresponse[message_content]); - } + } } } } -module.exports = MessageListener; \ No newline at end of file +module.exports = messageListener; \ No newline at end of file diff --git a/listeners/messageReactionAdd.js b/listeners/messageReactionAdd.js index 2709582..d4485ad 100644 --- a/listeners/messageReactionAdd.js +++ b/listeners/messageReactionAdd.js @@ -1,50 +1,56 @@ const { Listener } = require('discord-akairo'); -const Discord = require('discord.js'); +const { MessageEmbed } = require('discord.js'); const reload = require('auto-reload'); +let messageID = require('../json/starboard.json'); class MessageReactionAddListener extends Listener { constructor() { super('messagereactionadd', { emitter: 'client', - eventName: 'messageReactionAdd' + event: 'messageReactionAdd' }); } - async exec(reaction, message, client) { + async exec(reaction) { let messageContent = reaction.message.content; let messageAttachments = reaction.message.attachments.map(u=> `${u.url}`); if (reaction.emoji.name === 'šŸŒŸ' && reaction.count === 4) { + if (messageID.includes(reaction.message.id)) + return console.log('Message already in starboard!'); + + messageID.push(reaction.message.id); + 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}`); + return channel.send(`From: ${reaction.message.channel} ID: ${reaction.message.id} \n${messageAttachments}`); } if (reaction.emoji.name === 'āœ”' && reaction.count === 4) { - let shameboardChannel = reload(`../starboard/${message.guild.id}.json`); - const channel = client.channels.get(shameboardChannel['shameboard']); + if (messageID.includes(reaction.message.id)) + return console.log('Message already in starboard!'); - const starEmbed = new Discord.RichEmbed() - .setColor() - .setDescription(messageContent) - .setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL) - .setTimestamp() + messageID.push(reaction.message.id); - try { - channel.send({ embed: starEmbed}); - await channel.send(messageAttachments); - } catch(err) { - console.error('There is no shameboard'); - } + let shameboardChannel = reload(`../starboard/${reaction.message.guild.id}.json`); + const channel = this.client.channels.get(shameboardChannel['shameboard']); + + const shameEmbed = new MessageEmbed() + .setColor() + .setDescription(messageContent) + .setAuthor(reaction.message.author.username, reaction.message.author.displayAvatarURL) + .setTimestamp(); + + channel.send({ embed: shameEmbed}); + return channel.send(`From: ${reaction.message.channel} ID: ${reaction.message.id} \n${messageAttachments}`); } - } } diff --git a/listeners/ready.js b/listeners/ready.js new file mode 100644 index 0000000..a5b8d45 --- /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 diff --git a/package.json b/package.json index e495186..c590a39 100644 --- a/package.json +++ b/package.json @@ -1,37 +1,32 @@ { - "name": "discordbot", - "version": "1.0.0", - "description": "A simple discord bot made with discord.js and commando", + "name": "hahayes", + "version": "2.1.0", "main": "index.js", "dependencies": { "auto-reload": "^0.1.0", "canvas": "^2.2.0", - "eslint": "^5.11.1", - "eslint-config-standard": "^12.0.0", - "discord.js": "^11.4.2", - "eslint-plugin-import": "^2.14.0", - "discord-akairo": "^7.5.5", - "eslint-plugin-node": "^8.0.0", - "eslint-plugin-promise": "^4.0.1", - "eslint-plugin-standard": "^4.0.0", + "discord-akairo": "github:1Computer1/discord-akairo#master", + "discord.js": "github:discordjs/discord.js#master", "node-fetch": "^2.3.0", "reload-json": "^0.3.1", "superagent": "^4.1.0", "youtube-dl": "^1.12.2" }, - "devDependencies": {}, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "devDependencies": { + "eslint": "^5.11.1", + "eslint-config-standard": "^12.0.0", + "eslint-plugin-import": "^2.14.0", + "eslint-plugin-node": "^8.0.0", + "eslint-plugin-promise": "^4.0.1", + "eslint-plugin-standard": "^4.0.0" }, "repository": { "type": "git", "url": "git+https://gitlab.com/LoicBersier/DiscordBot.git" }, - "keywords": [], - "author": "", - "license": "ISC", "bugs": { "url": "https://gitlab.com/LoicBersier/DiscordBot/issues" }, - "homepage": "https://gitlab.com/LoicBersier/DiscordBot#readme" + "homepage": "https://gitlab.com/LoicBersier/DiscordBot#readme", + "description": "" }