From 6c074197976a113f98ebd05a35ffb0590e3702fe Mon Sep 17 00:00:00 2001 From: Minteck Date: Sun, 6 Mar 2022 15:31:09 +0100 Subject: Fix: resolves #17 --- commands/config.js | 366 ++++++++++++++++++++++++++-------------------------- commands/episode.js | 174 ++++++++++++------------- commands/eval.js | 146 ++++++++++----------- commands/help.js | 82 ++++++------ commands/info.js | 320 ++++++++++++++++++++++----------------------- commands/pony.js | 322 ++++++++++++++++++++++----------------------- commands/random.js | 146 ++++++++++----------- 7 files changed, 778 insertions(+), 778 deletions(-) mode change 100644 => 100755 commands/config.js mode change 100644 => 100755 commands/episode.js mode change 100644 => 100755 commands/eval.js mode change 100644 => 100755 commands/help.js mode change 100644 => 100755 commands/info.js mode change 100644 => 100755 commands/pony.js mode change 100644 => 100755 commands/random.js (limited to 'commands') diff --git a/commands/config.js b/commands/config.js old mode 100644 new mode 100755 index ae2d135..de7c592 --- a/commands/config.js +++ b/commands/config.js @@ -1,184 +1,184 @@ -/* - * MIT License - * - * Copyright (c) 2022- Minteck - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -const fs = require('fs'); -const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); - -const admin = fs.readFileSync("./config/admin.txt").toString().trim(); -const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); - -const getResult = require('../modules/result'); -const getEmbed = require('../modules/embed'); -const getPixel = require("../modules/pixel"); - -const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); -const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); - -module.exports = async (interaction) => { - if (interaction.options.getSubcommand() === 'serverlang') { - if (interaction.guild === null) { - await interaction.reply({ - ephemeral: false, - embeds: [ - new MessageEmbed() - .setColor('#dc2828') - .setTitle(l("Not a server", "Pas un serveur", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setDescription(l("You are trying to run a server-exclusive command in a direct message chat. Please run this command again on a server.", "Vous essayez d'exécuter une commande exclusive aux serveurs dans une conversation en messages privés. Veuillez réessayer cette commande sur un serveur.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ] - }); - return; - } - - if (!interaction.guild.members.resolve(interaction.user).permissions.has("MANAGE_GUILD") && interaction.user.id !== admin) { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#dc2828') - .setTitle(l("Permission denied", "Accès refusé", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setDescription(l("You don't have sufficient permission to run this command. You need to be a bot administrator, or have the **Manage Server** permission.", "Vous ne disposez pas de permissions suffisantes pour exécuter cette commande. Vous devez être administrateur(ice) de robot, ou avoir la permission **Gérer le serveur**.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ] - }); - return; - } - - lang = interaction.options.getString('locale'); - if (lang === "fr") { - servers[interaction.guild ? interaction.guild.id : 0] = "fr"; - } else if (lang === "en") { - servers[interaction.guild ? interaction.guild.id : 0] = "en"; - } else { - delete servers[interaction.guild ? interaction.guild.id : 0]; - } - fs.writeFileSync("./user/servers.json", JSON.stringify(servers, null, 4)); - if (lang === "en" || lang === "fr") { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#28dc46') - .setTitle(l("Server language settings", "Paramètres de langue du serveur", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setDescription(l("This server's enforced language is now **English**.", "La langue forcée sur ce serveur est maintenant le **français**.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ] - }); - } else { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#28dc46') - .setTitle(l("Server language settings", "Paramètres de langue du serveur", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setDescription(l("This server's enforced language is the user's prefered language.", "La langue forcée sur ce serveur est la langue de l'utilisateur.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ] - }); - } - } - - if (interaction.options.getSubcommand() === 'lang') { - lang = interaction.options.getString('locale'); - if (lang === "fr") { - langs[interaction.user.id] = "fr"; - } else { - langs[interaction.user.id] = "en"; - } - fs.writeFileSync("./user/userdata.json", JSON.stringify(langs, null, 4)); - if (typeof servers[interaction.guild ? interaction.guild.id : 0] !== "undefined") { - if (lang === "fr") { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#28dc46') - .setTitle(l("Language settings", "Paramètres de langue", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setDescription(l("Your preferred language is now **French**.\n\n> **Note:** This server enforces English for all users, your personal preferred language won't apply here.", "Votre langue principale est maintenant le **français**.\n\n> **Note :** Ce serveur oblige l'utilisation du français pour tous les utilisateurs, votre option de langue personelle ne s'appliquera pas ici.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ] - }); - } else { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#28dc46') - .setTitle(l("Language settings", "Paramètres de langue", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setDescription(l("Your preferred language is now **English**.\n\n> **Note:** This server enforces English for all users, your personal preferred language won't apply here.", "Votre langue principale est maintenant le **anglais**.\n\n> **Note :** Ce serveur oblige l'utilisation du français pour tous les utilisateurs, votre option de langue personelle ne s'appliquera pas ici.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ] - }); - } - } else { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#28dc46') - .setTitle(l("Language settings", "Paramètres de langue", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setDescription(l("Your preferred language is now **English**.", "Votre langue principale est maintenant le **français**.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ] - }); - } - } - - if (interaction.options.getSubcommand() === 'spoilers') { - v = interaction.options.getString('status'); - if (v === "yes") { - spoils[interaction.user.id] = 2; - } else if (v === "no") { - spoils[interaction.user.id] = 0; - } else { - spoils[interaction.user.id] = 1; - } - fs.writeFileSync("./user/spoilers.json", JSON.stringify(spoils, null, 4)); - if (v === "yes") { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#28dc46') - .setTitle(l("Spoilers settings", "Paramètres des révélations", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setDescription(l("Spoilers are now **always shown**.", "Les révélations sont désormais **toujours affichées**.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ] - }); - } else if (v === "no") { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#28dc46') - .setTitle(l("Spoilers settings", "Paramètres des révélations", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setDescription(l("Spoilers are now **always hidden**.", "Les révélations sont désormais **toujours masquées**.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ] - }); - } else { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#28dc46') - .setTitle(l("Spoilers settings", "Paramètres des révélations", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setDescription(l("Spoilers are now **hidden under spoiler tags**.", "Les révélations sont désormais **masqués derrière des tags révélation**.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ] - }); - } - } +/* + * MIT License + * + * Copyright (c) 2022- Minteck + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +const fs = require('fs'); +const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); + +const admin = fs.readFileSync("./config/admin.txt").toString().trim(); +const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); + +const getResult = require('../modules/result'); +const getEmbed = require('../modules/embed'); +const getPixel = require("../modules/pixel"); + +const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); +const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); + +module.exports = async (interaction) => { + if (interaction.options.getSubcommand() === 'serverlang') { + if (interaction.guild === null) { + await interaction.reply({ + ephemeral: false, + embeds: [ + new MessageEmbed() + .setColor('#dc2828') + .setTitle(l("Not a server", "Pas un serveur", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("You are trying to run a server-exclusive command in a direct message chat. Please run this command again on a server.", "Vous essayez d'exécuter une commande exclusive aux serveurs dans une conversation en messages privés. Veuillez réessayer cette commande sur un serveur.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + return; + } + + if (!interaction.guild.members.resolve(interaction.user).permissions.has("MANAGE_GUILD") && interaction.user.id !== admin) { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#dc2828') + .setTitle(l("Permission denied", "Accès refusé", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("You don't have sufficient permission to run this command. You need to be a bot administrator, or have the **Manage Server** permission.", "Vous ne disposez pas de permissions suffisantes pour exécuter cette commande. Vous devez être administrateur(ice) de robot, ou avoir la permission **Gérer le serveur**.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + return; + } + + lang = interaction.options.getString('locale'); + if (lang === "fr") { + servers[interaction.guild ? interaction.guild.id : 0] = "fr"; + } else if (lang === "en") { + servers[interaction.guild ? interaction.guild.id : 0] = "en"; + } else { + delete servers[interaction.guild ? interaction.guild.id : 0]; + } + fs.writeFileSync("./user/servers.json", JSON.stringify(servers, null, 4)); + if (lang === "en" || lang === "fr") { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#28dc46') + .setTitle(l("Server language settings", "Paramètres de langue du serveur", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("This server's enforced language is now **English**.", "La langue forcée sur ce serveur est maintenant le **français**.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + } else { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#28dc46') + .setTitle(l("Server language settings", "Paramètres de langue du serveur", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("This server's enforced language is the user's prefered language.", "La langue forcée sur ce serveur est la langue de l'utilisateur.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + } + } + + if (interaction.options.getSubcommand() === 'lang') { + lang = interaction.options.getString('locale'); + if (lang === "fr") { + langs[interaction.user.id] = "fr"; + } else { + langs[interaction.user.id] = "en"; + } + fs.writeFileSync("./user/userdata.json", JSON.stringify(langs, null, 4)); + if (typeof servers[interaction.guild ? interaction.guild.id : 0] !== "undefined") { + if (lang === "fr") { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#28dc46') + .setTitle(l("Language settings", "Paramètres de langue", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("Your preferred language is now **French**.\n\n> **Note:** This server enforces English for all users, your personal preferred language won't apply here.", "Votre langue principale est maintenant le **français**.\n\n> **Note :** Ce serveur oblige l'utilisation du français pour tous les utilisateurs, votre option de langue personelle ne s'appliquera pas ici.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + } else { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#28dc46') + .setTitle(l("Language settings", "Paramètres de langue", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("Your preferred language is now **English**.\n\n> **Note:** This server enforces English for all users, your personal preferred language won't apply here.", "Votre langue principale est maintenant le **anglais**.\n\n> **Note :** Ce serveur oblige l'utilisation du français pour tous les utilisateurs, votre option de langue personelle ne s'appliquera pas ici.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + } + } else { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#28dc46') + .setTitle(l("Language settings", "Paramètres de langue", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("Your preferred language is now **English**.", "Votre langue principale est maintenant le **français**.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + } + } + + if (interaction.options.getSubcommand() === 'spoilers') { + v = interaction.options.getString('status'); + if (v === "yes") { + spoils[interaction.user.id] = 2; + } else if (v === "no") { + spoils[interaction.user.id] = 0; + } else { + spoils[interaction.user.id] = 1; + } + fs.writeFileSync("./user/spoilers.json", JSON.stringify(spoils, null, 4)); + if (v === "yes") { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#28dc46') + .setTitle(l("Spoilers settings", "Paramètres des révélations", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("Spoilers are now **always shown**.", "Les révélations sont désormais **toujours affichées**.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + } else if (v === "no") { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#28dc46') + .setTitle(l("Spoilers settings", "Paramètres des révélations", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("Spoilers are now **always hidden**.", "Les révélations sont désormais **toujours masquées**.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + } else { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#28dc46') + .setTitle(l("Spoilers settings", "Paramètres des révélations", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("Spoilers are now **hidden under spoiler tags**.", "Les révélations sont désormais **masqués derrière des tags révélation**.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + } + } } \ No newline at end of file diff --git a/commands/episode.js b/commands/episode.js old mode 100644 new mode 100755 index b7d536a..07155a4 --- a/commands/episode.js +++ b/commands/episode.js @@ -1,88 +1,88 @@ -/* - * MIT License - * - * Copyright (c) 2022- Minteck - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -const fs = require('fs'); -const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); - -const getEpisodePublic = require("../modules/episodepublic"); -const episodeReply = require("../modules/episodereply"); -const getEpisodes = require("../modules/findepisode"); - -const series = JSON.parse(fs.readFileSync("./data/series.json").toString()); - -module.exports = async (interaction) => { - let select = interaction.options.getSubcommand(); - let episode = interaction.options.getString('episode').toLowerCase(); - let ep_orig = episode; - let sdata = series.filter(i => i.command.toLowerCase() === select)[0]; - - // Check if it's a valid episode - try { - let sid = episode.split("-")[0]; - let spt = sid.substring(1); - let eid = episode.split("-")[1]; - let edata = sdata.seasons.filter(i => i.id === sid)[0].episodes.filter(i => i.local - 1 + 1 === eid - 1 + 1)[0]; - } catch (e) { // If it's not, run the search engine - try { - episode = getEpisodes(series.filter(i => i.command.toLowerCase() === select)[0], episode)[0].value; - - let sid = episode.split("-")[0]; - let spt = sid.substring(1); - let eid = episode.split("-")[1]; - let edata = sdata.seasons.filter(i => i.id === sid)[0].episodes.filter(i => i.local - 1 + 1 === eid - 1 + 1)[0]; - } catch (e) { // If no result is found, return an error message - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#dc2828') - .setTitle(l("Results for", "Résultats pour", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + " \"" + ep_orig + "\"") - .setDescription(l("No results found. Please try with other keywords.", "Aucun résultat trouvé. Essayez avec d'autres mots clés.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ], - components: [ - new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId("result.report|" + ep_orig) - .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setStyle("DANGER") - ) - ] - }); - return; - } - } - - if (statsEpisodes[select + "-" + episode] !== undefined) { - statsEpisodes[select + "-" + episode]++; - } else { - statsEpisodes[select + "-" + episode] = 1; - } - fs.writeFile("./stats/episodes.json", JSON.stringify(statsEpisodes), () => {}); - - if (typeof episode === "string") { - await episodeReply(interaction, select, episode, sdata); - } +/* + * MIT License + * + * Copyright (c) 2022- Minteck + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +const fs = require('fs'); +const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); + +const getEpisodePublic = require("../modules/episodepublic"); +const episodeReply = require("../modules/episodereply"); +const getEpisodes = require("../modules/findepisode"); + +const series = JSON.parse(fs.readFileSync("./data/series.json").toString()); + +module.exports = async (interaction) => { + let select = interaction.options.getSubcommand(); + let episode = interaction.options.getString('episode').toLowerCase(); + let ep_orig = episode; + let sdata = series.filter(i => i.command.toLowerCase() === select)[0]; + + // Check if it's a valid episode + try { + let sid = episode.split("-")[0]; + let spt = sid.substring(1); + let eid = episode.split("-")[1]; + let edata = sdata.seasons.filter(i => i.id === sid)[0].episodes.filter(i => i.local - 1 + 1 === eid - 1 + 1)[0]; + } catch (e) { // If it's not, run the search engine + try { + episode = getEpisodes(series.filter(i => i.command.toLowerCase() === select)[0], episode)[0].value; + + let sid = episode.split("-")[0]; + let spt = sid.substring(1); + let eid = episode.split("-")[1]; + let edata = sdata.seasons.filter(i => i.id === sid)[0].episodes.filter(i => i.local - 1 + 1 === eid - 1 + 1)[0]; + } catch (e) { // If no result is found, return an error message + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#dc2828') + .setTitle(l("Results for", "Résultats pour", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + " \"" + ep_orig + "\"") + .setDescription(l("No results found. Please try with other keywords.", "Aucun résultat trouvé. Essayez avec d'autres mots clés.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ], + components: [ + new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId("result.report|" + ep_orig) + .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("DANGER") + ) + ] + }); + return; + } + } + + if (statsEpisodes[select + "-" + episode] !== undefined) { + statsEpisodes[select + "-" + episode]++; + } else { + statsEpisodes[select + "-" + episode] = 1; + } + fs.writeFile("./stats/episodes.json", JSON.stringify(statsEpisodes), () => {}); + + if (typeof episode === "string") { + await episodeReply(interaction, select, episode, sdata); + } } \ No newline at end of file diff --git a/commands/eval.js b/commands/eval.js old mode 100644 new mode 100755 index 288aca9..101d6d4 --- a/commands/eval.js +++ b/commands/eval.js @@ -1,74 +1,74 @@ -/* - * MIT License - * - * Copyright (c) 2022- Minteck - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -const fs = require('fs'); -const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); - -const admin = fs.readFileSync("./config/admin.txt").toString().trim(); -const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); - -const getResult = require('../modules/result'); -const getEmbed = require('../modules/embed'); -const getPixel = require("../modules/pixel"); - -const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); -const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); - -module.exports = async (interaction) => { - if (interaction.user.id !== admin) { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#dc2828') - .setTitle(l("Permission denied", "Accès refusé", interaction.user.id, 0)) - .setDescription(l("You don't have sufficient permission to run this command. You need to be a bot administrator, or have the **Manage Server** permission.", "Vous ne disposez pas de permissions suffisantes pour exécuter cette commande. Vous devez être administrateur(ice) de robot, ou avoir la permission **Gérer le serveur**.", interaction.user.id, 0)) - ] - }); - return; - } - - try { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#28dc46') - .setTitle("JavaScript") - .setDescription("```\n" + await eval(interaction.options.getString("code")).toString().replace(/`/g, "\\`") + "\n```") - ] - }); - } catch (e) { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#dc2828') - .setTitle("JavaScript") - .setDescription("```\n" + e.stack + "\n```") - ] - }); - } +/* + * MIT License + * + * Copyright (c) 2022- Minteck + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +const fs = require('fs'); +const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); + +const admin = fs.readFileSync("./config/admin.txt").toString().trim(); +const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); + +const getResult = require('../modules/result'); +const getEmbed = require('../modules/embed'); +const getPixel = require("../modules/pixel"); + +const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); +const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); + +module.exports = async (interaction) => { + if (interaction.user.id !== admin) { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#dc2828') + .setTitle(l("Permission denied", "Accès refusé", interaction.user.id, 0)) + .setDescription(l("You don't have sufficient permission to run this command. You need to be a bot administrator, or have the **Manage Server** permission.", "Vous ne disposez pas de permissions suffisantes pour exécuter cette commande. Vous devez être administrateur(ice) de robot, ou avoir la permission **Gérer le serveur**.", interaction.user.id, 0)) + ] + }); + return; + } + + try { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#28dc46') + .setTitle("JavaScript") + .setDescription("```\n" + await eval(interaction.options.getString("code")).toString().replace(/`/g, "\\`") + "\n```") + ] + }); + } catch (e) { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#dc2828') + .setTitle("JavaScript") + .setDescription("```\n" + e.stack + "\n```") + ] + }); + } } \ No newline at end of file diff --git a/commands/help.js b/commands/help.js old mode 100644 new mode 100755 index 0edad0a..7aa14ee --- a/commands/help.js +++ b/commands/help.js @@ -1,42 +1,42 @@ -/* - * MIT License - * - * Copyright (c) 2022- Minteck - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -const fs = require('fs'); -const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); - -const admin = fs.readFileSync("./config/admin.txt").toString().trim(); -const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); - -const getResult = require('../modules/result'); -const getEmbed = require('../modules/embed'); -const getPixel = require("../modules/pixel"); -const getHelp = require("../modules/help"); - -const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); -const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); - -module.exports = async (interaction) => { - await interaction.reply(getHelp(interaction.guild, interaction.guild.id, interaction.user.id, false)); +/* + * MIT License + * + * Copyright (c) 2022- Minteck + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +const fs = require('fs'); +const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); + +const admin = fs.readFileSync("./config/admin.txt").toString().trim(); +const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); + +const getResult = require('../modules/result'); +const getEmbed = require('../modules/embed'); +const getPixel = require("../modules/pixel"); +const getHelp = require("../modules/help"); + +const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); +const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); + +module.exports = async (interaction) => { + await interaction.reply(getHelp(interaction.guild, interaction.guild.id, interaction.user.id, false)); } \ No newline at end of file diff --git a/commands/info.js b/commands/info.js old mode 100644 new mode 100755 index b9f4a34..2b68b87 --- a/commands/info.js +++ b/commands/info.js @@ -1,160 +1,160 @@ -/* - * MIT License - * - * Copyright (c) 2022- Minteck - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -const fs = require('fs'); -const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); - -const admin = fs.readFileSync("./config/admin.txt").toString().trim(); -const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); -const series = JSON.parse(fs.readFileSync("./data/series.json").toString()); - -const getResult = require('../modules/result'); -const getEmbed = require('../modules/embed'); -const getPixel = require("../modules/pixel"); - -const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); -const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); - -function bytesToPretty(bytes, uid, gid) { - if (bytes > 1000) { - if (bytes > 1000000) { - return (bytes / 1000000).toFixed(2) + " " + l("MB", "Mo", uid, gid); - } else { - return (bytes / 1000).toFixed(2) + " " + l("KB", "Ko", uid, gid); - } - } else { - return bytes + " " + l("B", "o", uid, gid); - } -} - -function secondsToPretty(seconds, uid, gid) { - if (seconds > 60) { - if (seconds > 3600) { - if (seconds > 86400) { - return Math.floor(seconds / 86400) + " " + l("day", "jour", uid, gid) + (Math.floor(seconds / 86400) > 1 ? "s" : ""); - } else { - return Math.floor(seconds / 3600) + " " + l("hour", "heure", uid, gid) + (Math.floor(seconds / 3600) > 1 ? "s" : ""); - } - } else { - return Math.floor(seconds / 60) + " minute" + (Math.floor(seconds / 60) > 1 ? "s" : ""); - } - } else { - return Math.floor(seconds) + " " + l("second", "seconde", uid, gid) + (Math.floor(seconds) > 1 ? "s" : ""); - } -} - -module.exports = async (interaction) => { - let suffix = ""; - if (official.includes(interaction.guild ? interaction.guild.id : 0)) { - suffix = ".official-" + (interaction.guild ? interaction.guild.id : 0); - } else { - if ((interaction.guild ? interaction.guild.id : 0) === fpserver) { - suffix = ".francoponies-exp" + fs.readFileSync("./config/fpexperience.txt").toString(); - } - } - - let size = 0; - for (let file of fs.readdirSync("./data")) size += fs.readFileSync("./data/" + file).length; - let sizep = bytesToPretty(size); - - let statsCommand = "-"; - let statsCommandUsage = "n/a"; - - let statsCommandsP = statsCommands - try { delete statsCommandsP["eval"]; } catch (e) {} - - try { - statsCommand = Object.keys(statsCommandsP).filter(i => i !== "_total").reduce((a, b) => statsCommandsP[a] > statsCommandsP[b] ? a : b); - statsCommandUsage = statsCommandsP[Object.keys(statsCommandsP).reduce((a, b) => statsCommandsP[a] > statsCommandsP[b] ? a : b)].toString(); - } catch (e) { - console.error(e); - } - - let statsPony = "-"; - let statsPonyUsage = "n/a"; - try { - statsPony = Object.keys(statsPonies).reduce((a, b) => statsPonies[a] > statsPonies[b] ? a : b); - statsPonyUsage = statsPonies[Object.keys(statsPonies).reduce((a, b) => statsPonies[a] > statsPonies[b] ? a : b)].toString(); - } catch (e) { - console.error(e); - } - - let statsEpisode = "-"; - let statsEpisodeUsage = "n/a"; - try { - let statsEpisodeParts = Object.keys(statsEpisodes).reduce((a, b) => statsEpisodes[a] > statsEpisodes[b] ? a : b).split("-"); - statsEpisode = series.filter(i => i.command.toLowerCase() === statsEpisodeParts[0].toLowerCase())[0].seasons.filter(i => i.id === statsEpisodeParts[1])[0].episodes.filter(i => i.local === statsEpisodeParts[2])[0].name; - statsEpisodeUsage = statsEpisodes[Object.keys(statsEpisodes).reduce((a, b) => statsEpisodes[a] > statsEpisodes[b] ? a : b)].toString(); - } catch (e) { - console.error(e); - } - - let fields = [ - { name: l("Software version", "Version du logiciel", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: "v" + fs.readFileSync("./config/version.txt").toString().trim() + "." + fs.readFileSync("./.git/refs/heads/trunk").toString().substring(0, 8) + suffix + " (#" + client.shard.count + ")", inline: false }, - { name: l("Kernel version", "Version du noyau", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: process.version, inline: true }, - { name: l("Experience channel", "Canal d'expériences", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: channel, inline: true }, - { name: l("Known ponies", "Poneys connus", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())).length.toString(), inline: true }, - { name: l("Most used command", "Commande la plus utilisée", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: "`/" + statsCommand + "`\n(" + l("used " + statsCommandUsage + " times", "utilisée " + statsCommandUsage + " fois", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + ")", inline: true }, - { name: l("Most viewed pony", "Poney le plus consulté", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: statsPony + "\n(" + l("viewed " + statsPonyUsage + " times", "consulté " + statsPonyUsage + " fois", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + ")", inline: true }, - { name: l("Most viewed episode", "Épisode le plus consulté", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: statsEpisode + "\n(" + l("viewed " + statsEpisodeUsage + " times", "consulté " + statsEpisodeUsage + " fois", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + ")", inline: true }, - { name: l("Awaiting issue reports", "Rapports de problèmes en attente", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: fs.readdirSync("./reports").length.toString(), inline: true }, - { name: l("Database size", "Taille de la base de données", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: sizep, inline: true }, - { name: l("Memory usage", "Utilisation de la mémoire", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: bytesToPretty(process.memoryUsage().rss + process.memoryUsage().heapTotal + process.memoryUsage().external + process.memoryUsage().arrayBuffers, interaction.user.id, interaction.guild ? interaction.guild.id : 0), inline: true }, - { name: l("Uptime", "Durée de fonctionnement", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: secondsToPretty(process.uptime(), interaction.user.id, interaction.guild ? interaction.guild.id : 0), inline: true }, - ]; - - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#d6dc28') - .setTitle(l("Bot stats", "Statistiques du robot", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setDescription(l("Ponyfind is a Discord bot that helps you get easy and fast access to data relative to My Little Pony (generations 4 and 5).", "Ponyfind est un robot Discord qui vous aide à obtenir un accès simple et rapide à des données relatives à My Little Pony (générations 4 et 5).", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .addFields(fields) - .setFooter({text: l("made with ♥ by Minteck, a My Little Pony fan", "fait avec ♥ par Minteck, une fan de My Little Pony", interaction.user.id, interaction.guild ? interaction.guild.id : 0)}) - ], - components: [ - new MessageActionRow() - .addComponents( - new MessageButton() - .setStyle("LINK") - .setURL("https://gitlab.minteck.org/minteck/ponyfind") - .setLabel(l("Source Code", "Code source", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ) - .addComponents( - new MessageButton() - .setStyle("LINK") - .setURL("https://minteck.org/legal/#/privacy") - .setLabel(l("Data Privacy", "Politique de confidentialité", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ) - .addComponents( - new MessageButton() - .setStyle("LINK") - .setURL("https://minteck.org/legal/#/terms") - .setLabel(l("Terms and Conditions", "Conditions d'utilisation", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ) - ] - }); -} +/* + * MIT License + * + * Copyright (c) 2022- Minteck + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +const fs = require('fs'); +const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); + +const admin = fs.readFileSync("./config/admin.txt").toString().trim(); +const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); +const series = JSON.parse(fs.readFileSync("./data/series.json").toString()); + +const getResult = require('../modules/result'); +const getEmbed = require('../modules/embed'); +const getPixel = require("../modules/pixel"); + +const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); +const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); + +function bytesToPretty(bytes, uid, gid) { + if (bytes > 1000) { + if (bytes > 1000000) { + return (bytes / 1000000).toFixed(2) + " " + l("MB", "Mo", uid, gid); + } else { + return (bytes / 1000).toFixed(2) + " " + l("KB", "Ko", uid, gid); + } + } else { + return bytes + " " + l("B", "o", uid, gid); + } +} + +function secondsToPretty(seconds, uid, gid) { + if (seconds > 60) { + if (seconds > 3600) { + if (seconds > 86400) { + return Math.floor(seconds / 86400) + " " + l("day", "jour", uid, gid) + (Math.floor(seconds / 86400) > 1 ? "s" : ""); + } else { + return Math.floor(seconds / 3600) + " " + l("hour", "heure", uid, gid) + (Math.floor(seconds / 3600) > 1 ? "s" : ""); + } + } else { + return Math.floor(seconds / 60) + " minute" + (Math.floor(seconds / 60) > 1 ? "s" : ""); + } + } else { + return Math.floor(seconds) + " " + l("second", "seconde", uid, gid) + (Math.floor(seconds) > 1 ? "s" : ""); + } +} + +module.exports = async (interaction) => { + let suffix = ""; + if (official.includes(interaction.guild ? interaction.guild.id : 0)) { + suffix = ".official-" + (interaction.guild ? interaction.guild.id : 0); + } else { + if ((interaction.guild ? interaction.guild.id : 0) === fpserver) { + suffix = ".francoponies-exp" + fs.readFileSync("./config/fpexperience.txt").toString(); + } + } + + let size = 0; + for (let file of fs.readdirSync("./data")) size += fs.readFileSync("./data/" + file).length; + let sizep = bytesToPretty(size); + + let statsCommand = "-"; + let statsCommandUsage = "n/a"; + + let statsCommandsP = statsCommands + try { delete statsCommandsP["eval"]; } catch (e) {} + + try { + statsCommand = Object.keys(statsCommandsP).filter(i => i !== "_total").reduce((a, b) => statsCommandsP[a] > statsCommandsP[b] ? a : b); + statsCommandUsage = statsCommandsP[Object.keys(statsCommandsP).reduce((a, b) => statsCommandsP[a] > statsCommandsP[b] ? a : b)].toString(); + } catch (e) { + console.error(e); + } + + let statsPony = "-"; + let statsPonyUsage = "n/a"; + try { + statsPony = Object.keys(statsPonies).reduce((a, b) => statsPonies[a] > statsPonies[b] ? a : b); + statsPonyUsage = statsPonies[Object.keys(statsPonies).reduce((a, b) => statsPonies[a] > statsPonies[b] ? a : b)].toString(); + } catch (e) { + console.error(e); + } + + let statsEpisode = "-"; + let statsEpisodeUsage = "n/a"; + try { + let statsEpisodeParts = Object.keys(statsEpisodes).reduce((a, b) => statsEpisodes[a] > statsEpisodes[b] ? a : b).split("-"); + statsEpisode = series.filter(i => i.command.toLowerCase() === statsEpisodeParts[0].toLowerCase())[0].seasons.filter(i => i.id === statsEpisodeParts[1])[0].episodes.filter(i => i.local === statsEpisodeParts[2])[0].name; + statsEpisodeUsage = statsEpisodes[Object.keys(statsEpisodes).reduce((a, b) => statsEpisodes[a] > statsEpisodes[b] ? a : b)].toString(); + } catch (e) { + console.error(e); + } + + let fields = [ + { name: l("Software version", "Version du logiciel", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: "v" + fs.readFileSync("./config/version.txt").toString().trim() + "." + fs.readFileSync("./.git/refs/heads/trunk").toString().substring(0, 8) + suffix + " (#" + client.shard.count + ")", inline: false }, + { name: l("Kernel version", "Version du noyau", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: process.version, inline: true }, + { name: l("Experience channel", "Canal d'expériences", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: channel, inline: true }, + { name: l("Known ponies", "Poneys connus", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())).length.toString(), inline: true }, + { name: l("Most used command", "Commande la plus utilisée", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: "`/" + statsCommand + "`\n(" + l("used " + statsCommandUsage + " times", "utilisée " + statsCommandUsage + " fois", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + ")", inline: true }, + { name: l("Most viewed pony", "Poney le plus consulté", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: statsPony + "\n(" + l("viewed " + statsPonyUsage + " times", "consulté " + statsPonyUsage + " fois", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + ")", inline: true }, + { name: l("Most viewed episode", "Épisode le plus consulté", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: statsEpisode + "\n(" + l("viewed " + statsEpisodeUsage + " times", "consulté " + statsEpisodeUsage + " fois", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + ")", inline: true }, + { name: l("Awaiting issue reports", "Rapports de problèmes en attente", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: fs.readdirSync("./reports").length.toString(), inline: true }, + { name: l("Database size", "Taille de la base de données", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: sizep, inline: true }, + { name: l("Memory usage", "Utilisation de la mémoire", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: bytesToPretty(process.memoryUsage().rss + process.memoryUsage().heapTotal + process.memoryUsage().external + process.memoryUsage().arrayBuffers, interaction.user.id, interaction.guild ? interaction.guild.id : 0), inline: true }, + { name: l("Uptime", "Durée de fonctionnement", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: secondsToPretty(process.uptime(), interaction.user.id, interaction.guild ? interaction.guild.id : 0), inline: true }, + ]; + + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#d6dc28') + .setTitle(l("Bot stats", "Statistiques du robot", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("Ponyfind is a Discord bot that helps you get easy and fast access to data relative to My Little Pony (generations 4 and 5).", "Ponyfind est un robot Discord qui vous aide à obtenir un accès simple et rapide à des données relatives à My Little Pony (générations 4 et 5).", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .addFields(fields) + .setFooter({text: l("made with ♥ by Minteck, a My Little Pony fan", "fait avec ♥ par Minteck, une fan de My Little Pony", interaction.user.id, interaction.guild ? interaction.guild.id : 0)}) + ], + components: [ + new MessageActionRow() + .addComponents( + new MessageButton() + .setStyle("LINK") + .setURL("https://gitlab.minteck.org/minteck/ponyfind") + .setLabel(l("Source Code", "Code source", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ) + .addComponents( + new MessageButton() + .setStyle("LINK") + .setURL("https://minteck.org/legal/#/privacy") + .setLabel(l("Data Privacy", "Politique de confidentialité", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ) + .addComponents( + new MessageButton() + .setStyle("LINK") + .setURL("https://minteck.org/legal/#/terms") + .setLabel(l("Terms and Conditions", "Conditions d'utilisation", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ) + ] + }); +} diff --git a/commands/pony.js b/commands/pony.js old mode 100644 new mode 100755 index 3b853d5..b783334 --- a/commands/pony.js +++ b/commands/pony.js @@ -1,162 +1,162 @@ -/* - * MIT License - * - * Copyright (c) 2022- Minteck - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -const fs = require('fs'); -const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); - -const admin = fs.readFileSync("./config/admin.txt").toString().trim(); -const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); - -const getResult = require('../modules/result'); -const getEmbed = require('../modules/embed'); -const getPixel = require("../modules/pixel"); -const getPublic = require('../modules/public'); - -const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); -const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); - -module.exports = async (interaction) => { - query = interaction.options.getString('query').toLowerCase(); - result = getResult(query); - - if (result.results.length > 0 && getEmbed(result.results[0], interaction.user.id, interaction.guild ? interaction.guild.id : 0) !== false) { - if (statsQueries[result.results[0]] !== undefined) { - if (!statsQueries[result.results[0]].includes(query)) { - statsQueries[result.results[0]].push(query); - } - } else { - statsQueries[result.results[0]] = [ query ]; - } - fs.writeFile("./stats/queries.json", JSON.stringify(statsQueries), () => {}); - if (result.results[0].toLowerCase().trim() === query.toLowerCase().trim()) { - keys = [null, result.results[0]]; - if (statsPonies[keys[1]] !== undefined) { - statsPonies[keys[1]]++; - } else { - statsPonies[keys[1]] = 1; - } - fs.writeFile("./stats/ponies.json", JSON.stringify(statsPonies), () => {}); - if (interaction.guild) { - row = new MessageActionRow() - .addComponents( - getPublic(interaction, keys), - new MessageButton() - .setLabel(l("Read More", "Lire plus", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setStyle("LINK") - .setURL("https://mlp.fandom.com/wiki/" + encodeURI(keys[1])), - new MessageButton() - .setCustomId("pony.pixel|" + keys[1]) - .setLabel("Pixel Art") - .setDisabled(!fs.existsSync("./pixel/" + keys[1].toLowerCase())) - .setStyle("SECONDARY"), - new MessageButton() - .setCustomId("result.report|" + keys[1]) - .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setStyle("DANGER") - ) - } else { - row = new MessageActionRow() - .addComponents( - new MessageButton() - .setLabel(l("Read More", "Lire plus", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setStyle("LINK") - .setURL("https://mlp.fandom.com/wiki/" + encodeURI(keys[1])), - new MessageButton() - .setCustomId("pony.pixel|" + keys[1]) - .setLabel("Pixel Art") - .setDisabled(!fs.existsSync("./pixel/" + keys[1].toLowerCase())) - .setStyle("SECONDARY"), - new MessageButton() - .setCustomId("result.report|" + keys[1]) - .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setStyle("DANGER") - ) - } - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - getEmbed(keys[1], interaction.user.id, interaction.guild ? interaction.guild.id : 0, false, interaction.user, interaction.member, interaction.guild) - ], - components: [ - row - ] - }); - } else { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#d6dc28') - .setTitle(l("Results for", "Résultats pour", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + " \"" + query + "\"") - .setDescription(l("Here are the 3 first results corresponding to your query.", "Voici les 3 premiers résultats correspondants à votre recherche.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ], - components: [ - new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId("pony.display|" + result.first[0]) - .setLabel(result.first[0]) - .setStyle("PRIMARY"), - new MessageButton() - .setCustomId("pony.display|" + result.first[1]) - .setLabel(result.first[1]) - .setStyle("PRIMARY"), - new MessageButton() - .setCustomId("pony.display|" + result.first[2]) - .setLabel(result.first[2]) - .setStyle("PRIMARY"), - new MessageButton() - .setCustomId("result.report|" + query) - .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setStyle("DANGER") - ) - ] - }); - } - } else { - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - new MessageEmbed() - .setColor('#dc2828') - .setTitle(l("Results for", "Résultats pour", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + " \"" + query + "\"") - .setDescription(l("No results found. Please try with other keywords.", "Aucun résultat trouvé. Essayez avec d'autres mots clés.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - ], - components: [ - new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId("result.suggest|" + query) - .setLabel(l("Suggest a missing pony", "Proposer un poney manquant", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setStyle("SECONDARY"), - new MessageButton() - .setCustomId("result.report|" + query) - .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setStyle("DANGER") - ) - ] - }); - } +/* + * MIT License + * + * Copyright (c) 2022- Minteck + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +const fs = require('fs'); +const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); + +const admin = fs.readFileSync("./config/admin.txt").toString().trim(); +const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); + +const getResult = require('../modules/result'); +const getEmbed = require('../modules/embed'); +const getPixel = require("../modules/pixel"); +const getPublic = require('../modules/public'); + +const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); +const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); + +module.exports = async (interaction) => { + query = interaction.options.getString('query').toLowerCase(); + result = getResult(query); + + if (result.results.length > 0 && getEmbed(result.results[0], interaction.user.id, interaction.guild ? interaction.guild.id : 0) !== false) { + if (statsQueries[result.results[0]] !== undefined) { + if (!statsQueries[result.results[0]].includes(query)) { + statsQueries[result.results[0]].push(query); + } + } else { + statsQueries[result.results[0]] = [ query ]; + } + fs.writeFile("./stats/queries.json", JSON.stringify(statsQueries), () => {}); + if (result.results[0].toLowerCase().trim() === query.toLowerCase().trim()) { + keys = [null, result.results[0]]; + if (statsPonies[keys[1]] !== undefined) { + statsPonies[keys[1]]++; + } else { + statsPonies[keys[1]] = 1; + } + fs.writeFile("./stats/ponies.json", JSON.stringify(statsPonies), () => {}); + if (interaction.guild) { + row = new MessageActionRow() + .addComponents( + getPublic(interaction, keys), + new MessageButton() + .setLabel(l("Read More", "Lire plus", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("LINK") + .setURL("https://mlp.fandom.com/wiki/" + encodeURI(keys[1])), + new MessageButton() + .setCustomId("pony.pixel|" + keys[1]) + .setLabel("Pixel Art") + .setDisabled(!fs.existsSync("./pixel/" + keys[1].toLowerCase())) + .setStyle("SECONDARY"), + new MessageButton() + .setCustomId("result.report|" + keys[1]) + .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("DANGER") + ) + } else { + row = new MessageActionRow() + .addComponents( + new MessageButton() + .setLabel(l("Read More", "Lire plus", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("LINK") + .setURL("https://mlp.fandom.com/wiki/" + encodeURI(keys[1])), + new MessageButton() + .setCustomId("pony.pixel|" + keys[1]) + .setLabel("Pixel Art") + .setDisabled(!fs.existsSync("./pixel/" + keys[1].toLowerCase())) + .setStyle("SECONDARY"), + new MessageButton() + .setCustomId("result.report|" + keys[1]) + .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("DANGER") + ) + } + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + getEmbed(keys[1], interaction.user.id, interaction.guild ? interaction.guild.id : 0, false, interaction.user, interaction.member, interaction.guild) + ], + components: [ + row + ] + }); + } else { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#d6dc28') + .setTitle(l("Results for", "Résultats pour", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + " \"" + query + "\"") + .setDescription(l("Here are the 3 first results corresponding to your query.", "Voici les 3 premiers résultats correspondants à votre recherche.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ], + components: [ + new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId("pony.display|" + result.first[0]) + .setLabel(result.first[0]) + .setStyle("PRIMARY"), + new MessageButton() + .setCustomId("pony.display|" + result.first[1]) + .setLabel(result.first[1]) + .setStyle("PRIMARY"), + new MessageButton() + .setCustomId("pony.display|" + result.first[2]) + .setLabel(result.first[2]) + .setStyle("PRIMARY"), + new MessageButton() + .setCustomId("result.report|" + query) + .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("DANGER") + ) + ] + }); + } + } else { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#dc2828') + .setTitle(l("Results for", "Résultats pour", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + " \"" + query + "\"") + .setDescription(l("No results found. Please try with other keywords.", "Aucun résultat trouvé. Essayez avec d'autres mots clés.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ], + components: [ + new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId("result.suggest|" + query) + .setLabel(l("Suggest a missing pony", "Proposer un poney manquant", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("SECONDARY"), + new MessageButton() + .setCustomId("result.report|" + query) + .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("DANGER") + ) + ] + }); + } } \ No newline at end of file diff --git a/commands/random.js b/commands/random.js old mode 100644 new mode 100755 index a3521ff..e6b26b9 --- a/commands/random.js +++ b/commands/random.js @@ -1,74 +1,74 @@ -/* - * MIT License - * - * Copyright (c) 2022- Minteck - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -const fs = require('fs'); -const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); - -const admin = fs.readFileSync("./config/admin.txt").toString().trim(); -const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); - -const getResult = require('../modules/result'); -const getEmbed = require('../modules/embed'); -const getPixel = require("../modules/pixel"); - -const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); -const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); - -module.exports = async (interaction) => { - keys = [ - null, - list[Math.floor(Math.random() * list.length)] - ] - if (statsPonies[keys[1]] !== undefined) { - statsPonies[keys[1]]++; - } else { - statsPonies[keys[1]] = 1; - } - fs.writeFile("./stats/ponies.json", JSON.stringify(statsPonies), () => {}); - await interaction.reply({ - ephemeral: interaction.guild !== null, - embeds: [ - getEmbed(keys[1], interaction.user.id, interaction.guild ? interaction.guild.id : 0, false, interaction.user, interaction.member, interaction.guild) - ], - components: [ - new MessageActionRow() - .addComponents( - new MessageButton() - .setLabel(l("Read More", "Lire plus", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setStyle("LINK") - .setURL("https://mlp.fandom.com/wiki/" + encodeURI(keys[1])), - new MessageButton() - .setCustomId("pony.pixel|" + keys[1]) - .setLabel("Pixel Art") - .setDisabled(!fs.existsSync("./pixel/" + keys[1].toLowerCase())) - .setStyle("SECONDARY"), - new MessageButton() - .setCustomId("result.report|" + keys[1]) - .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setStyle("DANGER") - ) - ] - }); +/* + * MIT License + * + * Copyright (c) 2022- Minteck + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +const fs = require('fs'); +const {MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed} = require('discord.js'); + +const admin = fs.readFileSync("./config/admin.txt").toString().trim(); +const list = Object.keys(JSON.parse(fs.readFileSync("./data/data.json").toString())); + +const getResult = require('../modules/result'); +const getEmbed = require('../modules/embed'); +const getPixel = require("../modules/pixel"); + +const official = fs.readFileSync("./config/official.txt").toString().replace(/\r\n/g, "\n").split("\n"); +const fpserver = fs.readFileSync("./config/fpserver.txt").toString().trim(); + +module.exports = async (interaction) => { + keys = [ + null, + list[Math.floor(Math.random() * list.length)] + ] + if (statsPonies[keys[1]] !== undefined) { + statsPonies[keys[1]]++; + } else { + statsPonies[keys[1]] = 1; + } + fs.writeFile("./stats/ponies.json", JSON.stringify(statsPonies), () => {}); + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + getEmbed(keys[1], interaction.user.id, interaction.guild ? interaction.guild.id : 0, false, interaction.user, interaction.member, interaction.guild) + ], + components: [ + new MessageActionRow() + .addComponents( + new MessageButton() + .setLabel(l("Read More", "Lire plus", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("LINK") + .setURL("https://mlp.fandom.com/wiki/" + encodeURI(keys[1])), + new MessageButton() + .setCustomId("pony.pixel|" + keys[1]) + .setLabel("Pixel Art") + .setDisabled(!fs.existsSync("./pixel/" + keys[1].toLowerCase())) + .setStyle("SECONDARY"), + new MessageButton() + .setCustomId("result.report|" + keys[1]) + .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("DANGER") + ) + ] + }); } \ No newline at end of file -- cgit