diff options
author | Minteck <contact@minteck.org> | 2022-01-07 18:04:44 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-01-07 18:04:44 +0100 |
commit | ac2dea4a23ca72001e41c1dbf66ff1a0d01e217c (patch) | |
tree | 3cb37a7135bf5530917270ebde08f797ff52ea38 | |
parent | 041b8d1035cf0e7f6f8c686ec5dd7aa4ef204907 (diff) | |
download | ponyfind-ac2dea4a23ca72001e41c1dbf66ff1a0d01e217c.tar.gz ponyfind-ac2dea4a23ca72001e41c1dbf66ff1a0d01e217c.tar.bz2 ponyfind-ac2dea4a23ca72001e41c1dbf66ff1a0d01e217c.zip |
Update
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | .idea/deployment.xml | 14 | ||||
-rw-r--r-- | TODO | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | embed.js | 68 | ||||
-rwxr-xr-x | handler/button.js | 60 | ||||
-rwxr-xr-x | handler/command.js | 137 | ||||
-rwxr-xr-x | handler/errors.js | 44 | ||||
-rwxr-xr-x | handler/menu.js | 22 | ||||
-rwxr-xr-x[-rw-r--r--] | index.js | 178 | ||||
-rwxr-xr-x | registers.js | 33 | ||||
-rw-r--r-- | reports/PonyIssue-2022-01-07T13-45-37-231Z.txt | 18 | ||||
-rwxr-xr-x[-rw-r--r--] | result.js | 2 | ||||
-rw-r--r-- | servers.json | 3 |
13 files changed, 407 insertions, 178 deletions
@@ -1,4 +1,6 @@ +token.stable.txt token.txt +token.beta.txt client.txt data node_modules diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 0000000..247908f --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="PublishConfigData" serverName="Familine" remoteFilesAllowedToDisappearOnAutoupload="false"> + <serverData> + <paths name="Familine"> + <serverdata> + <mappings> + <mapping deploy="/mnt/ponyfind" local="$PROJECT_DIR$" web="/" /> + </mappings> + </serverdata> + </paths> + </serverData> + </component> +</project>
\ No newline at end of file @@ -0,0 +1,4 @@ +- Automatic error reporting
+- "Report an issue" button
+- "Pixel Art" button
+- Per-server language (enforce)
\ No newline at end of file @@ -1,7 +1,7 @@ const { MessageEmbed } = require("discord.js"); const data = require('./data/data.json'); -module.exports = (page, id) => { +module.exports = (page, id, gid) => { if (typeof data[page] === "undefined") { return false; } @@ -39,98 +39,98 @@ module.exports = (page, id) => { break; } - let kind = l("Unknown", "Inconnu", id); + let kind = l("Unknown", "Inconnu", id, gid); switch (d.kind) { case "Pegasus": - kind = l("Pegasus", "Pégase", id) + kind = l("Pegasus", "Pégase", id, gid) break; case "Earth": - kind = l("Earth Pony", "Poney terrestre", id) + kind = l("Earth Pony", "Poney terrestre", id, gid) break; case "Ahuizotl": - kind = l("Ahiuzotl", "Ahuizotl", id) + kind = l("Ahiuzotl", "Ahuizotl", id, gid) break; case "Rabbit": - kind = l("Rabbit", "Lapin", id) + kind = l("Rabbit", "Lapin", id, gid) break; case "Pony": - kind = l("Pony", "Poney", id) + kind = l("Pony", "Poney", id, gid) break; case "Unicorn": - kind = l("Unicorn", "Licorne", id) + kind = l("Unicorn", "Licorne", id, gid) break; case "Draconequus": - kind = l("Draconequus", "Draconequus", id) + kind = l("Draconequus", "Draconequus", id, gid) break; case "Griffon": - kind = l("Griffon", "Gryphon", id) + kind = l("Griffon", "Gryphon", id, gid) break; case "Alligator": - kind = l("Alligator", "Alligator", id) + kind = l("Alligator", "Alligator", id, gid) break; case "Minotaur": - kind = l("Minotaur", "Minotaure", id) + kind = l("Minotaur", "Minotaure", id, gid) break; case "Buffalo": - kind = l("Buffalo", "Buffle", id) + kind = l("Buffalo", "Buffle", id, gid) break; case "Alicorn": - kind = l("Alicorn", "Alicorne", id) + kind = l("Alicorn", "Alicorne", id, gid) break; case "Persian": - kind = l("Persian", "Persien", id) + kind = l("Persian", "Persien", id, gid) break; case "Owl": - kind = l("Owl", "Hibou", id) + kind = l("Owl", "Hibou", id, gid) break; case "Phoenix": - kind = l("Phoenix", "Phénix", id) + kind = l("Phoenix", "Phénix", id, gid) break; case "Changelingbr": - kind = l("Changelingbr", "Changelingbr", id) + kind = l("Changelingbr", "Changelingbr", id, gid) break; case "Breezie": - kind = l("Breezie", "Brisie", id) + kind = l("Breezie", "Brisie", id, gid) break; case "Dragon": - kind = l("Dragon", "Dragon", id) + kind = l("Dragon", "Dragon", id, gid) break; case "Sea": - kind = l("Sea", "Mer", id) + kind = l("Sea", "Mer", id, gid) break; case "Tortoise": - kind = l("Tortoise", "Tortue", id) + kind = l("Tortoise", "Tortue", id, gid) break; case "Centaurref": - kind = l("Centaurref", "Centaurref", id) + kind = l("Centaurref", "Centaurref", id, gid) break; case "Collie": - kind = l("Collie", "Collie", id) + kind = l("Collie", "Collie", id, gid) break; case "Zebrabr": - kind = l("Zebrabr", "Zebrabr", id) + kind = l("Zebrabr", "Zebrabr", id, gid) break; } @@ -138,7 +138,7 @@ module.exports = (page, id) => { let naming = "-"; if (names.length > 5) { - naming = "- " + names[0] + "\n- " + names[1] + "\n- " + names[2] + "\n- " + names[3] + "\n- " + names[4] + "\n*" + l("and " + (names.length - 5) + " others", "et " + (names.length - 5) + " autres", id) + "*" + naming = "- " + names[0] + "\n- " + names[1] + "\n- " + names[2] + "\n- " + names[3] + "\n- " + names[4] + "\n*" + l("and " + (names.length - 5) + " others", "et " + (names.length - 5) + " autres", id, gid) + "*" } else { if (names.length > 1) { naming = "- " + names.join("\n- ") @@ -153,7 +153,7 @@ module.exports = (page, id) => { let jobs = page; if (d.occupation.length > 5) { - jobs = "- " + d.occupation[0] + "\n- " + d.occupation[1] + "\n- " + d.occupation[2] + "\n- " + d.occupation[3] + "\n- " + d.occupation[4] + "\n*" + l("and " + (d.occupation.length - 5) + " others", "et " + (d.occupation.length - 5) + " autres", id) + "*" + jobs = "- " + d.occupation[0] + "\n- " + d.occupation[1] + "\n- " + d.occupation[2] + "\n- " + d.occupation[3] + "\n- " + d.occupation[4] + "\n*" + l("and " + (d.occupation.length - 5) + " others", "et " + (d.occupation.length - 5) + " autres", id, gid) + "*" } else { if (d.occupation.length > 1) { jobs = "- " + d.occupation.join("\n- ") @@ -164,7 +164,7 @@ module.exports = (page, id) => { let location = page; if (d.residence.length > 5) { - location = "- " + d.residence[0] + "\n- " + d.residence[1] + "\n- " + d.residence[2] + "\n- " + d.residence[3] + "\n- " + d.residence[4] + "\n*" + l("and " + (d.residence.length - 5) + " others", "et " + (d.residence.length - 5) + " autres", id) + "*" + location = "- " + d.residence[0] + "\n- " + d.residence[1] + "\n- " + d.residence[2] + "\n- " + d.residence[3] + "\n- " + d.residence[4] + "\n*" + l("and " + (d.residence.length - 5) + " others", "et " + (d.residence.length - 5) + " autres", id, gid) + "*" } else { if (d.residence.length > 1) { location = "- " + d.residence.join("\n- ") @@ -179,11 +179,11 @@ module.exports = (page, id) => { .setImage(d.image) .setThumbnail(d.mark) .addFields([ - { name: l("Nicknames", "Surnoms", id), value: naming, inline: true }, - { name: l("Sex", "Sexe", id), value: d.sex === "F" ? "♀" : "♂", inline: true }, - { name: l("Kind", "Type", id), value: kind, inline: true }, - { name: l("Occupation(s)", "Occupation(s)", id), value: "(" + l("spoilers", "révélations", id) + ") ||" + jobs + "||", inline: true }, - { name: l("Home(s)", "Résidence(s)", id), value: "(" + l("spoilers", "révélations", id) + ") ||" + location + "||", inline: true } + { name: l("Nicknames", "Surnoms", id, gid), value: naming, inline: true }, + { name: l("Sex", "Sexe", id, gid), value: d.sex === "F" ? "♀" : "♂", inline: true }, + { name: l("Kind", "Type", id, gid), value: kind, inline: true }, + { name: l("Occupation(s)", "Occupation(s)", id, gid), value: "(" + l("spoilers", "révélations", id, gid) + ")\n||" + jobs + "||", inline: true }, + { name: l("Home(s)", "Résidence(s)", id, gid), value: "(" + l("spoilers", "révélations", id, gid) + ")\n||" + location + "||", inline: true } ]) - .setFooter(l("Content provided without warranty, use at your own risk.", "Contenu fourni sans aucune garantie, utilisez à vos risques et périls", id)) + .setFooter(l("Content provided without warranty, use at your own risk.", "Contenu fourni sans aucune garantie, utilisez à vos risques et périls", id, gid)) }
\ No newline at end of file diff --git a/handler/button.js b/handler/button.js new file mode 100755 index 0000000..5d5fe03 --- /dev/null +++ b/handler/button.js @@ -0,0 +1,60 @@ +const fs = require('fs');
+const { MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require('discord.js');
+
+module.exports = async (interaction) => {
+ keys = interaction.customId.split("|")
+
+ if (keys[0] === "result.report") {
+ await interaction.reply({
+ ephemeral: false,
+ embeds: [
+ new MessageEmbed()
+ .setColor('#dc2828')
+ .setTitle(l("Report an issue with", "Signaler un problème avec", interaction.user.id, interaction.guild.id) + " \"" + keys[1] + "\"")
+ .setDescription(l("If you think the result to your query is problematic, you can report it so that the developers fix the issue.", "Si vous pensez que le résultat donné est problématique, vous pouvez le signaler pour que les développeurs corrigent le problème.", interaction.user.id, interaction.guild.id))
+ ],
+ components: [
+ new MessageActionRow()
+ .addComponents(
+ new MessageSelectMenu()
+ .setCustomId('select')
+ .setPlaceholder(l("Select a type of issue", "Sélectionnez le type de problème", interaction.user.id, interaction.guild.id))
+ .addOptions([
+ {
+ label: l("Inappropriate", "Inapproprié", interaction.user.id, interaction.guild.id),
+ description: l("The result contains inappropriate content: chocking or violent.", "La réponse contient du contenu inapproprié à certains publics, choquant, ou violent.", interaction.user.id, interaction.guild.id),
+ value: 'report.issue.innapropriate|' + keys[1],
+ },
+ {
+ label: l("Off topic", "Hors sujet", interaction.user.id, interaction.guild.id),
+ description: l("The result contains info that is unrelated to the aforementioned character.", "La réponse contient du contenu n'ayant pas de rapport avec le personnage évoqué.", interaction.user.id, interaction.guild.id),
+ value: 'report.issue.off|' + keys[1],
+ },
+ {
+ label: l("Incoherent data", "Données incohérentes", interaction.user.id, interaction.guild.id),
+ description: l("The result contains incoherent data, due to a database error.", "La réponse contient des données incohérentes, dûes à une erreur dans la base de données.", interaction.user.id, interaction.guild.id),
+ value: 'report.issue.data|' + keys[1],
+ },
+ {
+ label: l("Wrong result", "Mauvais résultat", interaction.user.id, interaction.guild.id),
+ description: l("The given result is not what was expected with this query.", "La réponse donnée n'est pas la réponse attendue par rapport à la demande.", interaction.user.id, interaction.guild.id),
+ value: 'report.issue.wrong|' + keys[1],
+ },
+ {
+ label: l("Wrong image(s)", "Mauvaise(s) image(s)", interaction.user.id, interaction.guild.id),
+ description: l("One or more of the provided image(s) do(es)n't correspond to the shown character.", "Une ou plusieurs image(s) fournie(s) avec la réponse ne correspond(ent) pas au personnage affiché.", interaction.user.id, interaction.guild.id),
+ value: 'report.issue.image|' + keys[1],
+ },
+ {
+ label: l("Wrong information", "Information erronée", interaction.user.id, interaction.guild.id),
+ description: l("A provided info does not correspond to the real info from a reliable source.", "Une information fournie ne correspond pas à la réelle information depuis une source fiable.", interaction.user.id, interaction.guild.id),
+ value: 'report.issue.missinfo|' + keys[1],
+ },
+ ]),
+ )
+ ]
+ });
+ } else {
+ throw new Error("Unknown Button ID");
+ }
+}
\ No newline at end of file diff --git a/handler/command.js b/handler/command.js new file mode 100755 index 0000000..c1cfe22 --- /dev/null +++ b/handler/command.js @@ -0,0 +1,137 @@ +const fs = require('fs');
+const { MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require('discord.js');
+
+const getResult = require('../result');
+const getEmbed = require('../embed');
+
+module.exports = async (interaction) => {
+ if (interaction.commandName === 'lang') {
+ lang = interaction.options.getString('locale');
+ if (lang === "fr") {
+ langs[interaction.user.id] = "fr";
+ } else {
+ langs[interaction.user.id] = "en";
+ }
+ fs.writeFileSync("./userdata.json", JSON.stringify(langs, null, 4));
+ if (typeof servers[interaction.guild.id] !== "undefined") {
+ if (lang === "fr") {
+ await interaction.reply({
+ ephemeral: false,
+ embeds: [
+ new MessageEmbed()
+ .setColor('#28dc46')
+ .setTitle(l("Language settings", "Paramètres de langue", interaction.user.id, interaction.guild.id))
+ .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.id))
+ ]
+ });
+ } else {
+ await interaction.reply({
+ ephemeral: false,
+ embeds: [
+ new MessageEmbed()
+ .setColor('#28dc46')
+ .setTitle(l("Language settings", "Paramètres de langue", interaction.user.id, interaction.guild.id))
+ .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.id))
+ ]
+ });
+ }
+ } else {
+ await interaction.reply({
+ ephemeral: false,
+ embeds: [
+ new MessageEmbed()
+ .setColor('#28dc46')
+ .setTitle(l("Language settings", "Paramètres de langue", interaction.user.id, interaction.guild.id))
+ .setDescription(l("Your preferred language is now **English**.", "Votre langue principale est maintenant le **français**.", interaction.user.id, interaction.guild.id))
+ ]
+ });
+ }
+ }
+
+ if (interaction.commandName === 'serverlang') {
+ lang = interaction.options.getString('locale');
+ if (lang === "fr") {
+ servers[interaction.guild.id] = "fr";
+ } else if (lang === "en") {
+ servers[interaction.guild.id] = "en";
+ } else {
+ delete servers[interaction.guild.id];
+ }
+ fs.writeFileSync("./servers.json", JSON.stringify(servers, null, 4));
+ if (lang === "en" || lang === "fr") {
+ await interaction.reply({
+ ephemeral: false,
+ embeds: [
+ new MessageEmbed()
+ .setColor('#28dc46')
+ .setTitle(l("Server language settings", "Paramètres de langue du serveur", interaction.user.id, interaction.guild.id))
+ .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.id))
+ ]
+ });
+ } else {
+ await interaction.reply({
+ ephemeral: false,
+ embeds: [
+ new MessageEmbed()
+ .setColor('#28dc46')
+ .setTitle(l("Server language settings", "Paramètres de langue du serveur", interaction.user.id, interaction.guild.id))
+ .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.id))
+ ]
+ });
+ }
+ }
+
+ 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.id) !== false) {
+ await interaction.reply({
+ ephemeral: false,
+ embeds: [
+ getEmbed(result.results[0], interaction.user.id, interaction.guild.id)
+ ],
+ components: [
+ new MessageActionRow()
+ .addComponents(
+ new MessageButton()
+ .setLabel(l("Read More", "Lire plus", interaction.user.id, interaction.guild.id))
+ .setStyle("LINK")
+ .setURL("https://mlp.fandom.com/wiki/" + encodeURI(result.results[0])),
+ new MessageButton()
+ .setCustomId("pony.pixel|" + result.results[0])
+ .setLabel("Pixel Art")
+ .setStyle("SECONDARY"),
+ new MessageButton()
+ .setCustomId("result.report|" + result.results[0])
+ .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild.id))
+ .setStyle("DANGER")
+ )
+ ]
+ });
+ } else {
+ await interaction.reply({
+ ephemeral: false,
+ embeds: [
+ new MessageEmbed()
+ .setColor('#dc2828')
+ .setTitle(l("Results for", "Résultats pour", interaction.user.id, interaction.guild.id) + " \"" + 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.id))
+ ],
+ 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.id))
+ .setStyle("SECONDARY"),
+ new MessageButton()
+ .setCustomId("result.report")
+ .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild.id))
+ .setStyle("DANGER")
+ )
+ ]
+ });
+ }
+ }
+}
\ No newline at end of file diff --git a/handler/errors.js b/handler/errors.js new file mode 100755 index 0000000..1bae519 --- /dev/null +++ b/handler/errors.js @@ -0,0 +1,44 @@ +const fs = require('fs');
+const { MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require('discord.js');
+
+module.exports = async (interaction, e) => {
+ try {
+ await interaction.reply({
+ ephemeral: false,
+ embeds: [
+ new MessageEmbed()
+ .setColor('#dc2828')
+ .setTitle(l("An internal exception occurred", "Une erreur interne s'est produite", interaction.user.id, interaction.guild.id))
+ .setDescription(l("That's not your fault! The developers have already been informed about the issue and will resolve it as soon as possible.", "Ce n'est pas votre faute ! Les développeurs ont déjà été informés du problème et il sera corrigé aussi vite que possible.", interaction.user.id, interaction.guild.id) + "\n\n```\n" + e.stack + "\n```")
+ ],
+ components: [
+ new MessageActionRow()
+ .addComponents(
+ new MessageButton()
+ .setCustomId("error.report")
+ .setLabel(l("Send bug report", "Envoyer un rapport de bug", interaction.user.id, interaction.guild.id))
+ .setStyle("DANGER")
+ )
+ ]
+ });
+ } catch (e) {
+ await interaction.reply({
+ ephemeral: false,
+ embeds: [
+ new MessageEmbed()
+ .setColor('#dc2828')
+ .setTitle("An internal exception occurred")
+ .setDescription("That's not your fault! The developers have already been informed about the issue and will resolve it as soon as possible.\n\n```\n" + e.stack + "\n```")
+ ],
+ components: [
+ new MessageActionRow()
+ .addComponents(
+ new MessageButton()
+ .setCustomId("error.report")
+ .setLabel("Send bug report")
+ .setStyle("DANGER")
+ )
+ ]
+ });
+ }
+}
\ No newline at end of file diff --git a/handler/menu.js b/handler/menu.js new file mode 100755 index 0000000..e2fd8c2 --- /dev/null +++ b/handler/menu.js @@ -0,0 +1,22 @@ +const fs = require('fs');
+const { MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require('discord.js');
+
+module.exports = async (interaction) => {
+ keys = interaction.values[0].split("|")
+
+ if (keys[0].startsWith("report.issue.")) {
+ item = keys[0].substr(13)
+ fs.writeFileSync("./reports/PonyIssue-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt", "-------------------\nPonyfind Issue Report\n-------------------\n\nReporter:\n " + interaction.user.tag + " (" + interaction.user.id + ")\n\nServer:\n " + interaction.guild.name + " (" + interaction.guild.id + ")\n\nChannel:\n " + interaction.channel.name + " (" + interaction.channel.id + ")\n\nItem:\n " + keys[1] + "\n\nReport Type:\n " + item)
+ await interaction.reply({
+ ephemeral: false,
+ embeds: [
+ new MessageEmbed()
+ .setColor('#28dc46')
+ .setTitle(l("Thanks for reporting an issue with", "Merci d'avoir signalé un problème avec", interaction.user.id, interaction.guild.id) + " \"" + keys[1] + "\"" + l("!", " !", interaction.user.id, interaction.guild.id))
+ .setDescription(l("Your report has been sent to the developers. They can contact you later if your settings allow this to ask you more about your issue.\nThanks for your help!", "Votre rapport a bien été envoyé aux développeurs. Ils pourront vous recontacter si vos paramètres le permettent afin de vous poser plus de questions sur le problème que vous rencontrez.\nMerci d'aider à améliorer notre système !", interaction.user.id, interaction.guild.id))
+ ]
+ });
+ } else {
+ throw new Error("Unknown Menu ID");
+ }
+}
\ No newline at end of file @@ -1,49 +1,44 @@ -// https://discord.com/oauth2/authorize?client_id=928695013083316295&scope=bot%20applications.commands&permissions=8 +// Stable: https://discord.com/oauth2/authorize?client_id=928695013083316295&scope=bot%20applications.commands&permissions=8 +// Beta: https://discord.com/oauth2/authorize?client_id=929057534491361341&scope=bot%20applications.commands&permissions=8 + +console.log("Channel: " + (typeof process.argv[2] !== "undefined" ? "beta" : "stable")); const fs = require('fs'); const { REST } = require('@discordjs/rest'); -const { SlashCommandBuilder } = require('@discordjs/builders'); const { Routes } = require('discord-api-types/v9'); if (!fs.existsSync("./userdata.json")) fs.writeFileSync("./userdata.json", "{}"); +if (!fs.existsSync("./servers.json")) fs.writeFileSync("./servers.json", "{}"); -const rest = new REST({ version: '9' }).setToken(fs.readFileSync("./token.txt").toString()); +const rest = new REST({ version: '9' }).setToken(fs.readFileSync("./token." + (typeof process.argv[2] !== "undefined" ? "beta" : "stable") + ".txt").toString()); const { Client, Intents, MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require('discord.js'); const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); -const getResult = require('./result'); -const getEmbed = require('./embed'); +const commandHandler = require('./handler/command'); +const buttonHandler = require('./handler/button'); +const menuHandler = require('./handler/menu'); +const errorHandler = require('./handler/errors'); -let langs = JSON.parse(fs.readFileSync("./userdata.json")); +global.langs = JSON.parse(fs.readFileSync("./userdata.json")); +global.servers = JSON.parse(fs.readFileSync("./servers.json")); -global.l = (en, fr, id) => { - if (langs[id] === "fr") { - return fr; +global.l = (en, fr, id, gid) => { + if (typeof servers[gid] !== "undefined") { + if (servers[gid] === "fr") { + return fr; + } else { + return en; + } } else { - return en; + if (langs[id] === "fr") { + return fr; + } else { + return en; + } } } -const commands = [ - new SlashCommandBuilder() - .setName('pony') - .setDescription("Searches for a pony") - .addStringOption(option => - option.setName("query") - .setDescription("The pony to search for") - .setRequired(true) - ), - new SlashCommandBuilder() - .setName('lang') - .setDescription("Changes the bot's language") - .addStringOption(option => - option.setName('locale') - .setDescription('The selected language') - .setRequired(true) - .addChoice('Français', 'fr') - .addChoice('English', 'en') - ) -]; +const commands = require('./registers'); client.on('ready', async () => { console.log(`Logged in as ${client.user.tag}!`); @@ -64,122 +59,19 @@ client.on('ready', async () => { }); client.on('interactionCreate', async interaction => { - if (!interaction.isCommand()) return; - try { - if (interaction.commandName === 'lang') { - lang = interaction.options.getString('locale'); - if (lang === "fr") { - langs[interaction.user.id] = "fr"; - } else { - langs[interaction.user.id] = "en"; - } - fs.writeFileSync("./userdata.json", JSON.stringify(langs, null, 4)); - await interaction.reply({ - ephemeral: false, - embeds: [ - new MessageEmbed() - .setColor('#28dc46') - .setTitle(l("Language settings", "Paramètres de langue", interaction.user.id)) - .setDescription(l("Your preferred language is now **English**.", "Votre langue principale est maintenant le **français**.", interaction.user.id)) - ] - }); - } - - if (interaction.commandName === 'pony') { - query = interaction.options.getString('query'); - result = getResult(query, interaction.user.id); - - if (result.results.length > 0 && getEmbed(result.results[0], interaction.user.id) !== false) { - await interaction.reply({ - ephemeral: false, - embeds: [ - getEmbed(result.results[0], interaction.user.id) - ], - components: [ - new MessageActionRow() - .addComponents( - new MessageButton() - .setLabel(l("Read More", "Lire plus", interaction.user.id)) - .setStyle("LINK") - .setURL("https://mlp.fandom.com/wiki/" + encodeURI(result.results[0])), - new MessageButton() - .setCustomId("pixel") - .setLabel("Pixel Art") - .setStyle("SECONDARY"), - new MessageButton() - .setCustomId("report") - .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id)) - .setStyle("DANGER") - ) - ] - }); - } else { - await interaction.reply({ - ephemeral: false, - embeds: [ - new MessageEmbed() - .setColor('#dc2828') - .setTitle(l("Results for", "Résultats pour", interaction.user.id) + " \"" + 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)) - ], - components: [ - new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId("pixel") - .setLabel(l("Suggest a missing pony", "Proposer un poney manquant", interaction.user.id)) - .setStyle("SECONDARY"), - new MessageButton() - .setCustomId("report") - .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id)) - .setStyle("DANGER") - ) - ] - }); - } + if (interaction.isCommand()) { + await commandHandler(interaction); + } else if (interaction.isButton()) { + await buttonHandler(interaction); + } else if (interaction.isSelectMenu()) { + await menuHandler(interaction); + } else { + throw new Error("Interaction type not supported") } } catch (e) { - try { - await interaction.reply({ - ephemeral: false, - embeds: [ - new MessageEmbed() - .setColor('#dc2828') - .setTitle(l("An internal exception occurred", "Une erreur interne s'est produite", interaction.user.id)) - .setDescription("```\n" + e.stack + "\n```") - ], - components: [ - new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId("report") - .setLabel(l("Send bug report", "Envoyer un rapport de bug", interaction.user.id)) - .setStyle("DANGER") - ) - ] - }); - } catch (e) { - await interaction.reply({ - ephemeral: false, - embeds: [ - new MessageEmbed() - .setColor('#dc2828') - .setTitle("An internal exception occurred") - .setDescription("```\n" + e.stack + "\n```") - ], - components: [ - new MessageActionRow() - .addComponents( - new MessageButton() - .setCustomId("report") - .setLabel("Send bug report") - .setStyle("DANGER") - ) - ] - }); - } + errorHandler(interaction, e) } }); -client.login(fs.readFileSync("./token.txt").toString());
\ No newline at end of file +client.login(fs.readFileSync("./token." + (typeof process.argv[2] !== "undefined" ? "beta" : "stable") + ".txt").toString());
\ No newline at end of file diff --git a/registers.js b/registers.js new file mode 100755 index 0000000..4092d12 --- /dev/null +++ b/registers.js @@ -0,0 +1,33 @@ +const { SlashCommandBuilder } = require('@discordjs/builders');
+
+module.exports = [
+ new SlashCommandBuilder()
+ .setName('pony')
+ .setDescription("Searches for a pony")
+ .addStringOption(option =>
+ option.setName("query")
+ .setDescription("The pony to search for")
+ .setRequired(true)
+ ),
+ new SlashCommandBuilder()
+ .setName('lang')
+ .setDescription("Changes the bot's language")
+ .addStringOption(option =>
+ option.setName('locale')
+ .setDescription('The selected language')
+ .setRequired(true)
+ .addChoice('Français', 'fr')
+ .addChoice('English', 'en')
+ ),
+ new SlashCommandBuilder()
+ .setName('serverlang')
+ .setDescription("Changes the bot's language on this server")
+ .addStringOption(option =>
+ option.setName('locale')
+ .setDescription('The selected language')
+ .setRequired(true)
+ .addChoice('Français', 'fr')
+ .addChoice('English', 'en')
+ .addChoice('User prefered language (default)', 'off')
+ )
+]
\ No newline at end of file diff --git a/reports/PonyIssue-2022-01-07T13-45-37-231Z.txt b/reports/PonyIssue-2022-01-07T13-45-37-231Z.txt new file mode 100644 index 0000000..6edffc3 --- /dev/null +++ b/reports/PonyIssue-2022-01-07T13-45-37-231Z.txt @@ -0,0 +1,18 @@ +------------------- +Ponyfind Issue Report +------------------- + +Reporter: + Minteck#2245 (493845599469174794) + +Server: + Ponyfind Test Server (928632669896593508) + +Channel: + truc (928749545947557938) + +Item: + Scootaloo + +Report Type: + data
\ No newline at end of file diff --git a/result.js b/result.js index faef56c..68eaf14 100644..100755 --- a/result.js +++ b/result.js @@ -1,7 +1,7 @@ const db = require('./data/search.json').associations; const Fuse = require('fuse.js'); -module.exports = (query, id) => { +module.exports = (query) => { const fuse = new Fuse(db, { keys: [ 'title', 'endpoint' ] }) diff --git a/servers.json b/servers.json new file mode 100644 index 0000000..a08681c --- /dev/null +++ b/servers.json @@ -0,0 +1,3 @@ +{ + "928632669896593508": "fr" +}
\ No newline at end of file |