diff options
author | Minteck <contact@minteck.org> | 2022-01-09 18:22:55 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-01-09 18:22:55 +0100 |
commit | 7d0d6272c8bf5260da53210c8ed327980e396397 (patch) | |
tree | 6812176231961767e9b7aa731193abb387bbc107 /handler/command.js | |
parent | dc65563df84d80bcc0970febef6a5f9a7759bdcb (diff) | |
download | ponyfind-7d0d6272c8bf5260da53210c8ed327980e396397.tar.gz ponyfind-7d0d6272c8bf5260da53210c8ed327980e396397.tar.bz2 ponyfind-7d0d6272c8bf5260da53210c8ed327980e396397.zip |
Update
Diffstat (limited to 'handler/command.js')
-rw-r--r-- | handler/command.js | 341 |
1 files changed, 15 insertions, 326 deletions
diff --git a/handler/command.js b/handler/command.js index d263204..1447332 100644 --- a/handler/command.js +++ b/handler/command.js @@ -11,346 +11,35 @@ 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) {
- if (bytes > 1000) {
- if (bytes > 1000000) {
- return (bytes / 1000000).toFixed(2) + " MB";
- } else {
- return (bytes / 1000).toFixed(2) + " KB";
- }
- } else {
- return bytes + " B";
- }
-}
-
-function secondsToPretty(seconds) {
- if (seconds > 60) {
- if (seconds > 3600) {
- if (seconds > 216000) {
- return Math.floor(seconds / 216000) + " day" + (Math.floor(seconds / 216000) > 1 ? "s" : "");
- } else {
- return Math.floor(seconds / 3600) + " hour" + (Math.floor(seconds / 3600) > 1 ? "s" : "");
- }
- } else {
- return Math.floor(seconds / 60) + " minute" + (Math.floor(seconds / 60) > 1 ? "s" : "");
- }
- } else {
- return Math.floor(seconds) + " second" + (Math.floor(seconds) > 1 ? "s" : "");
- }
-}
+const commandRandom = require('../commands/random');
+const commandInfo = require('../commands/info');
+const commandEval = require('../commands/eval');
+const commandConfig = require('../commands/config');
+const commandPony = require('../commands/pony');
+const commandHelp = require('../commands/help');
module.exports = async (interaction) => {
if (interaction.commandName === 'random') {
- keys = [
- null,
- list[Math.floor(Math.random() * list.length)]
- ]
- await interaction.reply({
- ephemeral: interaction.guild !== null,
- embeds: [
- getEmbed(keys[1], interaction.user.id, interaction.guild ? interaction.guild.id : 0)
- ],
- 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")
- )
- ]
- });
+ await commandRandom(interaction);
}
- if (interaction.commandName === 'info') {
- 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-epk" + 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 fields = [
- { name: l("Software version", "Version du logiciel", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: "v" + fs.readFileSync("./config/version.txt") + "." + fs.readFileSync("./.git/refs/heads/trunk").toString().substr(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("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), inline: true },
- { name: l("Uptime", "Durée de fonctionnement", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: secondsToPretty(process.uptime()), inline: true },
- ];
+ if (interaction.commandName === 'help') {
+ await commandHelp(interaction);
+ }
- 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(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))
- ]
- });
+ if (interaction.commandName === 'info') {
+ await commandInfo(interaction);
}
if (interaction.commandName === 'eval') {
- 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```")
- ]
- });
- }
+ await commandEval(interaction);
}
if (interaction.commandName === 'config') {
- 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_SERVER") && 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))
- ]
- });
- }
- }
+ await commandConfig(interaction);
}
if (interaction.commandName === 'pony') {
- query = interaction.options.getString('query');
- result = getResult(query);
-
- if (result.results.length > 0 && getEmbed(result.results[0], interaction.user.id, interaction.guild ? interaction.guild.id : 0) !== false) {
- 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")
- )
- ]
- });
- }
+ await commandPony(interaction);
}
}
\ No newline at end of file |