From 327119b4d1c2248b8a075cad3cd05ab92560e75d Mon Sep 17 00:00:00 2001 From: Minteck Date: Sun, 13 Feb 2022 16:16:18 +0100 Subject: Feature: implements #8, voids #9 --- handler/autocomplete.js | 13 +++++++++++++ handler/button.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++--- handler/command.js | 5 +++++ handler/menu.js | 2 +- 4 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 handler/autocomplete.js (limited to 'handler') diff --git a/handler/autocomplete.js b/handler/autocomplete.js new file mode 100644 index 0000000..5696ab7 --- /dev/null +++ b/handler/autocomplete.js @@ -0,0 +1,13 @@ +const getEpisodes = require('../modules/findepisode'); +const fs = require("fs"); +const episodes = JSON.parse(fs.readFileSync("./data/series.json").toString()); + +module.exports = async (interaction) => { + try { + let series = interaction.options.getSubcommand(); + + if (interaction.commandName === "episode") { + await interaction.respond(getEpisodes(episodes.filter(i => i.command.toLowerCase() === series)[0], interaction.options.getFocused())); + } + } catch (e) {} +} \ No newline at end of file diff --git a/handler/button.js b/handler/button.js index f9f283e..4a8a343 100644 --- a/handler/button.js +++ b/handler/button.js @@ -5,6 +5,8 @@ const { MessageActionRow, MessageButton, MessageSelectMenu, MessageEmbed, Messag const getPixel = require('../modules/pixel.js'); const getEmbed = require("../modules/embed"); const getPublic = require("../modules/public"); +const episodeReply = require("../modules/episodereply"); +const series = JSON.parse(fs.readFileSync("./data/series.json").toString()); module.exports = async (interaction) => { keys = interaction.customId.split("|") @@ -14,9 +16,51 @@ module.exports = async (interaction) => { } else { statsButtons[keys[0]] = 1; } - fs.writeFile("./stats/buttons.json", JSON.stringify(statsButtons), () => {}); + fs.writeFile("./stats/buttons.json", JSON.stringify(statsButtons), () => { + }); - if (keys[0] === "pony.display") { + if (keys[0] === "episode.public") { + if (typeof cooldowns[interaction.user.id] !== "undefined" && new Date() - cooldowns[interaction.user.id] < 30000) { + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#dc2828') + .setTitle(l("Calm down!", "Calmez-vous !", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("Please wait " + Math.ceil((30000 - (new Date() - cooldowns[interaction.user.id]))/1000) + " seconds before you can use this again.", "Patientez encore " + Math.ceil((30000 - (new Date() - cooldowns[interaction.user.id]))/1000) + " secondes avant de pouvoir réutiliser ça.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + } else { + try { + let select = keys[1]; + let episode = keys[2].toLowerCase(); + + let sdata = series.filter(i => i.command.toLowerCase() === select)[0]; + await episodeReply(interaction, select, episode, sdata, true); + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#28dc46') + .setTitle(l("Show to everypony", "Afficher à tous", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("This episode has been sent publicly to this channel.", "Cet épisode a été envoyé publiquement dans ce salon.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + cooldowns[interaction.user.id] = new Date(); + } catch (e) { + console.error(e); + await interaction.reply({ + ephemeral: interaction.guild !== null, + embeds: [ + new MessageEmbed() + .setColor('#dc2828') + .setTitle(l("Show to everypony", "Afficher à tous", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("We are unable to send a message to this channel, make sure the bot have sufficient permissions.", "Nous ne parvenons pas à envoyer un message dans ce salon, assurez-vous que le robot dispose de sufficient de permissions.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + ] + }); + } + } + } else if (keys[0] === "pony.display") { let row; if (statsPonies[keys[1]] !== undefined) { statsPonies[keys[1]]++; @@ -123,7 +167,7 @@ module.exports = async (interaction) => { new MessageEmbed() .setColor('#dc2828') .setTitle(l("Show to everypony", "Afficher à tous", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) - .setDescription(l("We are unable to send a message to this channel, make sure the bot have sufficient permissions.", "Nous ne parvenons pas à envoyer un message dans ce salon, assurez-vous que le robot dispose de sufficient de permissions.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setDescription(l("We are unable to send a message to this channel, make sure the bot have sufficient permissions.", "Nous ne parvenons pas à envoyer un message dans ce salon, assurez-vous que le robot dispose de suffisamment de permissions.", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) ] }); } diff --git a/handler/command.js b/handler/command.js index c1957ae..9733e6c 100644 --- a/handler/command.js +++ b/handler/command.js @@ -16,6 +16,7 @@ const commandInfo = require('../commands/info'); const commandEval = require('../commands/eval'); const commandConfig = require('../commands/config'); const commandPony = require('../commands/pony'); +const commandEpisode = require('../commands/episode'); const commandHelp = require('../commands/help'); module.exports = async (interaction) => { @@ -85,4 +86,8 @@ module.exports = async (interaction) => { if (interaction.commandName === 'pony') { await commandPony(interaction); } + + if (interaction.commandName === 'episode') { + await commandEpisode(interaction); + } } \ No newline at end of file diff --git a/handler/menu.js b/handler/menu.js index 1102b9e..f4cc3bc 100644 --- a/handler/menu.js +++ b/handler/menu.js @@ -12,7 +12,7 @@ module.exports = async (interaction) => { fs.writeFile("./stats/menu.json", JSON.stringify(statsMenu), () => {}); if (keys[0].startsWith("report.issue.")) { - item = keys[0].substr(13) + item = keys[0].substring(13) 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({ -- cgit