From ac0f71353d68d9b8835bb29c0598ad8f3382f36d Mon Sep 17 00:00:00 2001 From: Frederick Katsura Date: Tue, 21 Jul 2020 15:12:04 -0400 Subject: [PATCH] Small fixes + Minor modification - Fixed an issue when searching for an anime with no date - Fixed an issue when creating a poll with less than two options - Status messages will be pulled from the pre-defined list if no message is provided - Added some new speech lines for the COMMAND_CONF_GUARDED speech key. --- assets/speech/en-CA/system.js | 6 ++++- commands/Fun/Polling/createPoll.js | 2 +- commands/General/anime.js | 2 +- languages/en-CA.js | 2 +- utilities/presenceHelper.js | 37 ++++++++++++++++++++++++------ 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/assets/speech/en-CA/system.js b/assets/speech/en-CA/system.js index 0c81702..2332493 100644 --- a/assets/speech/en-CA/system.js +++ b/assets/speech/en-CA/system.js @@ -146,5 +146,9 @@ module.exports = { "-name is a required argument. You can't leave it blank!", "You need to give me a value for -name! It is required for this command!" ] - } + }, + "guarded": [ + "You cannot disable -name! It's one of the essential commands I provide.", + "Disabling -name is a no. You'd break my services to your guild that way." + ] }; \ No newline at end of file diff --git a/commands/Fun/Polling/createPoll.js b/commands/Fun/Polling/createPoll.js index 39a96ce..1a8c1e3 100644 --- a/commands/Fun/Polling/createPoll.js +++ b/commands/Fun/Polling/createPoll.js @@ -15,7 +15,7 @@ module.exports = class extends Command { async run(msg, [title, desc, ...option]) { if (!title) { return msg.sendLocale("POLL_NOTITLE", [msg]); } if (!desc) { return msg.sendLocale("POLL_NODESC", [msg]); } - if (option.length < 2) { return msg.sendLocale("POLL_NOOPTION", [msg]); } + if (option.length < 2) { return msg.sendLocale("POLL_NOOPTIONS", [msg]); } if (msg.guild.settings.poll.info) { return msg.sendLocale("POLL_NOCREATE", [msg]); } diff --git a/commands/General/anime.js b/commands/General/anime.js index e8e8fda..e2af7f1 100644 --- a/commands/General/anime.js +++ b/commands/General/anime.js @@ -31,7 +31,7 @@ module.exports = class extends Command { if (data.title.english) { title = `${title} | ${data.title.english}`; } var desc = `[Anilist](${data.siteUrl}) | [MyAnimeList](https://myanimelist.net/anime/${data.idMal})\n\n**Format:** `; - var time = `${this.client.util.toTitleCase(data.season)} ${data.startDate.year}`; + var time = (data.season) ? `${this.client.util.toTitleCase(data.season)} ${data.startDate.year}` : "To be announced"; if (data.format === "TV_SHORT") { data.format = "TV Short"; } if (data.format === "SPECIAL") { data.format = "Special"; } diff --git a/languages/en-CA.js b/languages/en-CA.js index b174115..956e2f1 100644 --- a/languages/en-CA.js +++ b/languages/en-CA.js @@ -69,6 +69,7 @@ module.exports = class extends Language { ]), RESOLVER_INVALID_CHANNEL: (name) => this.client.speech(falseMsg, ["func-system", "resolver", "channel"], [["-name", name]]), RESOLVER_INVALID_INT: (name) => this.client.speech(falseMsg, ["func-system", "resolver", "integer"], [["-name", name]]), + COMMAND_CONF_GUARDED: (name) => this.client.speech(falseMsg, ["func-system", "guarded"], [["-name", util.toTitleCase(name)]]), /* * Klasa System. Copied over from Klasa's en-US. @@ -143,7 +144,6 @@ module.exports = class extends Language { COMMAND_DISABLE_WARN: 'You probably don\'t want to disable that, since you wouldn\'t be able to run any command to enable it again', COMMAND_CONF_NOKEY: 'You must provide a key', COMMAND_CONF_NOVALUE: 'You must provide a value', - COMMAND_CONF_GUARDED: (name) => `${util.toTitleCase(name)} may not be disabled.`, COMMAND_CONF_UPDATED: (key, response) => `Successfully updated the key **${key}**: \`${response}\``, COMMAND_CONF_KEY_NOT_ARRAY: 'This key is not array type. Use the action \'reset\' instead.', COMMAND_CONF_GET_NOEXT: (key) => `The key **${key}** does not seem to exist.`, diff --git a/utilities/presenceHelper.js b/utilities/presenceHelper.js index ad579eb..9293ff5 100644 --- a/utilities/presenceHelper.js +++ b/utilities/presenceHelper.js @@ -8,6 +8,26 @@ function Presence(client, type, name, status) { client.user.setPresence({ activity: { name, type }, status }); } +/** + * Gets a random pre-defined status. If previous status is provide, function will + * determine a new and different status to display. + * @param {String} previous - The previous status of the bot. + * @returns {String[]} The status message and determined type. + */ +function determineStatus(previous) { + var items; + if (previous) { + do { + items = games[Math.floor(Math.random() * games.length)]; + } while (items[0] === previous); + return items; + } + + items = games[Math.floor(Math.random() * games.length)]; + + return items; +} + /** * Sets the presence for Margarine and starts a 15 minute interval for automatic change * @param { KlasaClient } client - Needed to grab the user and additional functions. @@ -17,16 +37,19 @@ function Presence(client, type, name, status) { */ module.exports = (client, name, type=0, status="online") => { //Type defaulted to play and status defaulted to online. const sliceCheck = `${client.globalPrefix}help |`.length; + var newStatus = null; - if (name === "-start" || name === "-reset") { - var items = games[Math.floor(Math.random() * games.length)]; //For random status upon startup - Presence(client, items[1], items[0], "online"); + if (name === "-start" || name === "-reset" || name === null) { + newStatus = determineStatus(); + Presence(client, newStatus[1], newStatus[0], "online"); client.timer = setInterval(function() { - do { //No duplicate statuses, Margarine. K thx. - var items = games[Math.floor(Math.random() * games.length)]; - } while (client.user.presence.activities[0].name !== null && items[0] === client.user.presence.activities[0].name.slice(sliceCheck)); + var presenceStatus = null; + if (client.user.presence.activities[0].name !== null) { + presenceStatus = client.user.presence.activities[0].name.slice(sliceCheck); + } - Presence(client, items[1], items[0], status); + newStatus = determineStatus(presenceStatus); + Presence(client, newStatus[1], newStatus[0], status); }, 900000); } else { Presence(client, type, name, status);