From af6153ef4052a305d7a2a483cfa1fb43a3dd505e Mon Sep 17 00:00:00 2001 From: Supositware Date: Wed, 2 Jan 2019 18:45:53 +0100 Subject: [PATCH] various fixes for djs v12 --- commands/admin/autoresponse.js | 10 +++++----- commands/admin/shameboard.js | 6 +++--- commands/admin/starboard.js | 6 +++--- commands/admin/tag.js | 7 +++---- commands/admin/untag.js | 4 ++-- commands/general/advice.js | 3 ++- commands/general/emotesay.js | 2 ++ commands/general/reddit.js | 5 ++++- commands/general/say.js | 4 +++- commands/general/sayd.js | 2 ++ commands/general/tts.js | 6 +++--- commands/general/ttsvc.js | 2 +- commands/utility/avatar.js | 6 +++--- commands/utility/download.js | 4 ++-- commands/utility/stats.js | 17 ++++++++++++++++- commands/utility/taglist.js | 19 +++++++++++-------- 16 files changed, 65 insertions(+), 38 deletions(-) diff --git a/commands/admin/autoresponse.js b/commands/admin/autoresponse.js index cad071bb..de1d3093 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 406dd512..e3aa8c2d 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 f4cdf8bd..7ceb2613 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 5bc207e6..8d6f9467 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 c41e1db2..f8785d78 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 f72ebc97..c4fd9d78 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 b90295d6..413fbc5f 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 0a9ff9e9..e2444d78 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 71ee8f46..534f8656 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 6a360e47..3585a7e9 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 82bdf925..91234ff3 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 53dfc7e0..d489e67e 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 39de9253..d4340582 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 f24d93ac..735d9cb2 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 9113caf0..f8fb1b7c 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 e9505282..9bba8ccb 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?'); + } }