aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--TODO4
-rw-r--r--beta0
-rw-r--r--bot.js77
-rw-r--r--config/version.txt2
-rw-r--r--handler/button.js60
-rw-r--r--handler/command.js327
-rw-r--r--handler/errors.js24
-rw-r--r--handler/menu.js10
-rw-r--r--index.js99
-rw-r--r--modules/embed.js26
-rw-r--r--modules/registers.js85
-rw-r--r--modules/result.js3
-rw-r--r--update/infobox.js2
-rw-r--r--update/parse.js28
-rw-r--r--user/spoilers.json3
16 files changed, 466 insertions, 288 deletions
diff --git a/README.md b/README.md
index 1eb4383..036bd2a 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Ponyfind
```plaintext
npm install # Install dependencies
-node update/index.js # Generate database
-node index.js # Start bot
+node update/bot.js # Generate database
+node bot.js # Start bot
```
diff --git a/TODO b/TODO
index f6f2425..ba163a6 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1 @@
-- /stats
-- /spoilers (on|off|hide)
-- /takeout \ No newline at end of file
+- /random \ No newline at end of file
diff --git a/beta b/beta
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/beta
diff --git a/bot.js b/bot.js
new file mode 100644
index 0000000..978544b
--- /dev/null
+++ b/bot.js
@@ -0,0 +1,77 @@
+// Stable: https://discord.com/oauth2/authorize?client_id=928695013083316295&scope=bot%20applications.commands&permissions=0
+// Beta: https://discord.com/oauth2/authorize?client_id=929057534491361341&scope=bot%20applications.commands&permissions=0
+
+console.log("Channel: " + (require('fs').existsSync("./beta") ? "beta" : "stable"));
+global.channel = (require('fs').existsSync("./beta") ? "beta" : "stable");
+
+const fs = require('fs');
+const { REST } = require('@discordjs/rest');
+const { Routes } = require('discord-api-types/v9');
+
+if (!fs.existsSync("./user/userdata.json")) fs.writeFileSync("./user/userdata.json", "{}");
+if (!fs.existsSync("./user/spoilers.json")) fs.writeFileSync("./user/spoilers.json", "{}");
+if (!fs.existsSync("./user/servers.json")) fs.writeFileSync("./user/servers.json", "{}");
+if (!fs.existsSync("./reports")) fs.mkdirSync("./reports");
+
+const rest = new REST({ version: '9' }).setToken(fs.readFileSync("./config/token." + (require('fs').existsSync("./beta") ? "beta" : "stable") + ".txt").toString());
+const { Client, Intents, MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require('discord.js');
+global.client = new Client({ intents: [Intents.FLAGS.GUILDS] });
+
+const commandHandler = require('./handler/command');
+const buttonHandler = require('./handler/button');
+const menuHandler = require('./handler/menu');
+const errorHandler = require('./handler/errors');
+
+global.langs = JSON.parse(fs.readFileSync("./user/userdata.json"));
+global.spoils = JSON.parse(fs.readFileSync("./user/spoilers.json"));
+global.servers = JSON.parse(fs.readFileSync("./user/servers.json"));
+
+global.l = (en, fr, id, gid) => {
+ if (typeof servers[gid] !== "undefined") {
+ if (servers[gid] === "fr") {
+ return fr;
+ } else {
+ return en;
+ }
+ } else {
+ if (langs[id] === "fr") {
+ return fr;
+ } else {
+ return en;
+ }
+ }
+}
+
+const commands = require('./modules/registers');
+
+client.on('ready', async () => {
+ console.log(`Logged in as ${client.user.tag}!`);
+ console.log("Started refreshing application (/) commands globally");
+
+ await rest.put(
+ Routes.applicationCommands(fs.readFileSync("./config/client." + (require('fs').existsSync("./beta") ? "beta" : "stable") + ".txt").toString()),
+ { body: commands },
+ );
+
+ console.log("Successfully reloaded application (/) commands globally");
+});
+
+client.on('interactionCreate', async interaction => {
+ if (!interaction) { return; }
+
+ try {
+ 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) {
+ errorHandler(interaction, e)
+ }
+});
+
+client.login(fs.readFileSync("./config/token." + (require('fs').existsSync("./beta") ? "beta" : "stable") + ".txt").toString()); \ No newline at end of file
diff --git a/config/version.txt b/config/version.txt
index 09a3acf..b1d7abc 100644
--- a/config/version.txt
+++ b/config/version.txt
@@ -1 +1 @@
-0.6.0 \ No newline at end of file
+0.6.2 \ No newline at end of file
diff --git a/handler/button.js b/handler/button.js
index 8fc49f5..c159071 100644
--- a/handler/button.js
+++ b/handler/button.js
@@ -10,15 +10,15 @@ module.exports = async (interaction) => {
if (keys[0] === "pony.display") {
await interaction.reply({
- ephemeral: true,
+ ephemeral: interaction.guild !== null,
embeds: [
- getEmbed(keys[1], interaction.user.id, interaction.guild.id)
+ 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.id))
+ .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()
@@ -28,60 +28,60 @@ module.exports = async (interaction) => {
.setStyle("SECONDARY"),
new MessageButton()
.setCustomId("result.report|" + keys[1])
- .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild.id))
+ .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0))
.setStyle("DANGER")
)
]
});
} else if (keys[0] === "result.report") {
await interaction.reply({
- ephemeral: true,
+ ephemeral: interaction.guild !== null,
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))
+ .setTitle(l("Report an issue with", "Signaler un problème avec", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + " \"" + 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 ? interaction.guild.id : 0))
],
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))
+ .setPlaceholder(l("Select a type of issue", "Sélectionnez le type de problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0))
.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),
+ label: l("Inappropriate", "Inapproprié", interaction.user.id, interaction.guild ? interaction.guild.id : 0),
+ 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 ? interaction.guild.id : 0),
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),
+ label: l("Off topic", "Hors sujet", interaction.user.id, interaction.guild ? interaction.guild.id : 0),
+ 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 ? interaction.guild.id : 0),
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),
+ label: l("Incoherent data", "Données incohérentes", interaction.user.id, interaction.guild ? interaction.guild.id : 0),
+ 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 ? interaction.guild.id : 0),
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),
+ label: l("Wrong result", "Mauvais résultat", interaction.user.id, interaction.guild ? interaction.guild.id : 0),
+ 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 ? interaction.guild.id : 0),
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),
+ label: l("Wrong image(s)", "Mauvaise(s) image(s)", interaction.user.id, interaction.guild ? interaction.guild.id : 0),
+ 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 ? interaction.guild.id : 0),
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),
+ label: l("Wrong information", "Information erronée", interaction.user.id, interaction.guild ? interaction.guild.id : 0),
+ 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 ? interaction.guild.id : 0),
value: 'report.issue.missinfo|' + keys[1],
},
{
- label: l("Translation issue", "Problème de traduction", interaction.user.id, interaction.guild.id),
- description: l("The English translation of a formerly French content is wrong and needs to be fixed.", "La version française d'un contenu originellement en anglais est erronée et doit être corrigée.", interaction.user.id, interaction.guild.id),
+ label: l("Translation issue", "Problème de traduction", interaction.user.id, interaction.guild ? interaction.guild.id : 0),
+ description: l("The English translation of a formerly French content is wrong and needs to be fixed.", "La version française d'un contenu originellement en anglais est erronée et doit être corrigée.", interaction.user.id, interaction.guild ? interaction.guild.id : 0),
value: 'report.issue.translation|' + keys[1],
},
]),
@@ -90,11 +90,11 @@ module.exports = async (interaction) => {
});
} else if (keys[0] === "pony.pixel") {
await interaction.reply({
- ephemeral: true,
+ ephemeral: interaction.guild !== null,
embeds: [
new MessageEmbed()
.setColor('#28dc46')
- .setTitle(l("Pixel Art for", "Pixel Art correspondant à", interaction.user.id, interaction.guild.id) + " \"" + keys[1] + "\"")
+ .setTitle(l("Pixel Art for", "Pixel Art correspondant à", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + " \"" + keys[1] + "\"")
],
files: [
new MessageAttachment(fs.readFileSync(getPixel(keys[1])), path.basename(getPixel(keys[1])))
@@ -104,20 +104,22 @@ module.exports = async (interaction) => {
.addComponents(
new MessageButton()
.setCustomId("result.report|" + getPixel(keys[1]))
- .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild.id))
+ .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0))
.setStyle("DANGER")
)
]
});
} else if (keys[0] === "result.suggest") {
- fs.writeFileSync("./reports/Telemetry-Request-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt", "-------------------------\nPonyfind Telemetry Report\n-------------------------\n\nReport Type:\n Pony Request Report\n\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 -");
+ tid = "./reports/Telemetry-Request-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt";
+ fs.writeFileSync(tid, "-------------------------\nPonyfind Telemetry Report\n-------------------------\n\nReport Type:\n Pony Request Report\n\n-------------------------\n\nReporter:\n " + interaction.user.tag + " (" + interaction.user.id + ")\n\nServer:\n " + interaction.guild ? interaction.guild.name : "[Direct Messages]" + " (" + interaction.guild ? interaction.guild.id : 0 + ")\n\nChannel:\n " + (interaction.channel ? interaction.channel.name : "[Direct Messages]") + " (" + (interaction.channel ? interaction.channel.id : 0) + ")\n\nItem:\n " + keys[1] + "\n\nReport Type:\n -");
await interaction.reply({
- ephemeral: true,
+ ephemeral: interaction.guild !== null,
embeds: [
new MessageEmbed()
.setColor('#28dc46')
- .setTitle(l("Thanks for suggesting", "Merci d'avoir proposé", interaction.user.id, interaction.guild.id) + " \"" + keys[1] + "\"" + l("!", " !", interaction.user.id, interaction.guild.id))
- .setDescription(l("Your suggestion has been sent to the developers. They can contact you later if your settings allow this to ask you more about your request.\nThanks for your help!", "Votre suggestion a bien été envoyée aux développeurs. Ils pourront vous recontacter si vos paramètres le permettent afin de vous poser plus de questions sur votre requête.\nMerci d'aider à améliorer notre système !", interaction.user.id, interaction.guild.id))
+ .setTitle(l("Thanks for suggesting", "Merci d'avoir proposé", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + " \"" + keys[1] + "\"" + l("!", " !", interaction.user.id, interaction.guild ? interaction.guild.id : 0))
+ .setDescription(l("Your suggestion has been sent to the developers. They can contact you later if your settings allow this to ask you more about your request.\nThanks for your help!", "Votre suggestion a bien été envoyée aux développeurs. Ils pourront vous recontacter si vos paramètres le permettent afin de vous poser plus de questions sur votre requête.\nMerci d'aider à améliorer notre système !", interaction.user.id, interaction.guild ? interaction.guild.id : 0))
+ .setFooter("Ticket ID: " + tid)
]
});
} else {
diff --git a/handler/command.js b/handler/command.js
index 37b3b41..d263204 100644
--- a/handler/command.js
+++ b/handler/command.js
@@ -1,7 +1,8 @@
const fs = require('fs');
const { MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require('discord.js');
-const admin = fs.readFileSync("./config/admin.txt");
+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');
@@ -39,12 +40,43 @@ function secondsToPretty(seconds) {
}
module.exports = async (interaction) => {
- if (interaction.commandName === 'stats') {
+ 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")
+ )
+ ]
+ });
+ }
+
+ if (interaction.commandName === 'info') {
let suffix = "";
- if (official.includes(interaction.guild.id)) {
- suffix = ".official-" + interaction.guild.id;
+ if (official.includes(interaction.guild ? interaction.guild.id : 0)) {
+ suffix = ".official-" + (interaction.guild ? interaction.guild.id : 0);
} else {
- if (interaction.guild.id === fpserver) {
+ if ((interaction.guild ? interaction.guild.id : 0) === fpserver) {
suffix = ".francoponies-epk" + fs.readFileSync("./config/fpexperience.txt").toString();
}
}
@@ -54,144 +86,225 @@ module.exports = async (interaction) => {
let sizep = bytesToPretty(size);
let fields = [
- { name: l("Software version", "Version du logiciel", interaction.user.id, interaction.guild.id), value: "v" + fs.readFileSync("./config/version.txt") + "." + fs.readFileSync("./.git/refs/heads/trunk").toString().substr(0, 8) + suffix, inline: false },
- { name: l("Kernel version", "Version du noyau", interaction.user.id, interaction.guild.id), value: process.version, inline: true },
- { name: l("Experience channel", "Canal d'expériences", interaction.user.id, interaction.guild.id), value: channel, inline: true },
- { name: l("Known ponies", "Poneys connus", interaction.user.id, interaction.guild.id), 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.id), value: fs.readdirSync("./reports").length.toString(), inline: true },
- { name: l("Database size", "Taille de la base de données", interaction.user.id, interaction.guild.id), value: sizep, inline: true },
- { name: l("Memory usage", "Utilisation de la mémoire", interaction.user.id, interaction.guild.id), 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.id), value: secondsToPretty(process.uptime()), inline: true },
+ { 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 },
];
await interaction.reply({
- ephemeral: true,
+ ephemeral: interaction.guild !== null,
embeds: [
new MessageEmbed()
.setColor('#d6dc28')
- .setTitle(l("Bot stats", "Statistiques du robot", interaction.user.id, interaction.guild.id))
- .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.id))
+ .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.id))
- .setThumbnail(client.user.avatarURL())
- ],
- components: [
- new MessageActionRow()
- .addComponents(
- new MessageButton()
- .setURL(fs.readFileSync("./config/source.txt").toString())
- .setLabel(l("Browse source code", "Explorer le code source", interaction.user.id, interaction.guild.id))
- .setStyle("LINK"),
- new MessageButton()
- .setURL(fs.readFileSync("./config/invite.txt").toString())
- .setLabel(l("Invite to your server", "Inviter sur votre serveur", interaction.user.id, interaction.guild.id))
- .setStyle("LINK"),
- )
+ .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 === '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.id] !== "undefined") {
- if (lang === "fr") {
- await interaction.reply({
- ephemeral: true,
- 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: true,
- 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: true,
- 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') {
- if (!interaction.guild.members.resolve(interaction.user).permissions.has("MANAGE_SERVER") || interaction.user.id === admin) {
+ if (interaction.commandName === 'eval') {
+ if (interaction.user.id !== admin) {
await interaction.reply({
- ephemeral: true,
+ ephemeral: interaction.guild !== null,
embeds: [
new MessageEmbed()
.setColor('#dc2828')
- .setTitle(l("Permission denied", "Accès refusé", interaction.user.id, interaction.guild.id))
- .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.id))
+ .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;
}
- 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("./user/servers.json", JSON.stringify(servers, null, 4));
- if (lang === "en" || lang === "fr") {
+ try {
await interaction.reply({
- ephemeral: true,
+ 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.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))
+ .setTitle("JavaScript")
+ .setDescription("```\n" + await eval(interaction.options.getString("code")).toString().replace(/`/g, "\\`") + "\n```")
]
});
- } else {
+ } catch (e) {
await interaction.reply({
- ephemeral: true,
+ 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.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))
+ .setColor('#dc2828')
+ .setTitle("JavaScript")
+ .setDescription("```\n" + e.stack + "\n```")
]
});
}
}
+ 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))
+ ]
+ });
+ }
+ }
+ }
+
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) {
+ if (result.results.length > 0 && getEmbed(result.results[0], interaction.user.id, interaction.guild ? interaction.guild.id : 0) !== false) {
await interaction.reply({
- ephemeral: true,
+ ephemeral: interaction.guild !== null,
embeds: [
new MessageEmbed()
.setColor('#d6dc28')
- .setTitle(l("Results for", "Résultats pour", interaction.user.id, interaction.guild.id) + " \"" + 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.id))
+ .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()
@@ -210,30 +323,30 @@ module.exports = async (interaction) => {
.setStyle("PRIMARY"),
new MessageButton()
.setCustomId("result.report|" + query)
- .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild.id))
+ .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: true,
+ ephemeral: interaction.guild !== null,
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))
+ .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.id))
+ .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.id))
+ .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0))
.setStyle("DANGER")
)
]
diff --git a/handler/errors.js b/handler/errors.js
index c816369..44c216b 100644
--- a/handler/errors.js
+++ b/handler/errors.js
@@ -3,43 +3,51 @@ const { MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = req
module.exports = async (interaction, e) => {
console.error(e);
- fs.writeFileSync("./reports/Telemetry-Crash-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt", "-------------------------\nPonyfind Telemetry Report\n-------------------------\n\nReport Type:\n System Crash Report\n\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 -\n\nReport Type:\n Automated Error Report\n\n-------------------------\n\n" + e.stack)
+ tid = "./reports/Telemetry-Crash-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt";
+ fs.writeFileSync(tid, "-------------------------\nPonyfind Telemetry Report\n-------------------------\n\nReport Type:\n System Crash Report\n\n-------------------------\n\nReporter:\n " + interaction.user.tag + " (" + interaction.user.id + ")\n\nServer:\n " + (interaction.guild ? interaction.guild.name : "[Direct Messages]") + " (" + (interaction.guild ? interaction.guild.id : 0) + ")\n\nChannel:\n " + (interaction.channel ? interaction.channel.name : "[Direct Messages]") + " (" + (interaction.channel ? interaction.channel.id : 0) + ")\n\nItem:\n -\n\nReport Type:\n Automated Error Report\n\n-------------------------\n\n" + e.stack)
try {
await interaction.reply({
- ephemeral: true,
+ ephemeral: interaction.guild !== null,
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))
+ .setTitle(l("An internal exception occurred", "Une erreur interne s'est produite", interaction.user.id, interaction.guild ? interaction.guild.id : 0))
+ .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 ? interaction.guild.id : 0))
+ .setFooter("Ticket ID: " + tid)
]
});
} catch (e2) {
- fs.writeFileSync("./reports/Telemetry-Crash-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt", "-------------------------\nPonyfind Telemetry Report\n-------------------------\n\nReport Type:\n System Crash Report\n\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 -\n\nReport Type:\n Automated Error Report (chained with " + e.message + ")\n\n-------------------------\n\n" + e2.stack)
+ tid = "./reports/Telemetry-Crash-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt";
+ fs.writeFileSync(tid, "-------------------------\nPonyfind Telemetry Report\n-------------------------\n\nReport Type:\n System Crash Report\n\n-------------------------\n\nReporter:\n " + interaction.user.tag + " (" + interaction.user.id + ")\n\nServer:\n " + (interaction.guild ? interaction.guild.name : "[Direct Messages]") + " (" + (interaction.guild ? interaction.guild.id : 0) + ")\n\nChannel:\n " + (interaction.channel ? interaction.channel.name : "[Direct Messages]") + " (" + (interaction.channel ? interaction.channel.id : 0) + ")\n\nItem:\n -\n\nReport Type:\n Automated Error Report (chained with " + e.message + ")\n\n-------------------------\n\n" + e2.stack)
try {
await interaction.reply({
- ephemeral: true,
+ ephemeral: interaction.guild !== null,
embeds: [
new MessageEmbed()
.setColor('#dc2828')
.setTitle("2 internal exceptions occurred")
.setDescription("That's not your fault! The developers have already been informed about the issue and will resolve it as soon as possible. We additionally weren't able to deliver you a localized error message.")
+ .setFooter("Ticket ID: " + tid)
]
});
} catch (e3) {
- fs.writeFileSync("./reports/Telemetry-Crash-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt", "-------------------------\nPonyfind Telemetry Report\n-------------------------\n\nReport Type:\n System Crash Report\n\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 -\n\nReport Type:\n Automated Error Report (chained with " + e.message + " and " + e2.message + ")\n\n-------------------------\n\n" + e3.stack)
+ tid = "./reports/Telemetry-Crash-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt";
+ fs.writeFileSync(tid, "-------------------------\nPonyfind Telemetry Report\n-------------------------\n\nReport Type:\n System Crash Report\n\n-------------------------\n\nReporter:\n " + interaction.user.tag + " (" + interaction.user.id + ")\n\nServer:\n " + (interaction.guild ? interaction.guild.name : "[Direct Messages]") + " (" + (interaction.guild ? interaction.guild.id : 0) + ")\n\nChannel:\n " + (interaction.channel ? interaction.channel.name : "[Direct Messages]") + " (" + (interaction.channel ? interaction.channel.id : 0) + ")\n\nItem:\n -\n\nReport Type:\n Automated Error Report (chained with " + e.message + " and " + e2.message + ")\n\n-------------------------\n\n" + e3.stack)
try {
interaction.channel.send({embeds: [new MessageEmbed()
.setColor('#dc2828')
.setTitle("3 internal exceptions occurred")
.setDescription("That's not your fault! The developers have already been informed about the issue and will resolve it as soon as possible. We additionally weren't able to deliver you a localized error message and/or through a reply to your command.")]
+ .setFooter("Ticket ID: " + tid)
}).catch((e4) => {
- fs.writeFileSync("./reports/Telemetry-Crash-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt", "-------------------------\nPonyfind Telemetry Report\n-------------------------\n\nReport Type:\n System Crash Report\n\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 -\n\nReport Type:\n Automated Error Report (chained with " + e.message + ", " + e2.message + " and " + e3.message + ")\n\n-------------------------\n\n" + e4.stack)
+ tid = "./reports/Telemetry-Crash-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt";
+ fs.writeFileSync(tid, "-------------------------\nPonyfind Telemetry Report\n-------------------------\n\nReport Type:\n System Crash Report\n\n-------------------------\n\nReporter:\n " + interaction.user.tag + " (" + interaction.user.id + ")\n\nServer:\n " + (interaction.guild ? interaction.guild.name : "[Direct Messages]") + " (" + (interaction.guild ? interaction.guild.id : 0) + ")\n\nChannel:\n " + (interaction.channel ? interaction.channel.name : "[Direct Messages]") + " (" + (interaction.channel ? interaction.channel.id : 0) + ")\n\nItem:\n -\n\nReport Type:\n Automated Error Report (chained with " + e.message + ", " + e2.message + " and " + e3.message + ")\n\n-------------------------\n\n" + e4.stack)
interaction.user.send({
embeds: [new MessageEmbed()
.setColor('#dc2828')
.setTitle("4 internal exceptions occurred")
.setDescription("That's not your fault! The developers have already been informed about the issue and will resolve it as soon as possible. We additionally weren't able to deliver you a localized error message, through a reply to your command and/or through the channel you initially executed the command.")]
+ .setFooter("Ticket ID: " + tid)
})
})
} catch (e) {}
diff --git a/handler/menu.js b/handler/menu.js
index 519aef6..4b0f313 100644
--- a/handler/menu.js
+++ b/handler/menu.js
@@ -6,14 +6,16 @@ module.exports = async (interaction) => {
if (keys[0].startsWith("report.issue.")) {
item = keys[0].substr(13)
- fs.writeFileSync("./reports/Telemetry-Pony-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt", "-------------------------\nPonyfind Telemetry Report\n-------------------------\n\nReport Type:\n Pony Issue Report\n\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)
+ tid = "./reports/Telemetry-Pony-" + (new Date().toISOString().replace(/[^a-zA-Z0-9]/gm, "-")) + ".txt";
+ fs.writeFileSync(tid, "-------------------------\nPonyfind Telemetry Report\n-------------------------\n\nReport Type:\n Pony Issue Report\n\n-------------------------\n\nReporter:\n " + interaction.user.tag + " (" + interaction.user.id + ")\n\nServer:\n " + (interaction.guild ? interaction.guild.name : "[Direct Messages]") + " (" + (interaction.guild ? interaction.guild.id : 0) + ")\n\nChannel:\n " + (interaction.channel ? interaction.channel.name : "[Direct Messages]") + " (" + (interaction.channel ? interaction.channel.id : 0) + ")\n\nItem:\n " + keys[1] + "\n\nReport Type:\n " + item)
await interaction.reply({
- ephemeral: true,
+ ephemeral: interaction.guild !== null,
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))
+ .setTitle(l("Thanks for reporting an issue with", "Merci d'avoir signalé un problème avec", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + " \"" + keys[1] + "\"" + l("!", " !", interaction.user.id, interaction.guild ? interaction.guild.id : 0))
+ .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 ? interaction.guild.id : 0))
+ .setFooter("Ticket ID: " + tid)
]
});
} else {
diff --git a/index.js b/index.js
index c877049..8cf19a2 100644
--- a/index.js
+++ b/index.js
@@ -1,96 +1,9 @@
-// Stable: https://discord.com/oauth2/authorize?client_id=928695013083316295&scope=bot%20applications.commands&permissions=0
-// Beta: https://discord.com/oauth2/authorize?client_id=929057534491361341&scope=bot%20applications.commands&permissions=0
+global.channel = (require('fs').existsSync("./beta") ? "beta" : "stable");
+const { ShardingManager } = require('discord.js');
+const fs = require("fs");
-console.log("Channel: " + (typeof process.argv[2] !== "undefined" ? "beta" : "stable"));
-global.channel = (typeof process.argv[2] !== "undefined" ? "beta" : "stable");
+const manager = new ShardingManager('./bot.js', { token: fs.readFileSync("./config/token." + (require('fs').existsSync("./beta") ? "beta" : "stable") + ".txt").toString() });
-const fs = require('fs');
-const { REST } = require('@discordjs/rest');
-const { Routes } = require('discord-api-types/v9');
+manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
-if (!fs.existsSync("./user/userdata.json")) fs.writeFileSync("./user/userdata.json", "{}");
-if (!fs.existsSync("./user/servers.json")) fs.writeFileSync("./user/servers.json", "{}");
-if (!fs.existsSync("./reports")) fs.mkdirSync("./reports");
-
-const rest = new REST({ version: '9' }).setToken(fs.readFileSync("./config/token." + (typeof process.argv[2] !== "undefined" ? "beta" : "stable") + ".txt").toString());
-const { Client, Intents, MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed } = require('discord.js');
-global.client = new Client({ intents: [Intents.FLAGS.GUILDS] });
-
-const commandHandler = require('./handler/command');
-const buttonHandler = require('./handler/button');
-const menuHandler = require('./handler/menu');
-const errorHandler = require('./handler/errors');
-
-global.langs = JSON.parse(fs.readFileSync("./user/userdata.json"));
-global.servers = JSON.parse(fs.readFileSync("./user/servers.json"));
-
-global.l = (en, fr, id, gid) => {
- if (typeof servers[gid] !== "undefined") {
- if (servers[gid] === "fr") {
- return fr;
- } else {
- return en;
- }
- } else {
- if (langs[id] === "fr") {
- return fr;
- } else {
- return en;
- }
- }
-}
-
-const commands = require('./modules/registers');
-
-client.on('ready', async () => {
- console.log(`Logged in as ${client.user.tag}!`);
- for (let guild of client.guilds.cache.map(g => g.id)) {
- try {
- console.log('Started refreshing application (/) commands for guild ' + guild + '.');
-
- await rest.put(
- Routes.applicationGuildCommands(fs.readFileSync("./config/client." + (typeof process.argv[2] !== "undefined" ? "beta" : "stable") + ".txt").toString(), guild),
- { body: commands },
- );
-
- console.log('Successfully reloaded application (/) commands for guild ' + guild + '.');
- } catch (error) {
- console.error(error);
- }
- }
-});
-
-client.on('guildCreate', async () => {
- for (let guild of client.guilds.cache.map(g => g.id)) {
- try {
- console.log('Started refreshing application (/) commands for guild ' + guild + '.');
-
- await rest.put(
- Routes.applicationGuildCommands(fs.readFileSync("./config/client." + (typeof process.argv[2] !== "undefined" ? "beta" : "stable") + ".txt").toString(), guild),
- { body: commands },
- );
-
- console.log('Successfully reloaded application (/) commands for guild ' + guild + '.');
- } catch (error) {
- console.error(error);
- }
- }
-})
-
-client.on('interactionCreate', async interaction => {
- try {
- 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) {
- errorHandler(interaction, e)
- }
-});
-
-client.login(fs.readFileSync("./config/token." + (typeof process.argv[2] !== "undefined" ? "beta" : "stable") + ".txt").toString()); \ No newline at end of file
+manager.spawn(); \ No newline at end of file
diff --git a/modules/embed.js b/modules/embed.js
index 9c2ab0a..dd846fe 100644
--- a/modules/embed.js
+++ b/modules/embed.js
@@ -173,18 +173,30 @@ module.exports = (page, id, gid) => {
}
}
+ let fields = [
+ { 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 },
+ ];
+
+ if (spoils[id] === 1) {
+ fields.push(
+ { 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 }
+ )
+ } else if (spoils[id] === 2) {
+ fields.push(
+ { name: l("Occupation(s)", "Occupation(s)", id, gid), value: jobs, inline: true },
+ { name: l("Home(s)", "Résidence(s)", id, gid), value: location, inline: true }
+ )
+ }
+
return new MessageEmbed()
.setColor(d.color.length === 6 ? d.color : "ffffff")
.setTitle(page + " " + sign)
.setDescription(l(d.extract, d.extract_fr, id, gid))
.setImage(d.image)
.setThumbnail(d.mark)
- .addFields([
- { 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 }
- ])
+ .addFields(fields)
.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/modules/registers.js b/modules/registers.js
index f99e274..a1cf4b5 100644
--- a/modules/registers.js
+++ b/modules/registers.js
@@ -10,27 +10,76 @@ module.exports = [
.setRequired(true)
),
new SlashCommandBuilder()
- .setName('stats')
- .setDescription("Gets stats about the bot"),
- new SlashCommandBuilder()
- .setName('lang')
- .setDescription("Changes the bot's language")
+ .setName('eval')
+ .setDescription("Run raw JavaScript code on the bot's server")
.addStringOption(option =>
- option.setName('locale')
- .setDescription('The selected language')
+ option.setName("code")
+ .setDescription("The JavaScript code to run")
.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')
+ .setName('info')
+ .setDescription("Gets stats and info about the bot"),
+ new SlashCommandBuilder()
+ .setName('random')
+ .setDescription("Picks a random pony"),
+ // 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('config')
+ .setDescription("Configure all aspects of the bot")
+ .addSubcommand(subcommand =>
+ subcommand.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')
+ )
+ )
+ .addSubcommand(subcommand =>
+ subcommand.setName('spoilers')
+ .setDescription("Enable, disable or hide spoilers in replies")
+ .addStringOption(option =>
+ option.setName('status')
+ .setDescription('Value')
+ .setRequired(true)
+ .addChoice('Always show spoilers', 'yes')
+ .addChoice('Show under spoiler tags (default)', 'hide')
+ .addChoice('Never show spoilers', 'no')
+ )
)
+ .addSubcommand(subcommand =>
+ subcommand.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')
+ )
+ ),
+ // 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/modules/result.js b/modules/result.js
index 3f94ebb..42419ec 100644
--- a/modules/result.js
+++ b/modules/result.js
@@ -1,4 +1,5 @@
const db = require('../data/search.json').associations;
+const list = Object.keys(require('../data/data.json'));
const Fuse = require('fuse.js');
module.exports = (query) => {
@@ -25,7 +26,7 @@ module.exports = (query) => {
findex = 0;
for (let result of fuse.search(query)) {
- if (!first.includes(result.item.endpoint) && findex < 3) {
+ if (!first.includes(result.item.endpoint) && findex < 3 && list.includes(result.item.endpoint)) {
first[findex] = result.item.endpoint
findex++
}
diff --git a/update/infobox.js b/update/infobox.js
index b9d2591..faaf943 100644
--- a/update/infobox.js
+++ b/update/infobox.js
@@ -14,7 +14,7 @@ console.log("Gathering infobox for each page...");
let mwextracts = (await axios.get("https://mlp.fandom.com/api.php?format=json&action=query&prop=extracts&exlimit=max&explaintext&exintro&titles=" + encodeURI(page.name) + "&redirects=")).data;
let extracts = "";
try {
- extracts = mwextracts.query.pages[Object.keys(mwextracts.query.pages)[0]].extract.replace(/(.*)\n\n(.*)/gm, "$2").replace(/([.?!])\s*(?=[A-Z])/g, "$1|").split("|")[0];
+ extracts = mwextracts.query.pages[Object.keys(mwextracts.query.pages)[0]].extract.replace(/(.*)\n(.*)/, "$2").replace(/(.*)\n\n(.*)/gm, "$2").replace(/([.?!])\s*(?=[A-Z])/g, "$1|").split("|")[0];
} catch (e) {
extracts = "";
}
diff --git a/update/parse.js b/update/parse.js
index 6f4ee3a..217cfd8 100644
--- a/update/parse.js
+++ b/update/parse.js
@@ -22,13 +22,13 @@ let ponies = {};
mark: "https://example.com"
}
- if (typeof box.name2 !== "undefined") data.names.push(box.name2);
- if (typeof box.name3 !== "undefined") data.names.push(box.name3);
- if (typeof box.name4 !== "undefined") data.names.push(box.name4);
- if (typeof box.name5 !== "undefined") data.names.push(box.name5);
+ if (typeof box.name2 !== "undefined") data.names.push(box.name2.replace(/<!--[\s\S]*?-->/g, ""));
+ if (typeof box.name3 !== "undefined") data.names.push(box.name3.replace(/<!--[\s\S]*?-->/g, ""));
+ if (typeof box.name4 !== "undefined") data.names.push(box.name4.replace(/<!--[\s\S]*?-->/g, ""));
+ if (typeof box.name5 !== "undefined") data.names.push(box.name5.replace(/<!--[\s\S]*?-->/g, ""));
if (typeof box.nicknames !== "undefined") {
- box.nicknames.split(",").filter(e => !e.match(/[^a-zA-Z0-9-_ ]/gm)).forEach((e, i) => {
+ box.nicknames.replace(/<!--[\s\S]*?-->/g, "").split(",").filter(e => !e.match(/[^a-zA-Z0-9-_ ]/gm)).forEach((e, i) => {
data.names.push(e.trim());
});
}
@@ -37,7 +37,7 @@ let ponies = {};
kp = box.kind.replace(/<!--[\s\S]*?-->/g, "").replace(/[^a-zA-Z0-9-_ ]/gm, "").split(" ")[0];
data.kind = kp.substr(kp.replace(/([A-Z])([a-z0-9]*)$/g, "").length);
}
- if (typeof box.sex !== "undefined") data.sex = box.sex.startsWith("F") ? "F" : "M";
+ if (typeof box.sex !== "undefined") data.sex = box.sex.replace(/<!--[\s\S]*?-->/g, "").trim().startsWith("F") ? "F" : "M";
if (typeof box._extract !== "undefined") {
data.extract = box._extract;
}
@@ -46,29 +46,29 @@ let ponies = {};
} else {
data.extract_fr = data.extract;
}
- if (typeof box.coat !== "undefined") data.color = box.coat.replace(/\[(.*)\/(.{6})\/ (.*)\]/gm, "$2").replace(/{{perbang\|([0-9A-Fa-f].{5})(.*)/g, "$1");
- if (typeof box.main !== "undefined") data.image = "https://mlp.fandom.com/Special:FilePath/" + encodeURI(box.main);
- if (typeof box.main1 !== "undefined") data.image = "https://mlp.fandom.com/Special:FilePath/" + encodeURI(box.main1);
- if (typeof box.image !== "undefined") data.image = "https://mlp.fandom.com/Special:FilePath/" + encodeURI(box.image);
+ if (typeof box.coat !== "undefined") data.color = box.coat.replace(/<!--[\s\S]*?-->/g, "").trim().replace(/\[(.*)\/(.{6})\/ (.*)\]/gm, "$2").replace(/{{perbang\|([0-9A-Fa-f].{5})(.*)/g, "$1");
+ if (typeof box.main !== "undefined") data.image = "https://mlp.fandom.com/Special:FilePath/" + encodeURI(box.main.replace(/<!--[\s\S]*?-->/g, "").trim());
+ if (typeof box.main1 !== "undefined") data.image = "https://mlp.fandom.com/Special:FilePath/" + encodeURI(box.main1.replace(/<!--[\s\S]*?-->/g, "").trim());
+ if (typeof box.image !== "undefined") data.image = "https://mlp.fandom.com/Special:FilePath/" + encodeURI(box.image.replace(/<!--[\s\S]*?-->/g, "").trim());
if (typeof box["cutie mark"] !== "undefined") {
try {
- data.markimg = box["cutie mark"].split("[[File:")[1].split("|")[0];
+ data.markimg = box["cutie mark"].replace(/<!--[\s\S]*?-->/g, "").trim().split("[[File:")[1].split("|")[0];
} catch (e) {
- data.markimg = box["cutie mark"].split("[[File:")[0].split("|")[0];
+ data.markimg = box["cutie mark"].replace(/<!--[\s\S]*?-->/g, "").trim().split("[[File:")[0].split("|")[0];
}
data.mark = "https://mlp.fandom.com/Special:Redirect/file/" + encodeURI(data.markimg) + "?width=128";
}
if (typeof box.occupation !== "undefined") {
occupations = [];
- box.occupation/*.replace(/\[\[(.*)_(.*)\]\]|\[\[(.*)\|(.*)\]\]|\[\[(.*)\]\]/gm, "$2$4$5")*/.replace(/\|/gm, "_").replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "|").replace(/( \|| \| | \| )/gm, "|").split("|").forEach((e) => {
+ box.occupation/*.replace(/\[\[(.*)_(.*)\]\]|\[\[(.*)\|(.*)\]\]|\[\[(.*)\]\]/gm, "$2$4$5")*/.replace(/<!--[\s\S]*?-->/g, "").trim().replace(/\|/gm, "_").replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "|").replace(/( \|| \| | \| )/gm, "|").split("|").forEach((e) => {
occupations.push(e.trim().replace(/[\[\]]/gm, "").replace(/<(.*)>/gm, "").replace(/([a-zA-Z0-9 \-_,.'"]*)_([a-zA-Z0-9 \-_,.'"]*)/gm, "$2"));
})
data.occupation = occupations;
}
if (typeof box.residence !== "undefined") {
residences = [];
- box.residence/*.replace(/\[\[(.*)_(.*)\]\]|\[\[(.*)\|(.*)\]\]|\[\[(.*)\]\]/gm, "$2$4$5")*/.replace(/\|/gm, "_").replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "|").replace(/( \|| \| | \| )/gm, "|").split("|").forEach((e) => {
+ box.residence/*.replace(/\[\[(.*)_(.*)\]\]|\[\[(.*)\|(.*)\]\]|\[\[(.*)\]\]/gm, "$2$4$5")*/.replace(/<!--[\s\S]*?-->/g, "").trim().replace(/\|/gm, "_").replace(/<( ||(|| )\/)( ||(|| )\/)(b|B)(r|R)( ||(|| )\/)( ||(|| )\/)>/gm, "|").replace(/( \|| \| | \| )/gm, "|").split("|").forEach((e) => {
residences.push(e.trim().replace(/[\[\]]/gm, "").replace(/<(.*)>/gm, "").replace(/([a-zA-Z0-9 \-_,.'"]*)_([a-zA-Z0-9 \-_,.'"]*)/gm, "$2"));
})
data.residence = residences;
diff --git a/user/spoilers.json b/user/spoilers.json
new file mode 100644
index 0000000..4aa4537
--- /dev/null
+++ b/user/spoilers.json
@@ -0,0 +1,3 @@
+{
+ "493845599469174794": 1
+} \ No newline at end of file