diff --git a/commands/admin/autoresponse.js b/commands/admin/autoresponse.js index cad071b..de1d309 100644 --- a/commands/admin/autoresponse.js +++ b/commands/admin/autoresponse.js @@ -38,7 +38,7 @@ class autoresponseCommand extends Command { fs.readFile('./json/autoresponse.json', 'utf8', function readFileCallback(err, data) { if (err) { - fs.close(); + console.log(err); } else { @@ -48,14 +48,14 @@ class autoresponseCommand extends Command { json = json.replace(/[<#>]/g, ''); fs.writeFile('./json/autoresponse.json', json, 'utf8', function (err) { if (err) { - fs.close(); + return console.log(err); } }); } }); - fs.close(); + return message.channel.send('Auto response have been disable/enable on every channel'); } else if (text == 'disable' || 'enable') { @@ -68,7 +68,7 @@ class autoresponseCommand extends Command { json = JSON.stringify(autoresponse); //convert it back to json fs.writeFile('./json/autoresponse.json', json, 'utf8', function (err) { if (err) { - fs.close(); + return console.log(err); } }); @@ -76,7 +76,7 @@ class autoresponseCommand extends Command { }); } - fs.close(); + return message.channel.send(`Autoresponse have been ${text}d`); } } diff --git a/commands/admin/shameboard.js b/commands/admin/shameboard.js index 406dd51..e3aa8c2 100644 --- a/commands/admin/shameboard.js +++ b/commands/admin/shameboard.js @@ -25,7 +25,7 @@ class shameboardCommand extends Command { if (err) { console.log(err); } - fs.close(); + return message.channel.send('This channel have been set as the shameboard'); }); } else { @@ -34,13 +34,13 @@ class shameboardCommand extends Command { var json = JSON.stringify(shameboard); //convert it back to json fs.writeFile(`./starboard/${message.guild.id}.json`, json, 'utf8', function (err) { if (err) { - fs.close(); + return console.log(err); } }); } }); - fs.close(); + return message.channel.send('This channel have been set as the shameboard'); } } diff --git a/commands/admin/starboard.js b/commands/admin/starboard.js index f4cdf8b..7ceb261 100644 --- a/commands/admin/starboard.js +++ b/commands/admin/starboard.js @@ -25,7 +25,7 @@ class StarBoardCommand extends Command { if (err) { console.log(err); } - fs.close(); + return message.channel.send('This channel have been set as the starboard'); }); } else { @@ -34,13 +34,13 @@ class StarBoardCommand extends Command { var json = JSON.stringify(starboard); //convert it back to json fs.writeFile(`./starboard/${message.guild.id}.json`, json, 'utf8', function (err) { if (err) { - fs.close(); + return console.log(err); } }); } }); - fs.close(); + return message.channel.send('This channel have been set as the starboard'); } } diff --git a/commands/admin/tag.js b/commands/admin/tag.js index 5bc207e..8d6f946 100644 --- a/commands/admin/tag.js +++ b/commands/admin/tag.js @@ -37,9 +37,9 @@ 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) { - fs.close(); + console.log(err); } }); @@ -49,14 +49,13 @@ 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) { - fs.close(); return console.log(err); } }); } }); - fs.close(); + return message.channel.send(`autoresponse have been set to ${trigger} : ${response}`); } } diff --git a/commands/admin/untag.js b/commands/admin/untag.js index c41e1db..f8785d7 100644 --- a/commands/admin/untag.js +++ b/commands/admin/untag.js @@ -40,14 +40,14 @@ class UnTagCommand extends Command { json = JSON.stringify(customresponse); //convert it back to json fs.writeFile(`./tag/${message.guild.id}.json`, json, 'utf8', function (err) { if (err) { - fs.close(); + return console.log(err); } }); } }); - fs.close(); + return message.channel.send(`The following autoresponse have been deleted: ${trigger}`); } diff --git a/commands/general/advice.js b/commands/general/advice.js index f72ebc9..c4fd9d7 100644 --- a/commands/general/advice.js +++ b/commands/general/advice.js @@ -19,7 +19,8 @@ class AdviceCommand extends Command { fetch('http://api.adviceslip.com/advice').then((response) => { return response.json(); }).then((response) => { - const adviceEmbed = new MessageEmbed() .setColor('#ff9900') + const adviceEmbed = new MessageEmbed() + .setColor('#ff9900') .setTitle(response.slip.slip_id) .setDescription(response.slip.advice); 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 0a9ff9e..e2444d7 100644 --- a/commands/general/reddit.js +++ b/commands/general/reddit.js @@ -11,7 +11,10 @@ class RedditCommand extends Command { args: [ { id: 'sub', - type: 'string' + type: 'string', + prompt: { + retry: 'That\'s not a valid subreddit! try again.' + }, } ], description: { 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/general/tts.js b/commands/general/tts.js index 82bdf92..91234ff 100644 --- a/commands/general/tts.js +++ b/commands/general/tts.js @@ -38,7 +38,7 @@ class TtsCommand extends Command { // Performs the Text-to-Speech request gclient.synthesizeSpeech(request, (err, response) => { if (err) { - fs.close(); + console.error('ERROR:', err); return; } @@ -48,13 +48,13 @@ class TtsCommand extends Command { if (err) { console.error('ERROR:', err); message.channel.send('An error has occured, the message is probably too long'); - fs.close(); + return; } console.log('Audio content written to file: tts.mp3'); message.channel.send({ files: ['./tts.mp3'] }); }); - fs.close(); + }); } } diff --git a/commands/general/ttsvc.js b/commands/general/ttsvc.js index 53dfc7e..d489e67 100644 --- a/commands/general/ttsvc.js +++ b/commands/general/ttsvc.js @@ -50,7 +50,7 @@ class TtsvcCommand extends Command { if (err) { console.error('ERROR:', err); message.channel.send('An error has occured, the message is probably too long'); - fs.close(); + return; } console.log('Audio content written to file: ttsvc.mp3'); 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/download.js b/commands/utility/download.js index f24d93a..735d9cb 100644 --- a/commands/utility/download.js +++ b/commands/utility/download.js @@ -43,10 +43,10 @@ class DownloadCommand extends Command { message.delete(); message.channel.send(`Downloaded by ${message.author.username}`, { files: ['./video.mp4'] }) .catch(() => message.channel.send('File too big')); - fs.close(); + }); } else { - fs.close(); + message.channel.send('You need to input a valid link'); } } diff --git a/commands/utility/stats.js b/commands/utility/stats.js index 9113caf..f8fb1b7 100644 --- a/commands/utility/stats.js +++ b/commands/utility/stats.js @@ -1,4 +1,5 @@ const { Command } = require('discord-akairo'); +const { MessageEmbed } = require('discord.js'); class StatsCommand extends Command { constructor() { @@ -21,7 +22,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) + .setTimestamp() + .setFooter('Powered by Yandex.Translate '); + + return message.channel.send(statsEmbed); } } diff --git a/commands/utility/taglist.js b/commands/utility/taglist.js index e950528..9bba8cc 100644 --- a/commands/utility/taglist.js +++ b/commands/utility/taglist.js @@ -18,28 +18,31 @@ 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); - fs.close(); + return; } let json = JSON.stringify(data); json = json.replace(/[{}'\\]+/g, ''); json = json.replace(/,+/g, '\n'); - const tagEmbed = new MessageEmbed() .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`); message.channel.send(tagEmbed); }); - fs.close(); - message.channel.send('An error has occured, do you have any tags on the server?'); + } }