diff options
author | Minteck <contact@minteck.org> | 2022-02-13 16:16:18 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-02-13 16:16:18 +0100 |
commit | 327119b4d1c2248b8a075cad3cd05ab92560e75d (patch) | |
tree | ce143399e74c120f7311e75490efd0defd9b58d8 /modules/episodereply.js | |
parent | ede8d0750f3f16e3ba5c3c3f716c98d267512b09 (diff) | |
download | ponyfind-327119b4d1c2248b8a075cad3cd05ab92560e75d.tar.gz ponyfind-327119b4d1c2248b8a075cad3cd05ab92560e75d.tar.bz2 ponyfind-327119b4d1c2248b8a075cad3cd05ab92560e75d.zip |
Feature: implements #8, voids #9
Diffstat (limited to 'modules/episodereply.js')
-rw-r--r-- | modules/episodereply.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/modules/episodereply.js b/modules/episodereply.js new file mode 100644 index 0000000..79a05c1 --- /dev/null +++ b/modules/episodereply.js @@ -0,0 +1,75 @@ +const { MessageActionRow, MessageButton, MessageEmbed } = require("discord.js"); +const getEpisodePublic = require("./episodepublic"); +const fs = require("fs"); + +module.exports = async (interaction, series, episode, sdata, isPublic) => { + let sid = episode.split("-")[0]; + let spt = sid.substring(1); + let eid = episode.split("-")[1]; + let edata = sdata.seasons.filter(i => i.id === sid)[0].episodes.filter(i => i.local - 1 + 1 === eid - 1 + 1)[0]; + + let fields = [ + { name: l("Airing Date", "Date de diffusion", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: edata.date_pre, inline: true }, + { name: l("Written by", "Écrit par", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: edata.writer, inline: true }, + { name: l("Overall no.", "N° global", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: edata.global + "/" + sdata.seasons.map(i => { return i.count }).reduce((a, b) => { return a + b; }), inline: true }, + { name: l("Season no.", "N° dans la saison", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: edata.local + "/" + sdata.seasons.filter(i => i.id === sid)[0].count, inline: true }, + ] + + if (edata.characters.length > 0) { + fields.push({ name: l("Characters", "Personnages", interaction.user.id, interaction.guild ? interaction.guild.id : 0), value: edata.characters.join("\n"), inline: true }); + } + + let row; + if (interaction.guild && !isPublic) { + row = new MessageActionRow() + .addComponents( + getEpisodePublic(interaction, series, episode), + 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(edata.name)), + new MessageButton() + .setCustomId("result.report|" + edata.name) + .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("DANGER") + ) + } else { + row = new MessageActionRow() + .addComponents( + new MessageButton() + .setLabel(l("Read More", "Lire plus", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("LINK") + .setURL("https://mlp.fandom.com/wiki/" + encodeURI(edata.name)), + new MessageButton() + .setCustomId("result.report|" + edata.name) + .setLabel(l("Report an issue", "Signaler un problème", interaction.user.id, interaction.guild ? interaction.guild.id : 0)) + .setStyle("DANGER") + ) + } + + let reply = { + embeds: [ + new MessageEmbed() + .setColor("DEFAULT") + .setAuthor({ name: l("Season", "Saison", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + " " + spt + " " + l("Episode", "Épisode", interaction.user.id, interaction.guild ? interaction.guild.id : 0) + " " + eid }) + .setTitle(edata.name) + .setDescription(edata.plot) + .setImage(edata.cover) + .addFields(fields) + .setFooter({ text: l("Content provided without warranty, use at your own risk.", "Contenu fourni sans aucune garantie, utilisez à vos risques et périls", interaction.user.id, interaction.guild ? interaction.guild.id : 0) }) + ], + components: [ + row + ] + }; + + if (!isPublic) { + reply.ephemeral = interaction.guild !== null; + } + + if (isPublic) { + await interaction.channel.send(reply); + } else { + await interaction.reply(reply); + } +}
\ No newline at end of file |