From a5f0232ca63da84dfeda27f26f3c4432b40b4e61 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 05:00:19 +0200 Subject: [PATCH 01/29] =?UTF-8?q?Cr=C3=A9ation=20de=20la=20structure=20des?= =?UTF-8?q?=20dossiers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- global/buttons/.gitignore | 0 global/contextMenus/.gitignore | 0 global/events/.gitignore | 0 global/selectMenus/.gitignore | 0 global/slashs/.gitignore | 0 iut_nc_depinfo/buttons/.gitignore | 0 iut_nc_depinfo/contextMenus/.gitignore | 0 iut_nc_depinfo/events/.gitignore | 0 iut_nc_depinfo/selectMenus/.gitignore | 0 iut_nc_depinfo/slashs/.gitignore | 0 10 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 global/buttons/.gitignore create mode 100644 global/contextMenus/.gitignore create mode 100644 global/events/.gitignore create mode 100644 global/selectMenus/.gitignore create mode 100644 global/slashs/.gitignore create mode 100644 iut_nc_depinfo/buttons/.gitignore create mode 100644 iut_nc_depinfo/contextMenus/.gitignore create mode 100644 iut_nc_depinfo/events/.gitignore create mode 100644 iut_nc_depinfo/selectMenus/.gitignore create mode 100644 iut_nc_depinfo/slashs/.gitignore diff --git a/global/buttons/.gitignore b/global/buttons/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/global/contextMenus/.gitignore b/global/contextMenus/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/global/events/.gitignore b/global/events/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/global/selectMenus/.gitignore b/global/selectMenus/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/global/slashs/.gitignore b/global/slashs/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/iut_nc_depinfo/buttons/.gitignore b/iut_nc_depinfo/buttons/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/iut_nc_depinfo/contextMenus/.gitignore b/iut_nc_depinfo/contextMenus/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/iut_nc_depinfo/events/.gitignore b/iut_nc_depinfo/events/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/iut_nc_depinfo/selectMenus/.gitignore b/iut_nc_depinfo/selectMenus/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/iut_nc_depinfo/slashs/.gitignore b/iut_nc_depinfo/slashs/.gitignore new file mode 100644 index 0000000..e69de29 From 9fc844c0730c515c8fb7cb0ea46b60f687060745 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 05:01:28 +0200 Subject: [PATCH 02/29] =?UTF-8?q?Extraction=20de=20fun=20pfc=20et=20l?= =?UTF-8?q?=C3=A9g=C3=A8re=20refonte=20technique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/Fun.ts | 147 ------------------------------------------ global/buttons/Pfc.ts | 23 +++++++ global/slashs/Fun.ts | 39 +++++++++++ libs/pfc.ts | 116 +++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+), 147 deletions(-) delete mode 100644 commands/Fun.ts create mode 100644 global/buttons/Pfc.ts create mode 100644 global/slashs/Fun.ts create mode 100644 libs/pfc.ts diff --git a/commands/Fun.ts b/commands/Fun.ts deleted file mode 100644 index aecbcb7..0000000 --- a/commands/Fun.ts +++ /dev/null @@ -1,147 +0,0 @@ -import { randomInt } from "crypto"; -import { ButtonInteraction, CommandInteraction, EmojiIdentifierResolvable, MessageActionRow, MessageButton, User } from "discord.js"; -import { ButtonComponent, DefaultPermission, Discord, Slash, SlashChoice, SlashGroup, SlashOption } from "discordx"; - -enum pfcChoix { - Pierre = "Pierre", - Feuille = "Feuille", - Ciseaux = "Ciseaux" -} - -enum pfcResultat { - WIN, - LOOSE, - DRAW -} - -class pfcProposition { - public static propositions = [ - new pfcProposition(pfcChoix.Pierre, 'đŸȘš', 'pfc-rock'), - new pfcProposition(pfcChoix.Feuille, 'đŸ§»', 'pfc-paper'), - new pfcProposition(pfcChoix.Ciseaux, '✂', 'pfc-scissors') - ] - - public name: pfcChoix; - public emoji: EmojiIdentifierResolvable; - public buttonCustomID: "pfc-rock" | "pfc-paper" | "pfc-scissors"; - - constructor(nom: pfcChoix, emoji: EmojiIdentifierResolvable, buttonCustomID: "pfc-rock" | "pfc-paper" | "pfc-scissors") { - this.name = nom; - this.emoji = emoji; - this.buttonCustomID = buttonCustomID; - } - - public static nameToClass(nom: string) { - return this.propositions.find(proposition => nom === proposition.name); - } - - public static buttonCustomIDToClass(buttonCustomID: string) { - return this.propositions.find(proposition => buttonCustomID === proposition.buttonCustomID); - } -} - -@Discord() -@DefaultPermission(true) -@SlashGroup("fun", "Commandes orientĂ© sur l'amusement") -abstract class Fun { - - @Slash("pfc", { description: "Quoi de plus amusant que jouer Ă  Pierre Feuille Ciseaux avec un robot ?" }) - async pfc( - @SlashChoice(pfcChoix) - @SlashOption("Choix", { description: "Que voulez-vous jouer ?" }) - choice: pfcChoix, - interaction: CommandInteraction - ) { - - if (choice) { - await interaction.deferReply({ ephemeral: true }); - - const playerChoice = pfcProposition.nameToClass(choice); - - if (!playerChoice) { interaction.editReply({ content: `Erreur, ${choice} est un choix invalide.` }); return; } - - const botChoice = Fun.pfcPlayBot(); - const result = Fun.isWin(playerChoice, botChoice); - - interaction.editReply(Fun.pfcTraitementResultat(playerChoice, botChoice, result, interaction.user)); - } else { - await interaction.deferReply(); - - const rockButton = new MessageButton() - .setLabel("Pierre") - .setEmoji('đŸȘš') - .setStyle('PRIMARY') - .setCustomId('pfc-rock'); - - const paperButton = new MessageButton() - .setLabel("Feuille") - .setEmoji('đŸ§»') - .setStyle('PRIMARY') - .setCustomId('pfc-paper'); - - const scissorButton = new MessageButton() - .setLabel("Ciseaux") - .setEmoji('✂') - .setStyle('PRIMARY') - .setCustomId('pfc-scissors'); - - const wellButton = new MessageButton() - .setLabel("Puit") - .setEmoji('❓') - .setStyle('PRIMARY') - .setCustomId('pfc-well') - .setDisabled(true); - - const buttonRow = new MessageActionRow() - .addComponents(rockButton, paperButton, scissorButton, wellButton); - - interaction.editReply({ content: "Ok let's go. 1v1 Pierre Feuille Ciseaux. Vas-y choisis !", components: [buttonRow] }); - } - } - - @ButtonComponent('pfc-rock') - @ButtonComponent('pfc-paper') - @ButtonComponent('pfc-scissors') - private async pfcButton(interaction: ButtonInteraction) { - const playerChoice = pfcProposition.buttonCustomIDToClass(interaction.customId); - - if (!playerChoice) { interaction.reply({ content: `Erreur, ${interaction.customId} est un choix invalide.`, ephemeral: true }); return; } - - const botChoice = Fun.pfcPlayBot(); - const result = Fun.isWin(playerChoice, botChoice); - - interaction.update(Fun.pfcTraitementResultat(playerChoice, botChoice, result, interaction.user)); - } - - private static isWin(playerChoice: pfcProposition, botChoice: pfcProposition): pfcResultat { - switch (playerChoice.name) { - case pfcChoix.Pierre: - if (botChoice.name === pfcChoix.Ciseaux) return pfcResultat.WIN; - if (botChoice.name === pfcChoix.Feuille) return pfcResultat.LOOSE; - return pfcResultat.DRAW; - case pfcChoix.Feuille: - if (botChoice.name === pfcChoix.Pierre) return pfcResultat.WIN; - if (botChoice.name === pfcChoix.Ciseaux) return pfcResultat.LOOSE; - return pfcResultat.DRAW; - case pfcChoix.Ciseaux: - if (botChoice.name === pfcChoix.Feuille) return pfcResultat.WIN; - if (botChoice.name === pfcChoix.Pierre) return pfcResultat.LOOSE; - return pfcResultat.DRAW; - } - } - - private static pfcPlayBot(): pfcProposition { - return pfcProposition.propositions[randomInt(pfcProposition.propositions.length)]; - } - - private static pfcTraitementResultat(choix: pfcProposition, choixBot: pfcProposition, resultat: pfcResultat, player: User) { - switch (resultat) { - case pfcResultat.WIN: - return { content: `(${player}) ${choixBot.emoji} ${choixBot.name} ! Well, noob ${choix.emoji} ${choix.name} need nerf plz...` }; - case pfcResultat.LOOSE: - return { content: `(${player}) ${choixBot.emoji} ${choixBot.name} ! GG NO RE, EZ !` }; - case pfcResultat.DRAW: - return { content: `(${player}) ${choixBot.emoji} ${choixBot.name} ! Ha... ÉgalitĂ©...` }; - } - } -} \ No newline at end of file diff --git a/global/buttons/Pfc.ts b/global/buttons/Pfc.ts new file mode 100644 index 0000000..b088133 --- /dev/null +++ b/global/buttons/Pfc.ts @@ -0,0 +1,23 @@ +import { ButtonInteraction } from "discord.js"; +import { ButtonComponent, Discord } from "discordx"; +import { pfcIsWin, pfcPlayBot, pfcProposition, pfcTraitementResultat } from "../../libs/pfc"; + +@Discord() +abstract class Pfc { + + @ButtonComponent('pfc-rock') + @ButtonComponent('pfc-paper') + @ButtonComponent('pfc-scissors') + private async pfcButton(interaction: ButtonInteraction) { + const playerChoice = pfcProposition.buttonCustomIdToClass(interaction.customId); + + if (!playerChoice) { interaction.reply({ content: `Erreur, ${interaction.customId} est un choix invalide.`, ephemeral: true }); return; } + + const botChoice = pfcPlayBot(); + const result = pfcIsWin(playerChoice, botChoice); + + if (!result) { interaction.editReply({ content: `Erreur, ${playerChoice} vs ${botChoice} est un cas de figure non implĂ©mentĂ©.` }); return; } + + interaction.update(pfcTraitementResultat(playerChoice, botChoice, result, interaction.user)); + } +} \ No newline at end of file diff --git a/global/slashs/Fun.ts b/global/slashs/Fun.ts new file mode 100644 index 0000000..185518a --- /dev/null +++ b/global/slashs/Fun.ts @@ -0,0 +1,39 @@ +import { CommandInteraction, MessageActionRow, MessageButton } from "discord.js"; +import { DefaultPermission, Discord, Slash, SlashChoice, SlashGroup, SlashOption } from "discordx"; +import { pfcButtons, pfcChoix, pfcIsWin, pfcPlayBot, pfcProposition, pfcTraitementResultat } from "../../libs/pfc"; + +@Discord() +@DefaultPermission(true) +@SlashGroup("fun", "Commandes orientĂ© sur l'amusement") +abstract class Fun { + + @Slash("pfc", { description: "Quoi de plus amusant que jouer Ă  Pierre Feuille Ciseaux avec un robot ?" }) + async pfc( + @SlashChoice(pfcChoix) + @SlashOption("Choix", { description: "Que voulez-vous jouer ?" }) + choix: pfcChoix, + interaction: CommandInteraction + ) { + if (choix) { + await interaction.deferReply({ ephemeral: true }); + + const choixJoueur = pfcProposition.nameToClass(choix); + + if (!choixJoueur) { interaction.editReply({ content: `Erreur, ${choix} est un choix invalide.` }); return; } + + const choixBot = pfcPlayBot(); + const resultat = pfcIsWin(choixJoueur, choixBot); + + if (!resultat) { interaction.editReply({ content: `Erreur, ${choixJoueur} vs ${choixBot} est un cas de figure non implĂ©mentĂ©.` }); return; } + + interaction.editReply(pfcTraitementResultat(choixJoueur, choixBot, resultat, interaction.user)); + } else { + await interaction.deferReply(); + + const buttonRow = new MessageActionRow() + .addComponents(pfcButtons); + + interaction.editReply({ content: "Ok let's go. 1v1 Pierre Feuille Ciseaux. Vas-y choisis !", components: [buttonRow] }); + } + } +} \ No newline at end of file diff --git a/libs/pfc.ts b/libs/pfc.ts new file mode 100644 index 0000000..9d6158c --- /dev/null +++ b/libs/pfc.ts @@ -0,0 +1,116 @@ +import { randomInt } from "crypto"; +import { EmojiIdentifierResolvable, MessageButton, User } from "discord.js"; + +export enum pfcChoix { + Pierre = "Pierre", + Feuille = "Feuille", + Ciseaux = "Ciseaux", + Puit = "Puit" +} + +export enum pfcEmoji { + Pierre = "đŸȘš", + Feuille = "đŸ§»", + Ciseaux = "✂", + Puit = "❓" +} + +export enum pfcButtonId { + Pierre = "pfc-pierre", + Feuille = "pfc-feuille", + Ciseaux = "pfc-ciseaux", + Puit = "pfc-puit" +} + +export const pfcButtons: MessageButton[] = [ + new MessageButton() + .setLabel(pfcChoix.Pierre) + .setEmoji(pfcEmoji.Pierre) + .setStyle('PRIMARY') + .setCustomId(pfcButtonId.Pierre), + new MessageButton() + .setLabel(pfcChoix.Feuille) + .setEmoji(pfcEmoji.Feuille) + .setStyle('PRIMARY') + .setCustomId(pfcButtonId.Feuille), + new MessageButton() + .setLabel(pfcChoix.Ciseaux) + .setEmoji(pfcEmoji.Ciseaux) + .setStyle('PRIMARY') + .setCustomId(pfcButtonId.Ciseaux), + new MessageButton() + .setLabel(pfcChoix.Puit) + .setEmoji(pfcEmoji.Puit) + .setStyle('PRIMARY') + .setCustomId(pfcButtonId.Puit) +]; + +export enum pfcResultat { + GAGNÉ, + PERDU, + ÉGALITÉ +} + +export class pfcProposition { + public nom: pfcChoix; + public emoji: EmojiIdentifierResolvable; + public buttonCustomId: pfcButtonId; + + public static propositions = [ + new pfcProposition(pfcChoix.Pierre, pfcEmoji.Pierre, pfcButtonId.Pierre), + new pfcProposition(pfcChoix.Feuille, pfcEmoji.Feuille, pfcButtonId.Feuille), + new pfcProposition(pfcChoix.Ciseaux, pfcEmoji.Ciseaux, pfcButtonId.Ciseaux) + ] + + constructor(nom: pfcChoix, emoji: EmojiIdentifierResolvable, buttonCustomId: pfcButtonId) { + this.nom = nom; + this.emoji = emoji; + this.buttonCustomId = buttonCustomId; + } + + public static nameToClass(nom: string): pfcProposition | undefined { + return this.propositions.find(proposition => nom === proposition.nom); + } + + public static buttonCustomIdToClass(buttonCustomId: string): pfcProposition | undefined { + return this.propositions.find(proposition => buttonCustomId === proposition.buttonCustomId); + } + + public toString() { + return `${this.emoji} ${this.nom}`; + } +} + +export function pfcIsWin(choixJoueur: pfcProposition, choixBot: pfcProposition): pfcResultat | undefined { + if (choixBot.nom === choixJoueur.nom) return pfcResultat.ÉGALITÉ; + + switch (choixJoueur.nom) { + case pfcChoix.Pierre: + if (choixBot.nom === pfcChoix.Ciseaux) return pfcResultat.GAGNÉ; + if (choixBot.nom === pfcChoix.Feuille) return pfcResultat.PERDU; + break; + case pfcChoix.Feuille: + if (choixBot.nom === pfcChoix.Pierre) return pfcResultat.GAGNÉ; + if (choixBot.nom === pfcChoix.Ciseaux) return pfcResultat.PERDU; + break; + case pfcChoix.Ciseaux: + if (choixBot.nom === pfcChoix.Feuille) return pfcResultat.GAGNÉ; + if (choixBot.nom === pfcChoix.Pierre) return pfcResultat.PERDU; + break; + } +} + +export function pfcPlayBot(): pfcProposition { + return pfcProposition.propositions[randomInt(pfcProposition.propositions.length)]; +} + +export function pfcTraitementResultat(choix: pfcProposition, choixBot: pfcProposition, resultat: pfcResultat, user: User) { + switch (resultat) { + case pfcResultat.GAGNÉ: + return { content: `(${user}) ${choixBot} ! Well, noob ${choix} need nerf plz...` }; + case pfcResultat.PERDU: + return { content: `(${user}) ${choixBot} ! GG NO RE, EZ !` }; + case pfcResultat.ÉGALITÉ: + return { content: `(${user}) ${choixBot} ! Ha... ÉgalitĂ©...` }; + } +} \ No newline at end of file From 1e75f1c315a99e7ee4d21ce56603812edac2bbbc Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 05:03:43 +0200 Subject: [PATCH 03/29] =?UTF-8?q?Retrait=20du=20DefaultPermission=20d?= =?UTF-8?q?=C3=A9j=C3=A0=20=C3=A0=20true=20de=20base?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- global/slashs/Fun.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/global/slashs/Fun.ts b/global/slashs/Fun.ts index 185518a..09f1a34 100644 --- a/global/slashs/Fun.ts +++ b/global/slashs/Fun.ts @@ -3,7 +3,6 @@ import { DefaultPermission, Discord, Slash, SlashChoice, SlashGroup, SlashOption import { pfcButtons, pfcChoix, pfcIsWin, pfcPlayBot, pfcProposition, pfcTraitementResultat } from "../../libs/pfc"; @Discord() -@DefaultPermission(true) @SlashGroup("fun", "Commandes orientĂ© sur l'amusement") abstract class Fun { From 669a02157e94dade54d067f44012e8036d33a442 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 05:16:30 +0200 Subject: [PATCH 04/29] Chargement des classes avec la nouvelle structure --- index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 4356968..0c76176 100644 --- a/index.ts +++ b/index.ts @@ -24,8 +24,10 @@ async function start() { Intents.FLAGS.GUILD_BANS, ], classes: [ - `${__dirname}/commands/*.ts`, - `${__dirname}/events/discord/*.ts` + `${__dirname}/global/*/*.ts`, + `${__dirname}/global/events/discord/*.ts`, + `${__dirname}/iut_nc_depinfo/*/*.ts`, + `${__dirname}/iut_nc_depinfo/events/discord/*.ts` ], botId: "850109914827587605" }); From 12cc533a8374410741d7305eb9c95d094f6f2184 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 05:16:58 +0200 Subject: [PATCH 05/29] Retrait du botId --- index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 0c76176..4197b9a 100644 --- a/index.ts +++ b/index.ts @@ -28,8 +28,7 @@ async function start() { `${__dirname}/global/events/discord/*.ts`, `${__dirname}/iut_nc_depinfo/*/*.ts`, `${__dirname}/iut_nc_depinfo/events/discord/*.ts` - ], - botId: "850109914827587605" + ] }); SingletonClient.once("ready", async () => { From a4ae3c172c42dac8d04c0fa4a4789265bb2e1189 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 05:29:25 +0200 Subject: [PATCH 06/29] =?UTF-8?q?D=C3=A9placement=20de=20sondage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sondage.ts => global/slashs/Divers.ts | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) rename commands/Sondage.ts => global/slashs/Divers.ts (64%) diff --git a/commands/Sondage.ts b/global/slashs/Divers.ts similarity index 64% rename from commands/Sondage.ts rename to global/slashs/Divers.ts index d23ba8e..b753ec8 100644 --- a/commands/Sondage.ts +++ b/global/slashs/Divers.ts @@ -1,20 +1,19 @@ -import { CommandInteraction, MessageEmbed } from "discord.js"; -import { DefaultPermission, Discord, Slash, SlashOption } from "discordx"; +import { CommandInteraction, Message, MessageEmbed } from "discord.js"; +import { Discord, Slash, SlashOption } from "discordx"; @Discord() -@DefaultPermission(true) -abstract class Sondage { +abstract class Divers { @Slash('sondage', { description: "CrĂ©Ă© un sondage" }) async sondage( @SlashOption("Titre", { description: "Sujet du sondage", required: true }) - title: string, + titre: string, @SlashOption("Description", { description: "Explications affichĂ©es en dessous" }) desc: string, @SlashOption("ImageURL", { description: "Url de l'image affichĂ©e en bas du sondage" }) imageurl: string, @SlashOption("VoteNeutre", { description: "Autoriser ou Interdire le vote neutre. AutorisĂ© par dĂ©faut." }) - allowNeutralVote: boolean = true, + autoriserVoteNeutre: boolean = true, interaction: CommandInteraction ) { await interaction.deferReply(); @@ -22,7 +21,7 @@ abstract class Sondage { const resEmbed = new MessageEmbed() .setColor("#DD131E") .setAuthor(interaction.user.username, (interaction.user.avatarURL({ dynamic: true }) || undefined)) - .setTitle(title) + .setTitle(titre) .setFooter("Tu peux voter en cliquant sur les rĂ©actions en dessous") .setTimestamp(); @@ -33,16 +32,16 @@ abstract class Sondage { const reply = await interaction.fetchReply(); + if (!(reply instanceof Message)) { interaction.editReply("Erreur, reply: " + reply.type); return; } + + // Le processus est assez lent pour que la rĂ©ponse de l'interaction soit supprimĂ© et fasse crash le bot try { - //@ts-ignore await reply.react("👍"); - //@ts-ignore - if (allowNeutralVote) await reply.react("đŸ€”"); - //@ts-ignore + if (autoriserVoteNeutre) await reply.react("đŸ€”"); await reply.react("👎"); } catch (err) { - interaction.editReply("Erreur <@227882902031958016>, " + reply.type) + console.error(err); + try { interaction.editReply("Erreur, vĂ©rification des logs."); } catch (err) { console.error(err); return; } } - } } \ No newline at end of file From 53035dabe045aa9a821accca4f6881d710e01e37 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 05:41:33 +0200 Subject: [PATCH 07/29] Extraction des enums des IDs --- IDs.ts | 3 +++ {enums => iut_nc_depinfo}/IDs.ts | 9 ++------- 2 files changed, 5 insertions(+), 7 deletions(-) create mode 100644 IDs.ts rename {enums => iut_nc_depinfo}/IDs.ts (91%) diff --git a/IDs.ts b/IDs.ts new file mode 100644 index 0000000..42cf0fd --- /dev/null +++ b/IDs.ts @@ -0,0 +1,3 @@ +export enum Serveur { + DEP_INFO = "753171392450527282" +} \ No newline at end of file diff --git a/enums/IDs.ts b/iut_nc_depinfo/IDs.ts similarity index 91% rename from enums/IDs.ts rename to iut_nc_depinfo/IDs.ts index 5f90b31..fc5647c 100644 --- a/enums/IDs.ts +++ b/iut_nc_depinfo/IDs.ts @@ -1,4 +1,4 @@ -export enum RoleIDs { +export enum Role { EVERYONE = '753171392450527282', STAR = '753181468183887914', ADMIN = '753182939352793138', @@ -29,12 +29,7 @@ export enum RoleIDs { ALTERNANT = '887692800878063706' } -export enum ChannelIDs{ +export enum Channel { ADMIN_CHANNEL = '753753680334815345', TWITTER = '854010477838073876' - -} - -export enum ServerIDs { - MAIN = '753171392450527282' } \ No newline at end of file From 0364fa25c001b7dc750274bdf02597298fc17cd5 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 05:47:47 +0200 Subject: [PATCH 08/29] Extraction de info --- commands/Info.ts | 51 -------------------------------- iut_nc_depinfo/slashs/Divers.ts | 52 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 51 deletions(-) delete mode 100644 commands/Info.ts create mode 100644 iut_nc_depinfo/slashs/Divers.ts diff --git a/commands/Info.ts b/commands/Info.ts deleted file mode 100644 index 4004091..0000000 --- a/commands/Info.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { CommandInteraction, MessageEmbed } from 'discord.js'; -import { Discord, Slash } from 'discordx'; -import { RoleIDs } from '../enums/IDs'; - -@Discord() -abstract class Info { - - @Slash('info', { description: "Affiche les informations du serveur" }) - private async info(interaction: CommandInteraction) { - if (interaction.channel?.type === "DM") { interaction.reply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande en message privĂ©.", ephemeral: true }) } - - await interaction.deferReply(); - - const guild = interaction.guild; - - const resEmbed = new MessageEmbed() - .setColor('#DD131E') - .setTitle('Informations du Serveur') - .addFields( - { - name: 'Membres', - value: ` - <@&${RoleIDs.ADMIN}> : \`${guild?.roles.resolve(RoleIDs.ADMIN)?.members.size}\` - <@&${RoleIDs.SERVER_BOOSTER}> : \`${guild?.roles.resolve(RoleIDs.SERVER_BOOSTER)?.members.size}\` - <@&${RoleIDs.ENSEIGNANT}> : \`${guild?.roles.resolve(RoleIDs.ENSEIGNANT)?.members.size}\` - <@&${RoleIDs.DÉLÉGUÉ}> : \`${guild?.roles.resolve(RoleIDs.DÉLÉGUÉ)?.members.size}\` - Ancien Étudiant : \`${(guild?.roles.resolve(RoleIDs.ANCIEN_DUT)?.members.size || 0) + (guild?.roles.resolve(RoleIDs.ANCIEN_LP_CIASIE)?.members.size || 0)}\` - <@&${RoleIDs.ÉTUDIANT}> : \`${guild?.roles.resolve(RoleIDs.ÉTUDIANT)?.members.size}\` - <@&${RoleIDs.COMPTE_SECONDAIRE}> : \`${guild?.roles.resolve(RoleIDs.COMPTE_SECONDAIRE)?.members.size}\` - Total : \`${guild?.memberCount}\` - `, - inline: true - }, - { - name: 'Promos', - value: ` - <@&${RoleIDs.LP_ACORS}> : \`${guild?.roles.resolve(RoleIDs.LP_ACORS)?.members.size}\` - <@&${RoleIDs.LP_AFTER}> : \`${guild?.roles.resolve(RoleIDs.LP_AFTER)?.members.size}\` - <@&${RoleIDs.LP_CIASIE}> : \`${guild?.roles.resolve(RoleIDs.LP_CIASIE)?.members.size}\` - <@&${RoleIDs.BUT_1A}> : \`${guild?.roles.resolve(RoleIDs.BUT_1A)?.members.size}\` - <@&${RoleIDs.DUT_2A}> : \`${guild?.roles.resolve(RoleIDs.DUT_2A)?.members.size}\` - `, - inline: true - }, - { name: 'Nombre de salons', value: `${guild?.channels.cache.size}/500` } - ) - .setTimestamp(); - - interaction.editReply({ embeds: [resEmbed] }) - } -} \ No newline at end of file diff --git a/iut_nc_depinfo/slashs/Divers.ts b/iut_nc_depinfo/slashs/Divers.ts new file mode 100644 index 0000000..f2ddaeb --- /dev/null +++ b/iut_nc_depinfo/slashs/Divers.ts @@ -0,0 +1,52 @@ +import { CommandInteraction, MessageEmbed } from 'discord.js'; +import { Discord, Guild, Slash } from 'discordx'; +import { Serveur } from '../../IDs'; +import { Role } from '../IDs'; + +@Discord() +@Guild(Serveur.DEP_INFO) +abstract class Divers { + + @Slash('info', { description: "Affiche les informations du serveur" }) + private async info(interaction: CommandInteraction) { + + await interaction.deferReply(); + + const guild = interaction.guild; + + const resEmbed = new MessageEmbed() + .setColor('#DD131E') + .setTitle('Informations du Serveur') + .addFields( + { + name: 'Membres', + value: ` + <@&${Role.ADMIN}> : \`${guild?.roles.resolve(Role.ADMIN)?.members.size}\` + <@&${Role.SERVER_BOOSTER}> : \`${guild?.roles.resolve(Role.SERVER_BOOSTER)?.members.size}\` + <@&${Role.ENSEIGNANT}> : \`${guild?.roles.resolve(Role.ENSEIGNANT)?.members.size}\` + <@&${Role.DÉLÉGUÉ}> : \`${guild?.roles.resolve(Role.DÉLÉGUÉ)?.members.size}\` + Ancien Étudiant : \`${(guild?.roles.resolve(Role.ANCIEN_DUT)?.members.size || 0) + (guild?.roles.resolve(Role.ANCIEN_LP_CIASIE)?.members.size || 0)}\` + <@&${Role.ÉTUDIANT}> : \`${guild?.roles.resolve(Role.ÉTUDIANT)?.members.size}\` + <@&${Role.COMPTE_SECONDAIRE}> : \`${guild?.roles.resolve(Role.COMPTE_SECONDAIRE)?.members.size}\` + Total : \`${guild?.memberCount}\` + `, + inline: true + }, + { + name: 'Promos', + value: ` + <@&${Role.LP_ACORS}> : \`${guild?.roles.resolve(Role.LP_ACORS)?.members.size}\` + <@&${Role.LP_AFTER}> : \`${guild?.roles.resolve(Role.LP_AFTER)?.members.size}\` + <@&${Role.LP_CIASIE}> : \`${guild?.roles.resolve(Role.LP_CIASIE)?.members.size}\` + <@&${Role.BUT_1A}> : \`${guild?.roles.resolve(Role.BUT_1A)?.members.size}\` + <@&${Role.DUT_2A}> : \`${guild?.roles.resolve(Role.DUT_2A)?.members.size}\` + `, + inline: true + }, + { name: 'Nombre de salons', value: `${guild?.channels.cache.size}/500` } + ) + .setTimestamp(); + + interaction.editReply({ embeds: [resEmbed] }) + } +} \ No newline at end of file From 54c2a551f4464caa9fa09f6bcb9f2203469e33db Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 06:55:15 +0200 Subject: [PATCH 09/29] Renommage de l'enum DEP_INFO --- IDs.ts | 2 +- iut_nc_depinfo/slashs/Divers.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/IDs.ts b/IDs.ts index 42cf0fd..f0bac22 100644 --- a/IDs.ts +++ b/IDs.ts @@ -1,3 +1,3 @@ export enum Serveur { - DEP_INFO = "753171392450527282" + IUT_NC_DEP_INFO = "753171392450527282" } \ No newline at end of file diff --git a/iut_nc_depinfo/slashs/Divers.ts b/iut_nc_depinfo/slashs/Divers.ts index f2ddaeb..acfeaee 100644 --- a/iut_nc_depinfo/slashs/Divers.ts +++ b/iut_nc_depinfo/slashs/Divers.ts @@ -4,7 +4,7 @@ import { Serveur } from '../../IDs'; import { Role } from '../IDs'; @Discord() -@Guild(Serveur.DEP_INFO) +@Guild(Serveur.IUT_NC_DEP_INFO) abstract class Divers { @Slash('info', { description: "Affiche les informations du serveur" }) From 4aa70458a044ab8854edaeb8fa0432eaa43e16c1 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 06:55:33 +0200 Subject: [PATCH 10/29] =?UTF-8?q?Passage=20en=20Fran=C3=A7ais=20de=20Chann?= =?UTF-8?q?el?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iut_nc_depinfo/IDs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iut_nc_depinfo/IDs.ts b/iut_nc_depinfo/IDs.ts index fc5647c..d3dda19 100644 --- a/iut_nc_depinfo/IDs.ts +++ b/iut_nc_depinfo/IDs.ts @@ -29,7 +29,7 @@ export enum Role { ALTERNANT = '887692800878063706' } -export enum Channel { +export enum Salon { ADMIN_CHANNEL = '753753680334815345', TWITTER = '854010477838073876' } \ No newline at end of file From 7727b8669f13bb6caaa8df25299d985e06b309d6 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 08:23:04 +0200 Subject: [PATCH 11/29] Ajout de MEMBRE_UL --- iut_nc_depinfo/IDs.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iut_nc_depinfo/IDs.ts b/iut_nc_depinfo/IDs.ts index d3dda19..f6b6173 100644 --- a/iut_nc_depinfo/IDs.ts +++ b/iut_nc_depinfo/IDs.ts @@ -26,7 +26,8 @@ export enum Role { DUT_2A_D = '756580564982825121', ANCIEN_DUT = '784475924569522247', ANCIEN_LP_CIASIE = '784476096480804884', - ALTERNANT = '887692800878063706' + ALTERNANT = '887692800878063706', + MEMBRE_UL = '887917824822083594' } export enum Salon { From 5c44a62b7adae348981f95d907060f64bdf47fe3 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 08:23:32 +0200 Subject: [PATCH 12/29] =?UTF-8?q?Extract=20des=20SelectMenu=20de=20prise?= =?UTF-8?q?=20de=20r=C3=B4les?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/Role.ts | 418 ------------------ iut_nc_depinfo/selectMenus/Roles.ts | 348 +++++++++++++++ .../slashs/MessagesSelectionRoles.ts | 102 +++++ 3 files changed, 450 insertions(+), 418 deletions(-) delete mode 100644 commands/Role.ts create mode 100644 iut_nc_depinfo/selectMenus/Roles.ts create mode 100644 iut_nc_depinfo/slashs/MessagesSelectionRoles.ts diff --git a/commands/Role.ts b/commands/Role.ts deleted file mode 100644 index c1f94e8..0000000 --- a/commands/Role.ts +++ /dev/null @@ -1,418 +0,0 @@ -import { CommandInteraction, Guild, MessageActionRow, MessageSelectMenu, SelectMenuInteraction, User } from "discord.js"; -import { DefaultPermission, Discord, Guild as Guildx, Permission, SelectMenuComponent, Slash } from "discordx"; -import { ChannelIDs, RoleIDs, ServerIDs } from "../enums/IDs"; - -@Discord() -@Guildx(ServerIDs.MAIN) // Alias @Guild due to import name conflict -@DefaultPermission(false) -@Permission({ id: RoleIDs.ADMIN, type: 'ROLE', permission: true }) -@Permission({ id: RoleIDs.STAR, type: 'ROLE', permission: true }) -abstract class Role { - - @Slash('messageroles', { description: "Envoie le message permettant d'obtenir les rĂŽles" }) - async messageroles(interaction: CommandInteraction) { - await interaction.deferReply({ ephemeral: true }); - - const channel = interaction.channel; - - if (!channel) { interaction.editReply({ content: "Erreur, channel: " + channel }); return; } - - if (!channel.isText()) interaction.reply("Type de salon inattendu."); - - const licensesProRow = new MessageActionRow() - .addComponents( - new MessageSelectMenu() - .setCustomId('role-lp') - .setPlaceholder("Licences Professionnelles") - .addOptions([ - { - label: "Licenses Pro. ACORS", - value: "lp-ACORS", - description: "Vous ĂȘtes en Licences Professionnelle ACORS ?" - }, - { - label: "Licenses Pro. AFTER", - value: "lp-AFTER", - description: "Vous ĂȘtes en Licences Professionnelle AFTER ?" - }, - { - label: "Licenses Pro. CIASIE 1", - value: "lp-CIASIE-1", - description: "Vous ĂȘtes en Licences Professionnelle CIASIE (Groupe 1) ?" - }, - { - label: "Licenses Pro. CIASIE 2", - value: "lp-CIASIE-2", - description: "Vous ĂȘtes en Licences Professionnelle CIASIE (Groupe 2) ?" - }])); - - const BUT1ARow = new MessageActionRow() - .addComponents( - new MessageSelectMenu() - .setCustomId('role-but-1a') - .setPlaceholder("BUT 1Ăšre AnnĂ©e") - .addOptions([ - { - label: "BUT 1Ăšre AnnĂ©e A", - value: "but-1A-a", - description: "Vous ĂȘtes en 1Ăšre AnnĂ©e de BUT (Groupe A)?" - }, - { - label: "BUT 1Ăšre AnnĂ©e B", - value: "but-1A-b", - description: "Vous ĂȘtes en 1Ăšre AnnĂ©e de BUT (Groupe B)?" - }, - { - label: "BUT 1Ăšre AnnĂ©e C", - value: "but-1A-c", - description: "Vous ĂȘtes en 1Ăšre AnnĂ©e de BUT (Groupe C)?" - }, - { - label: "BUT 1Ăšre AnnĂ©e D", - value: "but-1A-d", - description: "Vous ĂȘtes en 1Ăšre AnnĂ©e de BUT (Groupe D)?" - }, - { - label: "BUT 1Ăšre AnnĂ©e E", - value: "but-1A-e", - description: "Vous ĂȘtes en 1Ăšre AnnĂ©e de BUT (Groupe E)?" - } - ]) - ); - - const DUT2ARow = new MessageActionRow() - .addComponents( - new MessageSelectMenu() - .setCustomId('role-dut-2a') - .setPlaceholder("DUT 2Ăšme AnnĂ©e") - .addOptions([ - { - label: "DUT 2Ăšme AnnĂ©e A", - value: "dut-2A-a", - description: "Vous ĂȘtes en 2Ăšme AnnĂ©e de DUT (Groupe A)?" - }, - { - label: "DUT 2Ăšme AnnĂ©e B", - value: "dut-2A-b", - description: "Vous ĂȘtes en 2Ăšme AnnĂ©e de DUT (Groupe B)?" - }, - { - label: "DUT 2Ăšme AnnĂ©e C", - value: "dut-2A-c", - description: "Vous ĂȘtes en 2Ăšme AnnĂ©e de DUT (Groupe C)?" - }, - { - label: "DUT 2Ăšme AnnĂ©e D", - value: "dut-2A-d", - description: "Vous ĂȘtes en 2Ăšme AnnĂ©e de DUT (Groupe D)?" - } - ]) - ); - - const NotStudentRow = new MessageActionRow() - .addComponents( - new MessageSelectMenu() - .setCustomId('role-other') - .setPlaceholder("Non-Ă©tudiant") - .addOptions([ - { - label: "Enseignant", - value: "teacher", - description: "Vous ĂȘtes enseignant ?" - } - ]) - ); - - const OldStudentRow = new MessageActionRow() - .addComponents( - new MessageSelectMenu() - .setCustomId('role-old-student') - .setPlaceholder("Ancien Ă©tudiant") - .addOptions([ - /*{ - label: "Ancien LP ACORS", - value: "old-lp-ACORS", - description: "Vous ĂȘtes un ancien de la LP ACORS ?" - }, - { - label: "Ancien LP AFTER", - value: "old-lp-AFTER", - description: "Vous ĂȘtes un ancien de la LP AFTER ?" - },*/ - { - label: "Ancien LP CIASIE", - value: "old-lp-CIASIE", - description: "Vous ĂȘtes un ancien de la LP CIASIE ?" - }, - { - label: "Ancien DUT", - value: "old-DUT", - description: "Vous ĂȘtes un ancien du DUT ?" - } - ]) - ); - - try { - await channel.send({ content: "Bienvenue sur le Serveur du DĂ©partement Informatique de l'IUT Nancy-Charlemagne ! Veuillez sĂ©lectionner ce qui vous correspondant via le menu juste en dessous.", components: [licensesProRow, BUT1ARow, DUT2ARow, NotStudentRow, OldStudentRow] }); - } catch (err) { - interaction.editReply({ content: "Une erreur est survenue." }); - console.log(err) - } finally { - interaction.editReply({ content: "Done." }); - } - } - - @SelectMenuComponent('role-lp') - async selectMenuLP(interaction: SelectMenuInteraction) { - await interaction.deferReply({ ephemeral: true }); - - const roleValue = interaction.values?.[0]; - - if (!roleValue) { interaction.editReply({ content: `Erreur, value = ${roleValue}` }); return; } - - const user = interaction.user; - - const guild = interaction.guild; - - if (!guild) { interaction.editReply({ content: `Erreur, value = ${guild}` }); return; } - - switch (roleValue) { - case 'lp-ACORS': - await this.assignRole(guild, user, RoleIDs.LP_ACORS, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - case 'lp-AFTER': - await this.assignRole(guild, user, RoleIDs.LP_AFTER, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - case 'lp-CIASIE-1': - await this.assignRole(guild, user, RoleIDs.LP_CIASIE, interaction); - await this.assignRole(guild, user, RoleIDs.LP_CIASIE_1, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - case 'lp-CIASIE-2': - await this.assignRole(guild, user, RoleIDs.LP_CIASIE, interaction); - await this.assignRole(guild, user, RoleIDs.LP_CIASIE_2, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - default: - await interaction.followUp({ content: `Erreur, value = ${roleValue}`, ephemeral: true }); - } - } - - @SelectMenuComponent('role-but-1a') - async selectMenuBUT1A(interaction: SelectMenuInteraction) { - await interaction.deferReply({ ephemeral: true }); - - const roleValue = interaction.values?.[0]; - - if (!roleValue) { interaction.editReply({ content: `Erreur, value = ${roleValue}` }); return; } - - const user = interaction.user; - - const guild = interaction.guild; - - if (!guild) { interaction.editReply({ content: `Erreur, value = ${guild}` }); return; } - - switch (roleValue) { - case 'but-1A-a': - await this.assignRole(guild, user, RoleIDs.BUT_1A, interaction); - await this.assignRole(guild, user, RoleIDs.BUT_1A_A, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - case 'but-1A-b': - await this.assignRole(guild, user, RoleIDs.BUT_1A, interaction); - await this.assignRole(guild, user, RoleIDs.BUT_1A_B, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - case 'but-1A-c': - await this.assignRole(guild, user, RoleIDs.BUT_1A, interaction); - await this.assignRole(guild, user, RoleIDs.BUT_1A_C, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - case 'but-1A-d': - await this.assignRole(guild, user, RoleIDs.BUT_1A, interaction); - await this.assignRole(guild, user, RoleIDs.BUT_1A_D, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - case 'but-1A-e': - await this.assignRole(guild, user, RoleIDs.BUT_1A, interaction); - await this.assignRole(guild, user, RoleIDs.BUT_1A_E, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - default: - await interaction.followUp({ content: `Erreur, value = ${roleValue}`, ephemeral: true }); - } - } - - @SelectMenuComponent('role-dut-2a') - async selectMenuDUT2A(interaction: SelectMenuInteraction) { - await interaction.deferReply({ ephemeral: true }); - - const roleValue = interaction.values?.[0]; - - if (!roleValue) { interaction.editReply({ content: `Erreur, value = ${roleValue}` }); return; } - - const user = interaction.user; - - const guild = interaction.guild; - - if (!guild) { interaction.editReply({ content: `Erreur, value = ${guild}` }); return; } - - switch (roleValue) { - case 'dut-2A-a': - await this.assignRole(guild, user, RoleIDs.DUT_2A, interaction); - await this.assignRole(guild, user, RoleIDs.DUT_2A_A, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - case 'dut-2A-b': - await this.assignRole(guild, user, RoleIDs.DUT_2A, interaction); - await this.assignRole(guild, user, RoleIDs.DUT_2A_B, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - case 'dut-2A-c': - await this.assignRole(guild, user, RoleIDs.DUT_2A, interaction); - await this.assignRole(guild, user, RoleIDs.DUT_2A_C, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - case 'dut-2A-d': - await this.assignRole(guild, user, RoleIDs.DUT_2A, interaction); - await this.assignRole(guild, user, RoleIDs.DUT_2A_D, interaction); - await this.assignRole(guild, user, RoleIDs.ÉTUDIANT, interaction); - break; - default: - await interaction.followUp({ content: `Erreur, value = ${roleValue}`, ephemeral: true }); - } - } - - @SelectMenuComponent('role-other') - async selectMenuOther(interaction: SelectMenuInteraction) { - await interaction.deferReply({ ephemeral: true }); - - const roleValue = interaction.values?.[0]; - - if (!roleValue) { interaction.editReply({ content: `Erreur, value = ${roleValue}` }); return; } - - const user = interaction.user; - - const guild = interaction.guild; - - if (!guild) { interaction.editReply({ content: `Erreur, value = ${guild}` }); return; } - - switch (roleValue) { - case 'teacher': - const adminChannel = (interaction.guild.channels.resolve(ChannelIDs.ADMIN_CHANNEL)); - - if (!adminChannel) { interaction.editReply({ content: `Erreur, adminChannel = ${adminChannel}` }); return; } - - if (!adminChannel.isText()) { interaction.editReply({ content: `Erreur, adminChannelType = ${adminChannel.type}` }); return; } - - await adminChannel.send(`${interaction.guild.roles.resolve(RoleIDs.ADMIN)} ! ${user} demande le grade ${interaction?.guild?.roles?.resolve(RoleIDs.ENSEIGNANT)}.`); - interaction.followUp({ content: "Votre demande a bien Ă©tĂ© transmisse ! Étant donnĂ© les permissions attachĂ©es Ă  ce rĂŽle, il vous sera attribuĂ©e manuelle par un " + guild.roles.resolve(RoleIDs.ADMIN) + " aprĂšs vĂ©rifications.", ephemeral: true }); - break; - default: - await interaction.followUp({ content: `Erreur, value = ${roleValue}`, ephemeral: true }); - } - } - - @SelectMenuComponent('role-old-student') - async selectMenuOldStudent(interaction: SelectMenuInteraction) { - await interaction.deferReply({ ephemeral: true }); - - const roleValue = interaction.values?.[0]; - - if (!roleValue) { interaction.editReply({ content: `Erreur, value = ${roleValue}` }); return; } - - const user = interaction.user; - - const guild = interaction.guild; - - if (!guild) { interaction.editReply({ content: `Erreur, value = ${guild}` }); return; } - - switch (roleValue) { - case 'old-lp-CIASIE': - await this.assignRole(guild, user, RoleIDs.ANCIEN_LP_CIASIE, interaction); - break; - case 'old-DUT': - await this.assignRole(guild, user, RoleIDs.ANCIEN_DUT, interaction); - break; - default: - await interaction.followUp({ content: `Erreur, value = ${roleValue}`, ephemeral: true }); - } - } - - private async assignRole(guild: Guild, user: User, roleID: RoleIDs, interaction: SelectMenuInteraction) { - await guild?.members.resolve(user)?.roles.add(roleID); - await interaction.followUp({ content: `Le rĂŽle <@&${roleID}> a bien Ă©tĂ© assignĂ© !`, ephemeral: true }); - } - - private async removeRole(guild: Guild, user: User, roleID: RoleIDs, interaction: SelectMenuInteraction) { - await guild?.members.resolve(user)?.roles.remove(roleID); - await interaction.followUp({ content: `Le rĂŽle <@&${roleID}> a bien Ă©tĂ© retirĂ© !`, ephemeral: true }); - } - - @Slash('messageRoleAlternant', { description: "Envoie le message permettant d'obtenir le rĂŽle alternant" }) - async messageRoleAlternant(interaction: CommandInteraction) { - await interaction.deferReply({ ephemeral: true }); - - const channel = interaction.channel; - - if (!channel) { interaction.editReply({ content: "Erreur, channel: " + channel }); return; } - - if (!channel.isText()) interaction.reply("Type de salon inattendu."); - - const row = new MessageActionRow() - .addComponents( - new MessageSelectMenu() - .setCustomId('role-alternant') - .setPlaceholder("Veuillez sĂ©lectionner une rĂ©ponse") - .addOptions([ - { - label: "Oui", - description: "Je suis en alternance", - value: "oui" - }, - { - label: "Non", - "description": "Je suis en formation classique", - value: "non" - } - ]) - ); - - try { - await channel.send({ content: "Êtes-vous en alternance ? Si oui, vous pouvez obtenir un rĂŽle spĂ©cial afin de faciliter les mentions et avoir un salon regroupant les alternants.", components: [row] }); - } catch (err) { - interaction.editReply({ content: "Une erreur est survenue." }); - console.log(err) - } finally { - interaction.editReply({ content: "Done." }); - } - } - - @SelectMenuComponent('role-alternant') - async selectMenuAlternant(interaction: SelectMenuInteraction){ - await interaction.deferReply({ ephemeral: true }); - - const roleValue = interaction.values?.[0]; - - if (!roleValue) { interaction.editReply({ content: `Erreur, value = ${roleValue}` }); return; } - - const user = interaction.user; - - const guild = interaction.guild; - - if (!guild) { interaction.editReply({ content: `Erreur, value = ${guild}` }); return; } - - switch (roleValue) { - case 'oui': - await this.assignRole(guild, user, RoleIDs.ALTERNANT, interaction); - break; - case 'non': - await this.removeRole(guild, user, RoleIDs.ALTERNANT, interaction); - break; - default: - await interaction.followUp({ content: `Erreur, value = ${roleValue}`, ephemeral: true }); - } - } -} \ No newline at end of file diff --git a/iut_nc_depinfo/selectMenus/Roles.ts b/iut_nc_depinfo/selectMenus/Roles.ts new file mode 100644 index 0000000..6c4e992 --- /dev/null +++ b/iut_nc_depinfo/selectMenus/Roles.ts @@ -0,0 +1,348 @@ +import { Guild, SelectMenuInteraction, User } from "discord.js"; +import { Discord, SelectMenuComponent } from "discordx"; +import { Role, Salon } from "../IDs"; + +@Discord() +abstract class Roles { + + @SelectMenuComponent('role-lp') + async roleLP(interaction: SelectMenuInteraction) { + await interaction.deferReply({ ephemeral: true }); + + const roleValue = interaction.values?.[0]; + + if (!roleValue) { interaction.editReply({ content: `Erreur, value = ${roleValue}` }); return; } + + const user = interaction.user; + + const guild = interaction.guild; + + if (!guild) { interaction.editReply({ content: `Erreur, value = ${guild}` }); return; } + + switch (roleValue) { + case 'lp-ACORS': + await this.assignRole(guild, user, Role.LP_ACORS, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + case 'lp-AFTER': + await this.assignRole(guild, user, Role.LP_AFTER, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + case 'lp-CIASIE-1': + await this.assignRole(guild, user, Role.LP_CIASIE, interaction); + await this.assignRole(guild, user, Role.LP_CIASIE_1, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + case 'lp-CIASIE-2': + await this.assignRole(guild, user, Role.LP_CIASIE, interaction); + await this.assignRole(guild, user, Role.LP_CIASIE_2, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + default: + await interaction.followUp({ content: `Erreur, value = ${roleValue}`, ephemeral: true }); + } + } + + @SelectMenuComponent('role-but-1a') + async roleBUT1A(interaction: SelectMenuInteraction) { + await interaction.deferReply({ ephemeral: true }); + + const roleValue = interaction.values?.[0]; + + if (!roleValue) { interaction.editReply({ content: `Erreur, value = ${roleValue}` }); return; } + + const user = interaction.user; + + const guild = interaction.guild; + + if (!guild) { interaction.editReply({ content: `Erreur, value = ${guild}` }); return; } + + switch (roleValue) { + case 'but-1A-a': + await this.assignRole(guild, user, Role.BUT_1A, interaction); + await this.assignRole(guild, user, Role.BUT_1A_A, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + case 'but-1A-b': + await this.assignRole(guild, user, Role.BUT_1A, interaction); + await this.assignRole(guild, user, Role.BUT_1A_B, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + case 'but-1A-c': + await this.assignRole(guild, user, Role.BUT_1A, interaction); + await this.assignRole(guild, user, Role.BUT_1A_C, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + case 'but-1A-d': + await this.assignRole(guild, user, Role.BUT_1A, interaction); + await this.assignRole(guild, user, Role.BUT_1A_D, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + case 'but-1A-e': + await this.assignRole(guild, user, Role.BUT_1A, interaction); + await this.assignRole(guild, user, Role.BUT_1A_E, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + default: + await interaction.followUp({ content: `Erreur, value = ${roleValue}`, ephemeral: true }); + } + } + + @SelectMenuComponent('role-dut-2a') + async roleDUT2A(interaction: SelectMenuInteraction) { + await interaction.deferReply({ ephemeral: true }); + + const roleValue = interaction.values?.[0]; + + if (!roleValue) { interaction.editReply({ content: `Erreur, value = ${roleValue}` }); return; } + + const user = interaction.user; + + const guild = interaction.guild; + + if (!guild) { interaction.editReply({ content: `Erreur, value = ${guild}` }); return; } + + switch (roleValue) { + case 'dut-2A-a': + await this.assignRole(guild, user, Role.DUT_2A, interaction); + await this.assignRole(guild, user, Role.DUT_2A_A, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + case 'dut-2A-b': + await this.assignRole(guild, user, Role.DUT_2A, interaction); + await this.assignRole(guild, user, Role.DUT_2A_B, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + case 'dut-2A-c': + await this.assignRole(guild, user, Role.DUT_2A, interaction); + await this.assignRole(guild, user, Role.DUT_2A_C, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + case 'dut-2A-d': + await this.assignRole(guild, user, Role.DUT_2A, interaction); + await this.assignRole(guild, user, Role.DUT_2A_D, interaction); + await this.assignRole(guild, user, Role.ÉTUDIANT, interaction); + break; + default: + await interaction.followUp({ content: `Erreur, value = ${roleValue}`, ephemeral: true }); + } + } + + @SelectMenuComponent('role-other') + async roleAutre(interaction: SelectMenuInteraction) { + await interaction.deferReply({ ephemeral: true }); + + const roleValue = interaction.values?.[0]; + + if (!roleValue) { interaction.editReply({ content: `Erreur, value = ${roleValue}` }); return; } + + const user = interaction.user; + + const guild = interaction.guild; + + if (!guild) { interaction.editReply({ content: `Erreur, value = ${guild}` }); return; } + + switch (roleValue) { + case 'membreUL': + await this.assignRole(guild, user, Role.MEMBRE_UL, interaction); + break; + case 'teacher': + const adminChannel = (interaction.guild.channels.resolve(Salon.ADMIN_CHANNEL)); + + if (!adminChannel) { interaction.editReply({ content: `Erreur, adminChannel = ${adminChannel}` }); return; } + + if (!adminChannel.isText()) { interaction.editReply({ content: `Erreur, adminChannelType = ${adminChannel.type}` }); return; } + + await adminChannel.send(`${interaction.guild.roles.resolve(Role.ADMIN)} ! ${user} demande le grade ${interaction?.guild?.roles?.resolve(Role.ENSEIGNANT)}.`); + interaction.followUp({ content: "Votre demande a bien Ă©tĂ© transmisse ! Étant donnĂ© les permissions attachĂ©es Ă  ce rĂŽle, il vous sera attribuĂ©e manuelle par un " + guild.roles.resolve(Role.ADMIN) + " aprĂšs vĂ©rifications.", ephemeral: true }); + break; + default: + await interaction.followUp({ content: `Erreur, value = ${roleValue}`, ephemeral: true }); + } + } + + @SelectMenuComponent('role-old-student') + async RoleAncien(interaction: SelectMenuInteraction) { + await interaction.deferReply({ ephemeral: true }); + + const roleValue = interaction.values?.[0]; + + if (!roleValue) { interaction.editReply({ content: `Erreur, value = ${roleValue}` }); return; } + + const user = interaction.user; + + const guild = interaction.guild; + + if (!guild) { interaction.editReply({ content: `Erreur, value = ${guild}` }); return; } + + switch (roleValue) { + case 'old-lp-CIASIE': + await this.assignRole(guild, user, Role.ANCIEN_LP_CIASIE, interaction); + break; + case 'old-DUT': + await this.assignRole(guild, user, Role.ANCIEN_DUT, interaction); + break; + default: + await interaction.followUp({ content: `Erreur, value = ${roleValue}`, ephemeral: true }); + } + } + + private async assignRole(guild: Guild, user: User, roleID: Role, interaction: SelectMenuInteraction) { + await guild?.members.resolve(user)?.roles.add(roleID); + await interaction.followUp({ content: `Le rĂŽle <@&${roleID}> a bien Ă©tĂ© assignĂ© !`, ephemeral: true }); + } + + private async removeRole(guild: Guild, user: User, roleID: Role, interaction: SelectMenuInteraction) { + await guild?.members.resolve(user)?.roles.remove(roleID); + await interaction.followUp({ content: `Le rĂŽle <@&${roleID}> a bien Ă©tĂ© retirĂ© !`, ephemeral: true }); + } + + @SelectMenuComponent('role-alternant') + async selectMenuAlternant(interaction: SelectMenuInteraction) { + await interaction.deferReply({ ephemeral: true }); + + const roleValue = interaction.values?.[0]; + + if (!roleValue) { interaction.editReply({ content: `Erreur, value = ${roleValue}` }); return; } + + const user = interaction.user; + + const guild = interaction.guild; + + if (!guild) { interaction.editReply({ content: `Erreur, value = ${guild}` }); return; } + + switch (roleValue) { + case 'oui': + await this.assignRole(guild, user, Role.ALTERNANT, interaction); + break; + case 'non': + await this.removeRole(guild, user, Role.ALTERNANT, interaction); + break; + default: + await interaction.followUp({ content: `Erreur, value = ${roleValue}`, ephemeral: true }); + } + } +} + +export const RolesLPOptions = [ + { + label: "Licenses Pro. ACORS", + value: "lp-ACORS", + description: "Vous ĂȘtes en Licences Professionnelle ACORS ?" + }, + { + label: "Licenses Pro. AFTER", + value: "lp-AFTER", + description: "Vous ĂȘtes en Licences Professionnelle AFTER ?" + }, + { + label: "Licenses Pro. CIASIE 1", + value: "lp-CIASIE-1", + description: "Vous ĂȘtes en Licences Professionnelle CIASIE (Groupe 1) ?" + }, + { + label: "Licenses Pro. CIASIE 2", + value: "lp-CIASIE-2", + description: "Vous ĂȘtes en Licences Professionnelle CIASIE (Groupe 2) ?" + } +]; + +export const RolesBUT1AOptions = [ + { + label: "BUT 1Ăšre AnnĂ©e A", + value: "but-1A-a", + description: "Vous ĂȘtes en 1Ăšre AnnĂ©e de BUT (Groupe A)?" + }, + { + label: "BUT 1Ăšre AnnĂ©e B", + value: "but-1A-b", + description: "Vous ĂȘtes en 1Ăšre AnnĂ©e de BUT (Groupe B)?" + }, + { + label: "BUT 1Ăšre AnnĂ©e C", + value: "but-1A-c", + description: "Vous ĂȘtes en 1Ăšre AnnĂ©e de BUT (Groupe C)?" + }, + { + label: "BUT 1Ăšre AnnĂ©e D", + value: "but-1A-d", + description: "Vous ĂȘtes en 1Ăšre AnnĂ©e de BUT (Groupe D)?" + }, + { + label: "BUT 1Ăšre AnnĂ©e E", + value: "but-1A-e", + description: "Vous ĂȘtes en 1Ăšre AnnĂ©e de BUT (Groupe E)?" + } +]; + +export const RolesDUT2AOptions = [ + { + label: "DUT 2Ăšme AnnĂ©e A", + value: "dut-2A-a", + description: "Vous ĂȘtes en 2Ăšme AnnĂ©e de DUT (Groupe A)?" + }, + { + label: "DUT 2Ăšme AnnĂ©e B", + value: "dut-2A-b", + description: "Vous ĂȘtes en 2Ăšme AnnĂ©e de DUT (Groupe B)?" + }, + { + label: "DUT 2Ăšme AnnĂ©e C", + value: "dut-2A-c", + description: "Vous ĂȘtes en 2Ăšme AnnĂ©e de DUT (Groupe C)?" + }, + { + label: "DUT 2Ăšme AnnĂ©e D", + value: "dut-2A-d", + description: "Vous ĂȘtes en 2Ăšme AnnĂ©e de DUT (Groupe D)?" + } +]; + +export const RolesAutreOptions = [ + { + label: "Enseignant du dĂ©partement", + value: "teacher", + description: "Vous ĂȘtes enseignant du DĂ©partement Informatique ?" + }, + { + label: "Membre de l'UniversitĂ© de Lorraine", + value: "membreUL", + description: "Vous ĂȘtes Ă©tudiant / enseignant / autre chose au sein de l'UniversitĂ© de Lorraine ?" + } +]; + +export const RolesAncienOptions = [ + /*{ + label: "Ancien LP ACORS", + value: "old-lp-ACORS", + description: "Vous ĂȘtes un ancien de la LP ACORS ?" + }, + { + label: "Ancien LP AFTER", + value: "old-lp-AFTER", + description: "Vous ĂȘtes un ancien de la LP AFTER ?" + },*/ + { + label: "Ancien LP CIASIE", + value: "old-lp-CIASIE", + description: "Vous ĂȘtes un ancien de la LP CIASIE ?" + }, + { + label: "Ancien DUT", + value: "old-DUT", + description: "Vous ĂȘtes un ancien du DUT ?" + } +]; + +export const RoleAlternantCIASIEOptions = [ + { + label: "Oui", + description: "Je suis en alternance", + value: "oui" + }, + { + label: "Non", + "description": "Je suis en formation classique", + value: "non" + } +] \ No newline at end of file diff --git a/iut_nc_depinfo/slashs/MessagesSelectionRoles.ts b/iut_nc_depinfo/slashs/MessagesSelectionRoles.ts new file mode 100644 index 0000000..3729386 --- /dev/null +++ b/iut_nc_depinfo/slashs/MessagesSelectionRoles.ts @@ -0,0 +1,102 @@ +import { CommandInteraction, MessageActionRow, MessageSelectMenu } from 'discord.js'; +import { DefaultPermission, Discord, Guild as Guildx, Permission, Slash, SlashGroup } from 'discordx'; +import { Serveur } from "../../IDs"; +import { Role } from '../IDs'; +import { RoleAlternantCIASIEOptions, RolesAncienOptions, RolesAutreOptions, RolesBUT1AOptions, RolesDUT2AOptions, RolesLPOptions } from '../selectMenus/Roles'; + +@Discord() +@Guildx(Serveur.IUT_NC_DEP_INFO) // Alias @Guild due to import name conflict +@DefaultPermission(false) +@Permission({ id: Role.ADMIN, type: 'ROLE', permission: true }) +@Permission({ id: Role.STAR, type: 'ROLE', permission: true }) +@SlashGroup("messageSelectionRoles", "Commandes ayant pour effet d'envoyer des messages permettant de choisir des rĂŽles") +abstract class MessagesSelectionRoles { + + @Slash('principaux', { description: "Envoie le message permettant d'obtenir les rĂŽles principaux" }) + async principaux(interaction: CommandInteraction) { + await interaction.deferReply({ ephemeral: true }); + + const channel = interaction.channel; + + if (!channel) { interaction.editReply({ content: "Erreur, channel: " + channel }); return; } + + if (!channel.isText()) interaction.reply("Type de salon inattendu."); + + const LPRow = new MessageActionRow() + .addComponents( + new MessageSelectMenu() + .setCustomId('role-lp') + .setPlaceholder("Licences Professionnelles") + .addOptions(RolesLPOptions) + ); + + const BUT1ARow = new MessageActionRow() + .addComponents( + new MessageSelectMenu() + .setCustomId('role-but-1a') + .setPlaceholder("BUT 1Ăšre AnnĂ©e") + .addOptions(RolesBUT1AOptions) + ); + + const DUT2ARow = new MessageActionRow() + .addComponents( + new MessageSelectMenu() + .setCustomId('role-dut-2a') + .setPlaceholder("DUT 2Ăšme AnnĂ©e") + .addOptions(RolesDUT2AOptions) + ); + + const AutreRow = new MessageActionRow() + .addComponents( + new MessageSelectMenu() + .setCustomId('role-other') + .setPlaceholder("Autre") + .addOptions(RolesAutreOptions) + ); + + const OldStudentRow = new MessageActionRow() + .addComponents( + new MessageSelectMenu() + .setCustomId('role-old-student') + .setPlaceholder("Ancien Ă©tudiant") + .addOptions(RolesAncienOptions) + ); + + try { + await channel.send({ content: "Bienvenue sur le Serveur du DĂ©partement Informatique de l'IUT Nancy-Charlemagne ! Veuillez sĂ©lectionner ce qui vous correspondant via le menu juste en dessous.", components: [LPRow, BUT1ARow, DUT2ARow, AutreRow, OldStudentRow] }); + } catch (err) { + interaction.editReply({ content: "Une erreur est survenue." }); + console.error(err) + } finally { + interaction.editReply({ content: "Done." }); + } + } + + @Slash('alternantLP', { description: "Envoie le message permettant d'obtenir le rĂŽle alternant pour la LP CIASIE" }) + async messageRoleAlternant(interaction: CommandInteraction) { + await interaction.deferReply({ ephemeral: true }); + + const channel = interaction.channel; + + if (!channel) { interaction.editReply({ content: "Erreur, channel: " + channel }); return; } + + if (!channel.isText()) interaction.reply("Type de salon inattendu."); + + const row = new MessageActionRow() + .addComponents( + new MessageSelectMenu() + .setCustomId('role-alternant') + .setPlaceholder("Veuillez sĂ©lectionner une rĂ©ponse") + .addOptions(RoleAlternantCIASIEOptions) + ); + + try { + await channel.send({ content: "Êtes-vous en alternance ? Si oui, vous pouvez obtenir un rĂŽle spĂ©cial afin de faciliter les mentions et avoir un salon regroupant les alternants.", components: [row] }); + } catch (err) { + interaction.editReply({ content: "Une erreur est survenue." }); + console.log(err) + } finally { + interaction.editReply({ content: "Done." }); + } + } +} \ No newline at end of file From e4a301752077a454e4525733eef42f9eb711ebed Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 08:26:52 +0200 Subject: [PATCH 13/29] =?UTF-8?q?D=C3=A9placement=20des=20commandes=20de?= =?UTF-8?q?=20maintenance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../slashs}/Maintenance.ts | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) rename {commands => iut_nc_depinfo/slashs}/Maintenance.ts (92%) diff --git a/commands/Maintenance.ts b/iut_nc_depinfo/slashs/Maintenance.ts similarity index 92% rename from commands/Maintenance.ts rename to iut_nc_depinfo/slashs/Maintenance.ts index 1bbb929..076ba7f 100644 --- a/commands/Maintenance.ts +++ b/iut_nc_depinfo/slashs/Maintenance.ts @@ -1,12 +1,13 @@ import { AwaitMessagesOptions, CategoryChannel, Channel, Collection, CommandInteraction, DMChannel, GuildChannel, Message, MessageActionRow, MessageButton, MessageEmbed, Snowflake } from "discord.js"; import { DefaultPermission, Discord, Guild, Permission, Slash, SlashGroup, SlashOption } from "discordx"; -import { RoleIDs, ServerIDs } from "../enums/IDs"; +import { Serveur } from "../../IDs"; +import { Role } from "../IDs"; @Discord() -@Guild(ServerIDs.MAIN) +@Guild(Serveur.IUT_NC_DEP_INFO) @DefaultPermission(false) -@Permission({ id: RoleIDs.ADMIN, type: 'ROLE', permission: true }) -@Permission({ id: RoleIDs.STAR, type: 'ROLE', permission: true }) +@Permission({ id: Role.ADMIN, type: 'ROLE', permission: true }) +@Permission({ id: Role.STAR, type: 'ROLE', permission: true }) @SlashGroup("maintenance", "Commandes de maintenance du serveur") abstract class Maintenance { @@ -41,9 +42,9 @@ abstract class Maintenance { reason: `CrĂ©ation du salon demandĂ© par ${interaction.user.username} via la commande 'setupCategorieScolaire'` }); - await annoncementChannel?.permissionOverwrites.edit(RoleIDs.EVERYONE, { "SEND_MESSAGES": false }); - await annoncementChannel?.permissionOverwrites.edit(RoleIDs.DÉLÉGUÉ, { "SEND_MESSAGES": true }); - await annoncementChannel?.permissionOverwrites.edit(RoleIDs.ENSEIGNANT, { "SEND_MESSAGES": true }); + await annoncementChannel?.permissionOverwrites.edit(Role.EVERYONE, { "SEND_MESSAGES": false }); + await annoncementChannel?.permissionOverwrites.edit(Role.DÉLÉGUÉ, { "SEND_MESSAGES": true }); + await annoncementChannel?.permissionOverwrites.edit(Role.ENSEIGNANT, { "SEND_MESSAGES": true }); } if (createDocuments) { @@ -54,9 +55,9 @@ abstract class Maintenance { reason: `CrĂ©ation du salon demandĂ© par ${interaction.user.username} via la commande 'setupCategorieScolaire'` }); - await documentChannel?.permissionOverwrites.edit(RoleIDs.EVERYONE, { "SEND_MESSAGES": false }); - await documentChannel?.permissionOverwrites.edit(RoleIDs.DÉLÉGUÉ, { "SEND_MESSAGES": true }); - await documentChannel?.permissionOverwrites.edit(RoleIDs.ENSEIGNANT, { "SEND_MESSAGES": true }); + await documentChannel?.permissionOverwrites.edit(Role.EVERYONE, { "SEND_MESSAGES": false }); + await documentChannel?.permissionOverwrites.edit(Role.DÉLÉGUÉ, { "SEND_MESSAGES": true }); + await documentChannel?.permissionOverwrites.edit(Role.ENSEIGNANT, { "SEND_MESSAGES": true }); } if (createOffreDeStage) { @@ -67,9 +68,9 @@ abstract class Maintenance { reason: `CrĂ©ation du salon demandĂ© par ${interaction.user.username} via la commande 'setupCategorieScolaire'` }); - await offreDeStageChannel?.permissionOverwrites.edit(RoleIDs.EVERYONE, { "SEND_MESSAGES": false }); - await offreDeStageChannel?.permissionOverwrites.edit(RoleIDs.DÉLÉGUÉ, { "SEND_MESSAGES": true }); - await offreDeStageChannel?.permissionOverwrites.edit(RoleIDs.ENSEIGNANT, { "SEND_MESSAGES": true }); + await offreDeStageChannel?.permissionOverwrites.edit(Role.EVERYONE, { "SEND_MESSAGES": false }); + await offreDeStageChannel?.permissionOverwrites.edit(Role.DÉLÉGUÉ, { "SEND_MESSAGES": true }); + await offreDeStageChannel?.permissionOverwrites.edit(Role.ENSEIGNANT, { "SEND_MESSAGES": true }); } const discussionsChannel = await guild?.channels.create("đŸ’Źăƒ»discussions", { @@ -94,8 +95,8 @@ abstract class Maintenance { reason: `CrĂ©ation du salon demandĂ© par ${interaction.user.username} via la commande 'setupCategorieScolaire'` }); - await amphiChannel?.permissionOverwrites.edit(RoleIDs.ENSEIGNANT, { "MANAGE_CHANNELS": true, "MUTE_MEMBERS": true, "MOVE_MEMBERS": true }); - await amphiChannel?.permissionOverwrites.edit(RoleIDs.DÉLÉGUÉ, { "MANAGE_CHANNELS": true, "MUTE_MEMBERS": true, "MOVE_MEMBERS": true }); + await amphiChannel?.permissionOverwrites.edit(Role.ENSEIGNANT, { "MANAGE_CHANNELS": true, "MUTE_MEMBERS": true, "MOVE_MEMBERS": true }); + await amphiChannel?.permissionOverwrites.edit(Role.DÉLÉGUÉ, { "MANAGE_CHANNELS": true, "MUTE_MEMBERS": true, "MOVE_MEMBERS": true }); await guild?.channels.create("đŸ’»ăƒ»Vocal #1", { type: "GUILD_VOICE", From 8d5659943947793d82427e4fd9d282783f00d32f Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 13:49:30 +0200 Subject: [PATCH 14/29] Extraction de maintenance --- global/slashs/Maintenance.ts | 117 +++++++++++++++++++++++++++ iut_nc_depinfo/slashs/Maintenance.ts | 108 +------------------------ 2 files changed, 118 insertions(+), 107 deletions(-) create mode 100644 global/slashs/Maintenance.ts diff --git a/global/slashs/Maintenance.ts b/global/slashs/Maintenance.ts new file mode 100644 index 0000000..65a231f --- /dev/null +++ b/global/slashs/Maintenance.ts @@ -0,0 +1,117 @@ +import { AwaitMessagesOptions, CategoryChannel, Channel, Collection, CommandInteraction, DMChannel, GuildChannel, Message, MessageActionRow, MessageButton, MessageEmbed, Snowflake } from "discord.js"; +import { DefaultPermission, Discord, Guild, Permission, Slash, SlashGroup, SlashOption } from "discordx"; +import { allServeursIds, globalAdminPerms } from "../GlobalVar"; + +@Discord() +@Guild(...allServeursIds) +@DefaultPermission(false) +@Permission(...globalAdminPerms) +@SlashGroup("maintenance", "Commandes de maintenance du serveur") +abstract class Maintenance { + + @Slash('deleteMessages', { description: "Supprime les derniers messages envoyĂ©s il y a moins de 2 semaines. Supprime 100 messages par dĂ©faut" }) + async deleteMessages( + @SlashOption('nombre', { description: "Nombre de message Ă  effacer" }) + amount: number, + @SlashOption('jours', { description: "AnciennetĂ© des messages Ă  supprimer en jours" }) + days: number = 0, + @SlashOption('heures', { description: "AnciennetĂ© des messages Ă  supprimer en heures" }) + hours: number = 0, + @SlashOption('minutes', { description: "AnciennetĂ© des messages Ă  supprimer en minutes" }) + minutes: number = 0, + interaction: CommandInteraction + ) { + await interaction.deferReply({ ephemeral: true }) + + const channel = interaction.channel; + + if (!channel) { interaction.editReply({ content: "Erreur, channel: " + channel }); return; } + + if (channel?.type === "DM") { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande en message privĂ©." }); return; } + + let messageList: Collection = new Collection(); + + if (days || hours || minutes) { + const time: number = days * 8.64e+7 + hours * 3.6e+6 + minutes * 60000; + + let Options: AwaitMessagesOptions = { + time + } + + if (amount) + Options.max = amount + + const maxTimestamp = new Date(Date.now() - time); + + messageList = (await channel.messages.fetch()).filter(message => message.createdAt >= maxTimestamp); + } + + const deletedMessages = await channel.bulkDelete((messageList || amount || 100), true); + const notDeletedMessageAmount = (messageList?.size || amount || 100) - deletedMessages.size; + + let replyMessage: string = `${deletedMessages.size} ${deletedMessages.size > 1 ? "messages ont Ă©tĂ© supprimĂ©s" : "message a Ă©tĂ© supprimĂ©"}.` + + if (notDeletedMessageAmount !== 0) + replyMessage += ` ${notDeletedMessageAmount} ${notDeletedMessageAmount > 1 ? "messages n'ont pas pu ĂȘtre supprimĂ©s" : "message n'a pas pu ĂȘtre supprimĂ©"}. Cela est peut ĂȘtre dĂ» Ă  la limitation de 2 semaines de Discord (Ou qu'il n'y avait pas autant de message dans le salon). Pour supprimer tout un salon vous pouvez utiliser \`/purgechannel\`.`; + + interaction.reply({ content: replyMessage }) + } + + @Slash('purgeChannel', { description: "Clone et supprime le salon afin de supprimer son contenu" }) + async purgeChannel( + @SlashOption("channel", { description: "Salon Ă  purger. Salon actuel par dĂ©faut", type: "CHANNEL", required: true }) + channel: GuildChannel | DMChannel, + interaction: CommandInteraction + ) { + await interaction.deferReply({ ephemeral: true }); + + if (channel.isThread()) { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande sur un Fil" }); return; } + if (channel.type === "DM") { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande en message privĂ© sans indiquer un salon prĂ©cis." }); return; } + + const newChannel = await channel.clone({ reason: `Purge du salon demandĂ© par ${interaction.user.username}` }); + await channel.delete(); + + if (channel !== interaction.channel) + interaction.editReply({ content: `Salon purgĂ© ! ${newChannel}` }); + } + + @Slash('webhook', { description: "Retourne le lien d'un webhook crĂ©Ă© par le bot" }) + async webhook( + @SlashOption("Salon", { type: "CHANNEL", required: true }) + channel: GuildChannel | DMChannel, + interaction: CommandInteraction + ) { + await interaction.deferReply({ ephemeral: true }); + + if (channel.isThread()) { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande sur un Fil" }); return; } + if (channel.type === "DM") { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande en message privĂ© sans indiquer un salon prĂ©cis." }); return; } + if (!channel.isText()) { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande sur un salon non-textuel." }); return; } + + const webhooks = await channel.fetchWebhooks(); + + let webhook = webhooks.find(webhook => { + if (webhook.owner === null || interaction.client === null || interaction.client.user === null) return false; + if (!webhook.owner.bot) return false; + if (webhook.owner.id !== interaction.client.user.id) return false; + return true; + }); + + if (!webhook) { + webhook = await channel.createWebhook("Embeds", { reason: `CrĂ©ation du webhook demandĂ© par ${interaction.user.username}` }); + } + + const embed = new MessageEmbed() + .setTitle("Votre webhook") + .setDescription(`\`${webhook.url}\``) + .setColor('#0080ff'); + + const row = new MessageActionRow() + .addComponents(new MessageButton() + .setStyle("LINK") + .setLabel("Ouvrir avec Discord.club (SOON)") + .setURL(`https://discord.club/dashboard?`) + .setDisabled(true)); + + interaction.editReply({ embeds: [embed], components: [row] }) + } +} \ No newline at end of file diff --git a/iut_nc_depinfo/slashs/Maintenance.ts b/iut_nc_depinfo/slashs/Maintenance.ts index 076ba7f..8701007 100644 --- a/iut_nc_depinfo/slashs/Maintenance.ts +++ b/iut_nc_depinfo/slashs/Maintenance.ts @@ -1,4 +1,4 @@ -import { AwaitMessagesOptions, CategoryChannel, Channel, Collection, CommandInteraction, DMChannel, GuildChannel, Message, MessageActionRow, MessageButton, MessageEmbed, Snowflake } from "discord.js"; +import { CategoryChannel, Channel, CommandInteraction } from "discord.js"; import { DefaultPermission, Discord, Guild, Permission, Slash, SlashGroup, SlashOption } from "discordx"; import { Serveur } from "../../IDs"; import { Role } from "../IDs"; @@ -114,110 +114,4 @@ abstract class Maintenance { interaction.editReply({ content: `Les salons ont Ă©tĂ© crĂ©Ă©s !` }); } - - @Slash('deleteMessages', { description: "Supprime les derniers messages envoyĂ©s il y a moins de 2 semaines. Supprime 100 messages par dĂ©faut" }) - async deleteMessages( - @SlashOption('nombre', { description: "Nombre de message Ă  effacer" }) - amount: number, - @SlashOption('jours', { description: "AnciennetĂ© des messages Ă  supprimer en jours" }) - days: number = 0, - @SlashOption('heures', { description: "AnciennetĂ© des messages Ă  supprimer en heures" }) - hours: number = 0, - @SlashOption('minutes', { description: "AnciennetĂ© des messages Ă  supprimer en minutes" }) - minutes: number = 0, - interaction: CommandInteraction - ) { - await interaction.deferReply({ ephemeral: true }) - - const channel = interaction.channel; - - if (!channel) { interaction.editReply({ content: "Erreur, channel: " + channel }); return; } - - if (channel?.type === "DM") { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande en message privĂ©." }); return; } - - let messageList: Collection = new Collection(); - - if (days || hours || minutes) { - const time: number = days * 8.64e+7 + hours * 3.6e+6 + minutes * 60000; - - let Options: AwaitMessagesOptions = { - time - } - - if (amount) - Options.max = amount - - const maxTimestamp = new Date(Date.now() - time); - - messageList = (await channel.messages.fetch()).filter(message => message.createdAt >= maxTimestamp); - } - - const deletedMessages = await channel.bulkDelete((messageList || amount || 100), true); - const notDeletedMessageAmount = (messageList?.size || amount || 100) - deletedMessages.size; - - let replyMessage: string = `${deletedMessages.size} ${deletedMessages.size > 1 ? "messages ont Ă©tĂ© supprimĂ©s" : "message a Ă©tĂ© supprimĂ©"}.` - - if (notDeletedMessageAmount !== 0) - replyMessage += ` ${notDeletedMessageAmount} ${notDeletedMessageAmount > 1 ? "messages n'ont pas pu ĂȘtre supprimĂ©s" : "message n'a pas pu ĂȘtre supprimĂ©"}. Cela est peut ĂȘtre dĂ» Ă  la limitation de 2 semaines de Discord (Ou qu'il n'y avait pas autant de message dans le salon). Pour supprimer tout un salon vous pouvez utiliser \`/purgechannel\`.`; - - interaction.reply({ content: replyMessage }) - } - - @Slash('purgeChannel', { description: "Clone et supprime le salon afin de supprimer son contenu" }) - async purgeChannel( - @SlashOption("channel", { description: "Salon Ă  purger. Salon actuel par dĂ©faut", type: "CHANNEL", required: true }) - channel: GuildChannel | DMChannel, - interaction: CommandInteraction - ) { - await interaction.deferReply({ ephemeral: true }); - - if (channel.isThread()) { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande sur un Fil" }); return; } - if (channel.type === "DM") { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande en message privĂ© sans indiquer un salon prĂ©cis." }); return; } - - const newChannel = await channel.clone({ reason: `Purge du salon demandĂ© par ${interaction.user.username}` }); - await channel.delete(); - - if (channel !== interaction.channel) - interaction.editReply({ content: `Salon purgĂ© ! ${newChannel}` }); - } - - @Slash('webhook', { description: "Retourne le lien d'un webhook crĂ©Ă© par le bot" }) - async webhook( - @SlashOption("Salon", { type: "CHANNEL", required: true }) - channel: GuildChannel | DMChannel, - interaction: CommandInteraction - ) { - await interaction.deferReply({ ephemeral: true }); - - if (channel.isThread()) { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande sur un Fil" }); return; } - if (channel.type === "DM") { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande en message privĂ© sans indiquer un salon prĂ©cis." }); return; } - if (!channel.isText()) { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande sur un salon non-textuel." }); return; } - - const webhooks = await channel.fetchWebhooks(); - - let webhook = webhooks.find(webhook => { - if (webhook.owner === null || interaction.client === null || interaction.client.user === null) return false; - if (!webhook.owner.bot) return false; - if (webhook.owner.id !== interaction.client.user.id) return false; - return true; - }); - - if (!webhook) { - webhook = await channel.createWebhook("Embeds", { reason: `CrĂ©ation du webhook demandĂ© par ${interaction.user.username}` }); - } - - const embed = new MessageEmbed() - .setTitle("Votre webhook") - .setDescription(`\`${webhook.url}\``) - .setColor('#0080ff'); - - const row = new MessageActionRow() - .addComponents(new MessageButton() - .setStyle("LINK") - .setLabel("Ouvrir avec Discord.club (SOON)") - .setURL(`https://discord.club/dashboard?`) - .setDisabled(true)); - - interaction.editReply({ embeds: [embed], components: [row] }) - } } \ No newline at end of file From 1d34791285d82f1b84eee25fc7d94d4fb4373297 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 13:50:22 +0200 Subject: [PATCH 15/29] Create GlobalVar.ts --- global/GlobalVar.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 global/GlobalVar.ts diff --git a/global/GlobalVar.ts b/global/GlobalVar.ts new file mode 100644 index 0000000..9027a11 --- /dev/null +++ b/global/GlobalVar.ts @@ -0,0 +1,17 @@ +import { ApplicationCommandPermissionData } from "discord.js"; +import { Serveur } from "../IDs"; +import { Role as Role_IUT_NC_DEPINFO } from "../iut_nc_depinfo/IDs"; + +export const globalAdminPerms: ApplicationCommandPermissionData[] = [ + { id: Role_IUT_NC_DEPINFO.STAR, type: "ROLE", permission: true }, + { id: Role_IUT_NC_DEPINFO.ADMIN, type: "ROLE", permission: true } +] + +export const globalEnseignantPerms: ApplicationCommandPermissionData[] = [ + { id: Role_IUT_NC_DEPINFO.ENSEIGNANT, type: "ROLE", permission: true } +] + +export const allServeursIds: Serveur[] = [ + Serveur.IUT_NC_DEP_INFO, + Serveur.IUT_NC_DEP_INFO2 +] \ No newline at end of file From df820f9d1156e0c04555f6afbf8030ea721c4079 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 13:50:31 +0200 Subject: [PATCH 16/29] sort import --- global/slashs/Fun.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/global/slashs/Fun.ts b/global/slashs/Fun.ts index 09f1a34..43f32a9 100644 --- a/global/slashs/Fun.ts +++ b/global/slashs/Fun.ts @@ -1,5 +1,5 @@ -import { CommandInteraction, MessageActionRow, MessageButton } from "discord.js"; -import { DefaultPermission, Discord, Slash, SlashChoice, SlashGroup, SlashOption } from "discordx"; +import { CommandInteraction, MessageActionRow } from "discord.js"; +import { Discord, Slash, SlashChoice, SlashGroup, SlashOption } from "discordx"; import { pfcButtons, pfcChoix, pfcIsWin, pfcPlayBot, pfcProposition, pfcTraitementResultat } from "../../libs/pfc"; @Discord() From b9461b0f8087b296cd8677b48847b28bb0acdd80 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 17:51:49 +0200 Subject: [PATCH 17/29] add npm script debug (sans les logs en fichier) --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d1b5d18..569b2b3 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.ts", "scripts": { "start": "./scripts/main_bot.bash", - "twitter": "./scripts/twitter_bot.bash" + "twitter": "./scripts/twitter_bot.bash", + "debug": "ts-node ." }, "repository": { "type": "git", @@ -30,4 +31,4 @@ "ts-node": "^10.2.1", "typescript": "^4.4.2" } -} +} \ No newline at end of file From 0758dc5f5347b2b21a874d6bd881ff541e0bddc1 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 17:52:00 +0200 Subject: [PATCH 18/29] update discordx --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index a07e55a..67c8217 100644 --- a/package-lock.json +++ b/package-lock.json @@ -352,9 +352,9 @@ } }, "node_modules/discordx": { - "version": "5.9.1", - "resolved": "https://registry.npmjs.org/discordx/-/discordx-5.9.1.tgz", - "integrity": "sha512-hZS4k2kbRFaZ9oGa9qEFPX7hcBitmBQ8CEeT1uNQHf4TJUmGwgRV02MIRJKCKkIpDn7CTMAE0WdG6q+rUtO6Xg==", + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/discordx/-/discordx-5.9.3.tgz", + "integrity": "sha512-X1lZO6z0EH7tn3Mg/68Jc0Qe6bVHllgSDEmd4ftQ8iSwigRMHloqAOnoj8wI/aSVex3KIDWlbSm2TRlkv7cEOw==", "dependencies": { "discord.js": "^13.1.0", "glob": "^7.1.7", @@ -1239,9 +1239,9 @@ } }, "discordx": { - "version": "5.9.1", - "resolved": "https://registry.npmjs.org/discordx/-/discordx-5.9.1.tgz", - "integrity": "sha512-hZS4k2kbRFaZ9oGa9qEFPX7hcBitmBQ8CEeT1uNQHf4TJUmGwgRV02MIRJKCKkIpDn7CTMAE0WdG6q+rUtO6Xg==", + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/discordx/-/discordx-5.9.3.tgz", + "integrity": "sha512-X1lZO6z0EH7tn3Mg/68Jc0Qe6bVHllgSDEmd4ftQ8iSwigRMHloqAOnoj8wI/aSVex3KIDWlbSm2TRlkv7cEOw==", "requires": { "discord.js": "^13.1.0", "glob": "^7.1.7", From 42ac1d04b868983bec0875a9e4c2fc7913b8c9fd Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Thu, 16 Sep 2021 18:04:08 +0200 Subject: [PATCH 19/29] rename mod group et extration en global de la commande webhook --- global/slashs/Divers.ts | 44 +++++++++++++++++++++++++++++++++++- global/slashs/Maintenance.ts | 43 ++--------------------------------- 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/global/slashs/Divers.ts b/global/slashs/Divers.ts index b753ec8..38ecfcb 100644 --- a/global/slashs/Divers.ts +++ b/global/slashs/Divers.ts @@ -1,4 +1,4 @@ -import { CommandInteraction, Message, MessageEmbed } from "discord.js"; +import { CommandInteraction, DMChannel, GuildChannel, Message, MessageActionRow, MessageButton, MessageEmbed } from "discord.js"; import { Discord, Slash, SlashOption } from "discordx"; @Discord() @@ -44,4 +44,46 @@ abstract class Divers { try { interaction.editReply("Erreur, vĂ©rification des logs."); } catch (err) { console.error(err); return; } } } + + @Slash('webhook', { description: "Retourne le lien d'un webhook crĂ©Ă© par le bot" }) + async webhook( + @SlashOption("Salon", { type: "CHANNEL", required: true }) + channel: GuildChannel | DMChannel, + interaction: CommandInteraction + ) { + await interaction.deferReply({ ephemeral: true }); + + if (channel.isThread()) { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande sur un Fil" }); return; } + if (channel.type === "DM") { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande en message privĂ© sans indiquer un salon prĂ©cis." }); return; } + if (!channel.isText()) { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande sur un salon non-textuel." }); return; } + + if (!(channel.permissionsFor(interaction.user)?.has("MANAGE_WEBHOOKS"))) { interaction.editReply({ content: `❌ DĂ©solĂ© mais tu n'as pas la permission "MANAGE_WEBHOOKS".` }); return; } + + const webhooks = await channel.fetchWebhooks(); + + let webhook = webhooks.find(webhook => { + if (webhook.owner === null || interaction.client === null || interaction.client.user === null) return false; + if (!webhook.owner.bot) return false; + if (webhook.owner.id !== interaction.client.user.id) return false; + return true; + }); + + if (!webhook) { + webhook = await channel.createWebhook("Embeds", { reason: `CrĂ©ation du webhook demandĂ© par ${interaction.user.username}` }); + } + + const embed = new MessageEmbed() + .setTitle("Votre webhook") + .setDescription(`\`${webhook.url}\``) + .setColor('#0080ff'); + + const row = new MessageActionRow() + .addComponents(new MessageButton() + .setStyle("LINK") + .setLabel("Ouvrir avec Discord.club (SOON)") + .setURL(`https://discord.club/dashboard?`) + .setDisabled(true)); + + interaction.editReply({ embeds: [embed], components: [row] }) + } } \ No newline at end of file diff --git a/global/slashs/Maintenance.ts b/global/slashs/Maintenance.ts index 65a231f..de815cc 100644 --- a/global/slashs/Maintenance.ts +++ b/global/slashs/Maintenance.ts @@ -1,4 +1,4 @@ -import { AwaitMessagesOptions, CategoryChannel, Channel, Collection, CommandInteraction, DMChannel, GuildChannel, Message, MessageActionRow, MessageButton, MessageEmbed, Snowflake } from "discord.js"; +import { AwaitMessagesOptions, Collection, CommandInteraction, DMChannel, GuildChannel, Message, Snowflake } from "discord.js"; import { DefaultPermission, Discord, Guild, Permission, Slash, SlashGroup, SlashOption } from "discordx"; import { allServeursIds, globalAdminPerms } from "../GlobalVar"; @@ -6,7 +6,7 @@ import { allServeursIds, globalAdminPerms } from "../GlobalVar"; @Guild(...allServeursIds) @DefaultPermission(false) @Permission(...globalAdminPerms) -@SlashGroup("maintenance", "Commandes de maintenance du serveur") +@SlashGroup("mod", "Commandes de modĂ©ration") abstract class Maintenance { @Slash('deleteMessages', { description: "Supprime les derniers messages envoyĂ©s il y a moins de 2 semaines. Supprime 100 messages par dĂ©faut" }) @@ -75,43 +75,4 @@ abstract class Maintenance { interaction.editReply({ content: `Salon purgĂ© ! ${newChannel}` }); } - @Slash('webhook', { description: "Retourne le lien d'un webhook crĂ©Ă© par le bot" }) - async webhook( - @SlashOption("Salon", { type: "CHANNEL", required: true }) - channel: GuildChannel | DMChannel, - interaction: CommandInteraction - ) { - await interaction.deferReply({ ephemeral: true }); - - if (channel.isThread()) { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande sur un Fil" }); return; } - if (channel.type === "DM") { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande en message privĂ© sans indiquer un salon prĂ©cis." }); return; } - if (!channel.isText()) { interaction.editReply({ content: "❌ DĂ©solĂ© mais je ne peux pas effectuer cette commande sur un salon non-textuel." }); return; } - - const webhooks = await channel.fetchWebhooks(); - - let webhook = webhooks.find(webhook => { - if (webhook.owner === null || interaction.client === null || interaction.client.user === null) return false; - if (!webhook.owner.bot) return false; - if (webhook.owner.id !== interaction.client.user.id) return false; - return true; - }); - - if (!webhook) { - webhook = await channel.createWebhook("Embeds", { reason: `CrĂ©ation du webhook demandĂ© par ${interaction.user.username}` }); - } - - const embed = new MessageEmbed() - .setTitle("Votre webhook") - .setDescription(`\`${webhook.url}\``) - .setColor('#0080ff'); - - const row = new MessageActionRow() - .addComponents(new MessageButton() - .setStyle("LINK") - .setLabel("Ouvrir avec Discord.club (SOON)") - .setURL(`https://discord.club/dashboard?`) - .setDisabled(true)); - - interaction.editReply({ embeds: [embed], components: [row] }) - } } \ No newline at end of file From 14e68d0b37aa043e3977a90cc4c8e5037ff91ef8 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Fri, 17 Sep 2021 02:22:15 +0200 Subject: [PATCH 20/29] =?UTF-8?q?D=C3=A9placement=20de=20util.ts=20dans=20?= =?UTF-8?q?libs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/Enseignant.ts | 71 ----------------------------------------- index.ts | 2 +- util.ts => libs/util.ts | 4 ++- 3 files changed, 4 insertions(+), 73 deletions(-) delete mode 100644 commands/Enseignant.ts rename util.ts => libs/util.ts (86%) diff --git a/commands/Enseignant.ts b/commands/Enseignant.ts deleted file mode 100644 index f2e23ce..0000000 --- a/commands/Enseignant.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { CommandInteraction, VoiceChannel } from "discord.js"; -import { DefaultPermission, Discord, Guild, Permission, Slash, SlashOption } from "discordx"; -import { RoleIDs, ServerIDs } from "../enums/IDs"; - -@Discord() -@Guild(ServerIDs.MAIN) -@DefaultPermission(false) -@Permission({ id: RoleIDs.ADMIN, type: 'ROLE', permission: true }) -@Permission({ id: RoleIDs.STAR, type: 'ROLE', permission: true }) -@Permission({ id: RoleIDs.ENSEIGNANT, type: 'ROLE', permission: true }) -abstract class Enseignant { - - @Slash('groupevocal', { description: "CrĂ©e un ou plusieurs salons vocaux temporaire dans cette catĂ©gorie (1 salon pendant 60m par dĂ©faut)" }) - private async groupevocal( - @SlashOption('quantitĂ©', { description: "Nombre de salon Ă  crĂ©er. (10 salon max)" }) - amount: number = 1, - @SlashOption('durĂ©e', { description: "DurĂ©e du salon avant sa suppression en minute. (240 minutes = 4 heures max)" }) - duration: number = 60, - interaction: CommandInteraction - ) { - if (amount <= 0) { interaction.reply({ content: "DĂ©solĂ© cependant vous ne pouvez crĂ©er une quantitĂ© nĂ©gative ou nulle de salon.", ephemeral: true }); return; } - if (duration <= 0) { interaction.reply({ content: "DĂ©solĂ© cependant vous ne pouvez crĂ©er de salon pour une durĂ©e nĂ©gative ou nulle.", ephemeral: true }); return; } - - if (amount > 10) { interaction.reply({ content: "DĂ©solĂ© cependant vous ne pouvez pas crĂ©er plus de 10 salons Ă  la fois.", ephemeral: true }); return; } - if (duration > 240) { interaction.reply({ content: "DĂ©solĂ© cependant vous ne pouvez crĂ©er de salon durant plus de 4 heures.", ephemeral: true }); return; } - - if (interaction.channel?.type !== "GUILD_TEXT") { return; } - - const category = interaction.channel?.parent; - - if (!category) { interaction.reply({ content: "DĂ©solĂ© cependant ce salon n'a pas de catĂ©gorie.", ephemeral: true }); return; } - - const guild = interaction.guild; - - if (!guild) { interaction.reply({ content: `Une erreur est survenue (guild: ${guild})`, ephemeral: true }); return; } - - await interaction.deferReply(); - - let newSalonsPromise: Promise[] = []; - - for (let i = 0; i < amount; i++) { - newSalonsPromise.push(guild.channels.create(`đŸ’»ăƒ»Groupe ${i + 1}`, { - type: "GUILD_VOICE", - parent: category, - reason: `Salon vocal de groupe temporaire crĂ©Ă© par ${interaction.user.username}` - })); - } - - interaction.editReply({ content: "Votre demande est en cours de traitement..." }) - - const newChannels = await Promise.all(newSalonsPromise); - - newChannels.forEach(async salon => { - salon.permissionOverwrites.create(interaction.user, { 'MANAGE_CHANNELS': true }, { reason: "Permissions donnĂ©es au crĂ©ateur du salon" }); - setTimeout((salon: VoiceChannel) => { - salon.delete(); - }, duration * 60000, salon); - }); - - interaction.editReply({ content: `Vos ${amount} salons ont Ă©tĂ© crĂ©Ă© pour ${duration} minutes. \`${duration} minutes restantes\`` }); - - let minutesSpend = 0; - const intervalID = setInterval( - (interaction: CommandInteraction, minutesSpend: number) => { - interaction.editReply({ content: `Vos ${amount} salons ont Ă©tĂ© crĂ©Ă© pour ${duration} minutes. \`${duration - minutesSpend} minutes restantes\`` }); - minutesSpend++ - }, 60000, interaction, ++minutesSpend); - - setTimeout((intervalID, interaction: CommandInteraction) => { clearInterval(intervalID); interaction.editReply({ content: `Temps Ă©coulĂ© ! Vos salons ont Ă©tĂ© supprimĂ©s.` }) }, duration * 60000, intervalID, interaction); - } -} \ No newline at end of file diff --git a/index.ts b/index.ts index 4197b9a..d3f326c 100644 --- a/index.ts +++ b/index.ts @@ -2,7 +2,7 @@ require('dotenv').config() import { Intents } from 'discord.js'; import { Client } from 'discordx'; import 'reflect-metadata'; -import { getHorodateConsole, logInteraction, resetPresence } from './util'; +import { getHorodateConsole, logInteraction, resetPresence } from './libs/util'; export let SingletonClient: Client; diff --git a/util.ts b/libs/util.ts similarity index 86% rename from util.ts rename to libs/util.ts index c35e0a4..95ad7a3 100644 --- a/util.ts +++ b/libs/util.ts @@ -8,7 +8,7 @@ export function getHorodateConsole() { } export function logInteraction(interaction: Interaction, client: Client) { - let log = `${getHorodateConsole()}\t${interaction.user.username}\t${interaction.type}` + let log = `${getHorodateConsole()}\t${interaction.guild?.name}\t${interaction.user.username}\t${interaction.type}` if (interaction.isCommand()) log += `\t${interaction.commandName}`; @@ -21,6 +21,8 @@ export function logInteraction(interaction: Interaction, client: Client) { } if (interaction.isContextMenu()) { + log += `\t${interaction.commandName}`; + if (interaction.targetType === "USER") log += `\t${client.users.resolve(interaction.targetId)?.username}`; else if (interaction.targetType === "MESSAGE") From e958a2312a4e7df81d75588647b04efc2e6fc89e Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Fri, 17 Sep 2021 02:22:25 +0200 Subject: [PATCH 21/29] Ajout de debug twitter --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 569b2b3..08a0eb4 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "start": "./scripts/main_bot.bash", "twitter": "./scripts/twitter_bot.bash", - "debug": "ts-node ." + "debug": "ts-node .", + "debug twitter": "ts-node twitter.ts" }, "repository": { "type": "git", From 472ff7f0d80c518708718fa3a7807dd698bb5e75 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Fri, 17 Sep 2021 02:22:35 +0200 Subject: [PATCH 22/29] dep util --- twitter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twitter.ts b/twitter.ts index 20897cd..f98a400 100644 --- a/twitter.ts +++ b/twitter.ts @@ -2,7 +2,7 @@ require('dotenv').config() import { Client } from 'discord.js'; import * as fs from 'fs'; import * as Twit from 'twit'; -import { getHorodateConsole, resetPresence } from './util'; +import { getHorodateConsole, resetPresence } from './libs/util'; export let SingletonClient: Client; From 0a3a2933f504e28a4ffab3182dafcf2e56688e10 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Fri, 17 Sep 2021 02:22:51 +0200 Subject: [PATCH 23/29] Ajout balise console.log --- index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index d3f326c..9e8dd57 100644 --- a/index.ts +++ b/index.ts @@ -33,7 +33,7 @@ async function start() { SingletonClient.once("ready", async () => { await SingletonClient.initApplicationCommands(); - console.log(`${getHorodateConsole()}\tReady !`); + console.log(`${getHorodateConsole()}\t[INFO]\tReady !`); if (SingletonClient.user) resetPresence(SingletonClient.user); @@ -48,10 +48,10 @@ async function start() { } function handleExit(signal: NodeJS.Signals) { - console.info(`${getHorodateConsole()} Signal ${signal} reçu.`); + console.info(`${getHorodateConsole()}\t[STOP]\tSignal ${signal} reçu.`); SingletonClient.user?.setPresence({ status: "idle", activities: [{ name: "ArrĂȘt en cours", type: "COMPETING" }] }) SingletonClient.destroy(); - console.log(`${getHorodateConsole()} ArrĂȘt du bot.`); + console.log(`${getHorodateConsole()}\t[STOP]\tArrĂȘt du bot.`); process.exit(0); } From b1e9ab1f688a899016e080e7ce2ce9f76bc047de Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Fri, 17 Sep 2021 02:23:00 +0200 Subject: [PATCH 24/29] =?UTF-8?q?Ajout=20des=20ids=20B=C3=AAta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IDs.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/IDs.ts b/IDs.ts index f0bac22..74aae78 100644 --- a/IDs.ts +++ b/IDs.ts @@ -1,3 +1,10 @@ export enum Serveur { - IUT_NC_DEP_INFO = "753171392450527282" + IUT_NC_DEP_INFO = "753171392450527282", + BETA_1 = "885296615089397790", + BETA_2 = "888005290333712384" +} + +export enum RoleBeta { + BETA_1 = "887875935175573545", + BETA_2 = "888005290333712385" } \ No newline at end of file From a444eece0502d074d701a891289ca3a613dc8c4c Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Fri, 17 Sep 2021 02:23:15 +0200 Subject: [PATCH 25/29] =?UTF-8?q?Renammage=20en=20Mod=C3=A9ration.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Maintenance.ts => "global/slashs/Mod\303\251ration.ts" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename global/slashs/Maintenance.ts => "global/slashs/Mod\303\251ration.ts" (99%) diff --git a/global/slashs/Maintenance.ts "b/global/slashs/Mod\303\251ration.ts" similarity index 99% rename from global/slashs/Maintenance.ts rename to "global/slashs/Mod\303\251ration.ts" index de815cc..f2e1935 100644 --- a/global/slashs/Maintenance.ts +++ "b/global/slashs/Mod\303\251ration.ts" @@ -7,7 +7,7 @@ import { allServeursIds, globalAdminPerms } from "../GlobalVar"; @DefaultPermission(false) @Permission(...globalAdminPerms) @SlashGroup("mod", "Commandes de modĂ©ration") -abstract class Maintenance { +abstract class ModĂ©ration { @Slash('deleteMessages', { description: "Supprime les derniers messages envoyĂ©s il y a moins de 2 semaines. Supprime 100 messages par dĂ©faut" }) async deleteMessages( From 7e0e90120db8884f61a747ed8044e08f342d429a Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Fri, 17 Sep 2021 02:23:38 +0200 Subject: [PATCH 26/29] Export de groupevocal --- global/slashs/Divers.ts | 68 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/global/slashs/Divers.ts b/global/slashs/Divers.ts index 38ecfcb..70fe279 100644 --- a/global/slashs/Divers.ts +++ b/global/slashs/Divers.ts @@ -1,5 +1,6 @@ -import { CommandInteraction, DMChannel, GuildChannel, Message, MessageActionRow, MessageButton, MessageEmbed } from "discord.js"; -import { Discord, Slash, SlashOption } from "discordx"; +import { CommandInteraction, DMChannel, GuildChannel, Message, MessageActionRow, MessageButton, MessageEmbed, VoiceChannel } from "discord.js"; +import { DefaultPermission, Discord, Guild, Permission, Slash, SlashOption } from "discordx"; +import { allServeursIds, globalAdminPerms, globalEnseignantPerms } from "../GlobalVar"; @Discord() abstract class Divers { @@ -86,4 +87,67 @@ abstract class Divers { interaction.editReply({ embeds: [embed], components: [row] }) } + + @Guild(...allServeursIds) + @DefaultPermission(false) + @Permission(...globalAdminPerms) + @Permission(...globalEnseignantPerms) + @Slash('groupevocal', { description: "CrĂ©e un ou plusieurs salons vocaux temporaire dans cette catĂ©gorie (1 salon pendant 60m par dĂ©faut)" }) + private async groupevocal( + @SlashOption('quantitĂ©', { description: "Nombre de salon Ă  crĂ©er. (10 salon max)" }) + amount: number = 1, + @SlashOption('durĂ©e', { description: "DurĂ©e du salon avant sa suppression en minute. (240 minutes = 4 heures max)" }) + duration: number = 60, + interaction: CommandInteraction + ) { + if (amount <= 0) { interaction.reply({ content: "DĂ©solĂ© cependant vous ne pouvez crĂ©er une quantitĂ© nĂ©gative ou nulle de salon.", ephemeral: true }); return; } + if (duration <= 0) { interaction.reply({ content: "DĂ©solĂ© cependant vous ne pouvez crĂ©er de salon pour une durĂ©e nĂ©gative ou nulle.", ephemeral: true }); return; } + + if (amount > 10) { interaction.reply({ content: "DĂ©solĂ© cependant vous ne pouvez pas crĂ©er plus de 10 salons Ă  la fois.", ephemeral: true }); return; } + if (duration > 240) { interaction.reply({ content: "DĂ©solĂ© cependant vous ne pouvez crĂ©er de salon durant plus de 4 heures.", ephemeral: true }); return; } + + if (interaction.channel?.type !== "GUILD_TEXT") { return; } + + const category = interaction.channel?.parent; + + if (!category) { interaction.reply({ content: "DĂ©solĂ© cependant ce salon n'a pas de catĂ©gorie.", ephemeral: true }); return; } + + const guild = interaction.guild; + + if (!guild) { interaction.reply({ content: `Une erreur est survenue (guild: ${guild})`, ephemeral: true }); return; } + + await interaction.deferReply(); + + let newSalonsPromise: Promise[] = []; + + for (let i = 0; i < amount; i++) { + newSalonsPromise.push(guild.channels.create(`đŸ’»ăƒ»Groupe ${i + 1}`, { + type: "GUILD_VOICE", + parent: category, + reason: `Salon vocal de groupe temporaire crĂ©Ă© par ${interaction.user.username}` + })); + } + + interaction.editReply({ content: "Votre demande est en cours de traitement..." }) + + const newChannels = await Promise.all(newSalonsPromise); + + newChannels.forEach(async salon => { + salon.permissionOverwrites.create(interaction.user, { 'MANAGE_CHANNELS': true }, { reason: "Permissions donnĂ©es au crĂ©ateur du salon" }); + setTimeout((salon: VoiceChannel) => { + salon.delete(); + }, duration * 60000, salon); + }); + + interaction.editReply({ content: `Vos ${amount} salons ont Ă©tĂ© crĂ©Ă© pour ${duration} minutes. \`${duration} minutes restantes\`` }); + + let minutesSpend = 0; + const intervalID = setInterval( + (interaction: CommandInteraction, minutesSpend: number) => { + interaction.editReply({ content: `Vos ${amount} salons ont Ă©tĂ© crĂ©Ă© pour ${duration} minutes. \`${duration - minutesSpend} minutes restantes\`` }); + minutesSpend++ + }, 60000, interaction, ++minutesSpend); + + setTimeout((intervalID, interaction: CommandInteraction) => { clearInterval(intervalID); interaction.editReply({ content: `Temps Ă©coulĂ© ! Vos salons ont Ă©tĂ© supprimĂ©s.` }) }, duration * 60000, intervalID, interaction); + } } \ No newline at end of file From b2ffc06bb19b811c0553187eb73605be8ec8516a Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Fri, 17 Sep 2021 02:24:17 +0200 Subject: [PATCH 27/29] =?UTF-8?q?Ajout=20des=20perms=20et=20serveurs=20b?= =?UTF-8?q?=C3=AAta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- global/GlobalVar.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/global/GlobalVar.ts b/global/GlobalVar.ts index 9027a11..8beed33 100644 --- a/global/GlobalVar.ts +++ b/global/GlobalVar.ts @@ -4,7 +4,9 @@ import { Role as Role_IUT_NC_DEPINFO } from "../iut_nc_depinfo/IDs"; export const globalAdminPerms: ApplicationCommandPermissionData[] = [ { id: Role_IUT_NC_DEPINFO.STAR, type: "ROLE", permission: true }, - { id: Role_IUT_NC_DEPINFO.ADMIN, type: "ROLE", permission: true } + { id: Role_IUT_NC_DEPINFO.ADMIN, type: "ROLE", permission: true }, + //{ id: RoleBeta.BETA_1, type: "ROLE", permission: true }, + //{ id: RoleBeta.BETA_2, type: "ROLE", permission: true } ] export const globalEnseignantPerms: ApplicationCommandPermissionData[] = [ @@ -13,5 +15,7 @@ export const globalEnseignantPerms: ApplicationCommandPermissionData[] = [ export const allServeursIds: Serveur[] = [ Serveur.IUT_NC_DEP_INFO, - Serveur.IUT_NC_DEP_INFO2 + //Serveur.BETA_2, + //Serveur.BETA_1 +] ] \ No newline at end of file From 44702953418f3eaeb44ae586eb216f3348a53520 Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Fri, 17 Sep 2021 02:24:29 +0200 Subject: [PATCH 28/29] Refactor twitter --- events/twitter/tweet.ts | 99 ------------------------------ global/GlobalVar.ts | 16 ++++- global/events/twitter/tweet.ts | 107 +++++++++++++++++++++++++++++++++ twitter.ts | 38 ++++++------ 4 files changed, 143 insertions(+), 117 deletions(-) delete mode 100644 events/twitter/tweet.ts create mode 100644 global/events/twitter/tweet.ts diff --git a/events/twitter/tweet.ts b/events/twitter/tweet.ts deleted file mode 100644 index cc0eac0..0000000 --- a/events/twitter/tweet.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { BaseGuildTextChannel, Client, MessageActionRow, MessageButton, MessageEmbed } from 'discord.js'; -import * as Twit from 'twit'; -import { ChannelIDs, ServerIDs } from '../../enums/IDs'; -import { getHorodateConsole } from '../../util'; - -module.exports = { - name: 'tweet', - endPoint: 'statuses/filter', - options: { - follow: ['329665290', '282478715', '4113039761', '1257587508738699265'] - }, - async execute(tweet: Twit.Twitter.Status, client: Client) { - if (!this.options.follow.includes(tweet.user.id_str)) return; - if (tweet.in_reply_to_status_id || tweet.in_reply_to_status_id_str || tweet.in_reply_to_user_id || tweet.in_reply_to_user_id_str || tweet.in_reply_to_screen_name) return; - - console.log(`${getHorodateConsole()}\t@${tweet.user.screen_name} : ${tweet.text}`); - - let channel = (client.guilds.resolve(ServerIDs.MAIN)?.channels.resolve(ChannelIDs.TWITTER)); - - if (!channel || channel.isVoice()) { console.log(`[Channel Error] Channel type = ${channel?.type}`); return; } - - channel.sendTyping(); - - const resEmbed = new MessageEmbed() - .setColor('#1DA1F2') - .setAuthor(tweet.user.name, tweet.user.profile_image_url, `https://twitter.com/${tweet.user.screen_name}`) - .setThumbnail(tweet.user.profile_image_url) - //@ts-ignore - .setDescription(tweet.extended_tweet?.full_text || tweet.text) - //@ts-ignore - .setTimestamp(tweet.created_at); - - const row = new MessageActionRow(); - - if (tweet.retweeted_status) { - resEmbed.setTitle(`${tweet.user.screen_name} a retweetĂ©(e)`) - .setAuthor(tweet.retweeted_status.user.name, tweet.retweeted_status.user.profile_image_url, `https://twitter.com/${tweet.retweeted_status.user.screen_name}`) - .setThumbnail(tweet.retweeted_status.user.profile_image_url) - //@ts-ignore - .setDescription(tweet.retweeted_status.extended_tweet?.full_text || tweet.retweeted_status.text); - - row.addComponents( - new MessageButton() - .setStyle("LINK") - .setLabel("Voir le Tweet") - .setURL(`https://twitter.com/${tweet.retweeted_status.user.screen_name}/status/${tweet.retweeted_status.id_str}`), - new MessageButton() - .setStyle("LINK") - .setLabel("Voir le Profil") - .setURL(`https://twitter.com/${tweet.retweeted_status.user.screen_name}`) - ); - } else { - resEmbed.setTitle(`Nouveau Tweet !`) - - row.addComponents( - new MessageButton() - .setStyle("LINK") - .setLabel("Voir le Tweet") - .setURL(`https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}`), - new MessageButton() - .setStyle("LINK") - .setLabel("Voir le Profil") - .setURL(`https://twitter.com/${tweet.user.screen_name}`) - ); - } - - if (tweet.quoted_status) { - //@ts-ignore - resEmbed.addField(`A citĂ© un Tweet de ${tweet.quoted_status.user.name}`, tweet.quoted_status.extended_tweet?.full_text || tweet.quoted_status.text); - //@ts-ignore - if (tweet.quoted_status?.extended_tweet?.extended_entities?.media) { - //@ts-ignore - resEmbed.setImage(tweet.quoted_status?.extended_tweet?.extended_entities?.media?.[0]?.media_url); - } - - row.addComponents( - new MessageButton() - .setStyle("LINK") - .setLabel("Voir le Tweet CitĂ©") - .setURL(`https://twitter.com/${tweet.quoted_status.user.screen_name}/status/${tweet.quoted_status.id_str}`), - new MessageButton() - .setStyle("LINK") - .setLabel("Voir le Profil CitĂ©") - .setURL(`https://twitter.com/${tweet.quoted_status.user.screen_name}`) - ); - } - - //@ts-ignore - if (tweet.extended_entities?.media || tweet?.extended_tweet?.extended_entities?.media || tweet.retweeted_status?.extended_tweet?.extended_entities?.media) { - //@ts-ignore - resEmbed.setImage(tweet.extended_entities?.media?.[0]?.media_url || tweet.extended_tweet?.extended_entities?.media?.[0]?.media_url || tweet.retweeted_status?.extended_tweet?.extended_entities?.media?.[0]?.media_url); - } - - const message = await channel.send({ embeds: [resEmbed], components: [row] }); - - if (channel.type === "GUILD_NEWS" || channel.type === "GUILD_NEWS_THREAD") - await message.crosspost(); - } -} \ No newline at end of file diff --git a/global/GlobalVar.ts b/global/GlobalVar.ts index 8beed33..d06adab 100644 --- a/global/GlobalVar.ts +++ b/global/GlobalVar.ts @@ -1,4 +1,4 @@ -import { ApplicationCommandPermissionData } from "discord.js"; +import { ApplicationCommandPermissionData, ChannelResolvable } from "discord.js"; import { Serveur } from "../IDs"; import { Role as Role_IUT_NC_DEPINFO } from "../iut_nc_depinfo/IDs"; @@ -18,4 +18,18 @@ export const allServeursIds: Serveur[] = [ //Serveur.BETA_2, //Serveur.BETA_1 ] + +export const salonIdPostTwitter: ChannelResolvable[] = [ + "854010477838073876", // iut_nc_depinfo twitter + //"887879239985168384", // BĂȘta 1 gĂ©nĂ©ral + //"885296615529787433", // BĂȘta 1 e + //"888005290958675992", // BĂȘta 2 e +] + +export const followTwitter = [ + '329665290', //@Univ_Lorraine + '282478715', //@iutCharlemagne + '4113039761', //@regiongrandest + '1257587508738699265', //@RA_GrandEst + //'1003899371354755072' //@Tenebrosful (tests) ] \ No newline at end of file diff --git a/global/events/twitter/tweet.ts b/global/events/twitter/tweet.ts new file mode 100644 index 0000000..c4c0573 --- /dev/null +++ b/global/events/twitter/tweet.ts @@ -0,0 +1,107 @@ +import { Client, MessageActionRow, MessageButton, MessageEmbed, MessageOptions } from 'discord.js'; +import * as Twit from 'twit'; +import { getHorodateConsole } from '../../../libs/util'; +import { followTwitter, salonIdPostTwitter } from '../../GlobalVar'; + +module.exports = { + name: 'tweet', + endPoint: 'statuses/filter', + options: { + follow: followTwitter + }, + async execute(tweet: Twit.Twitter.Status, client: Client) { + if (!this.options.follow.includes(tweet.user.id_str)) return; + if (tweet.in_reply_to_status_id || tweet.in_reply_to_status_id_str || tweet.in_reply_to_user_id || tweet.in_reply_to_user_id_str || tweet.in_reply_to_screen_name) return; + + console.log(`${getHorodateConsole()}\t[TWEET]\t@${tweet.user.screen_name} : ${tweet.text}`); + + const post = genererPost(tweet); + + const salons = salonIdPostTwitter.map(id => client.channels.resolve(id)); + + salons.forEach(async (salon, i) => { + if (!salon || !salon.isText()) { console.log(`${getHorodateConsole()}\t[Channel Error]\t${salonIdPostTwitter[i]} Channel type = ${salon?.type}`); return; } + + salon.sendTyping(); + + const message = await salon.send(post); + + if (salon.type === "GUILD_NEWS" || salon.type === "GUILD_NEWS_THREAD") + await message.crosspost(); + }) + } +} + +function genererPost(tweet: Twit.Twitter.Status): MessageOptions { + const resEmbed = new MessageEmbed() + .setColor('#1DA1F2') + .setAuthor(tweet.user.name, tweet.user.profile_image_url, `https://twitter.com/${tweet.user.screen_name}`) + .setThumbnail(tweet.user.profile_image_url) + //@ts-ignore + .setDescription(tweet.extended_tweet?.full_text || tweet.text) + //@ts-ignore + .setTimestamp(tweet.created_at); + + const row = new MessageActionRow(); + + if (tweet.retweeted_status) { + resEmbed.setTitle(`${tweet.user.screen_name} a retweetĂ©(e)`) + .setAuthor(tweet.retweeted_status.user.name, tweet.retweeted_status.user.profile_image_url, `https://twitter.com/${tweet.retweeted_status.user.screen_name}`) + .setThumbnail(tweet.retweeted_status.user.profile_image_url) + //@ts-ignore + .setDescription(tweet.retweeted_status.extended_tweet?.full_text || tweet.retweeted_status.text); + + row.addComponents( + new MessageButton() + .setStyle("LINK") + .setLabel("Voir le Tweet") + .setURL(`https://twitter.com/${tweet.retweeted_status.user.screen_name}/status/${tweet.retweeted_status.id_str}`), + new MessageButton() + .setStyle("LINK") + .setLabel("Voir le Profil") + .setURL(`https://twitter.com/${tweet.retweeted_status.user.screen_name}`) + ); + } else { + resEmbed.setTitle(`Nouveau Tweet !`) + + row.addComponents( + new MessageButton() + .setStyle("LINK") + .setLabel("Voir le Tweet") + .setURL(`https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}`), + new MessageButton() + .setStyle("LINK") + .setLabel("Voir le Profil") + .setURL(`https://twitter.com/${tweet.user.screen_name}`) + ); + } + + if (tweet.quoted_status) { + //@ts-ignore + resEmbed.addField(`A citĂ© un Tweet de ${tweet.quoted_status.user.name}`, tweet.quoted_status.extended_tweet?.full_text || tweet.quoted_status.text); + //@ts-ignore + if (tweet.quoted_status?.extended_tweet?.extended_entities?.media) { + //@ts-ignore + resEmbed.setImage(tweet.quoted_status?.extended_tweet?.extended_entities?.media?.[0]?.media_url); + } + + row.addComponents( + new MessageButton() + .setStyle("LINK") + .setLabel("Voir le Tweet CitĂ©") + .setURL(`https://twitter.com/${tweet.quoted_status.user.screen_name}/status/${tweet.quoted_status.id_str}`), + new MessageButton() + .setStyle("LINK") + .setLabel("Voir le Profil CitĂ©") + .setURL(`https://twitter.com/${tweet.quoted_status.user.screen_name}`) + ); + } + + //@ts-ignore + if (tweet.extended_entities?.media || tweet?.extended_tweet?.extended_entities?.media || tweet.retweeted_status?.extended_tweet?.extended_entities?.media) { + //@ts-ignore + resEmbed.setImage(tweet.extended_entities?.media?.[0]?.media_url || tweet.extended_tweet?.extended_entities?.media?.[0]?.media_url || tweet.retweeted_status?.extended_tweet?.extended_entities?.media?.[0]?.media_url); + } + + return { embeds: [resEmbed], components: [row] }; +} \ No newline at end of file diff --git a/twitter.ts b/twitter.ts index f98a400..1c27413 100644 --- a/twitter.ts +++ b/twitter.ts @@ -14,10 +14,10 @@ async function start() { consumer_secret: process.env.CONSUMER_SECRET ?? "", access_token: process.env.ACCESS_TOKEN ?? "", access_token_secret: process.env.ACCESS_TOKEN_SECRET ?? "" - }), SingletonClient); + }), SingletonClient, ["global"]); SingletonClient.on("ready", () => { - console.log(`${getHorodateConsole()}\tReady !`); + console.log(`${getHorodateConsole()}\t[INFO]\tReady !`); if (SingletonClient.user) resetPresence(SingletonClient.user); @@ -28,30 +28,34 @@ async function start() { -function loadTwitterEvents(Twitter: Twit, client: Client) { - const eventFiles = fs.readdirSync('./events/twitter').filter(file => file.endsWith('.ts')); +function loadTwitterEvents(Twitter: Twit, client: Client, dirs: string[]) { + dirs.forEach(dir => { + const eventFiles = fs.readdirSync(`./${dir}/events/twitter`).filter(file => file.endsWith('.ts')); - for (const file of eventFiles) { - const event = require(`./events/twitter/${file}`); - let stream; + for (const file of eventFiles) { + const event = require(`./${dir}/events/twitter/${file}`); + let stream; - try { - stream = Twitter.stream(event.endPoint, event.options); - } catch (err) { - console.log(err); - } + try { + stream = Twitter.stream(event.endPoint, event.options); + } catch (err) { + console.log(err); + } + + if (!stream) { console.error(`${getHorodateConsole()}\t[FAIL LOAD]\t${dir} ${file}, stream = ${stream}`); return; } - if (!stream) { console.error(`[FAIL LOAD] ${file}, stream = ${stream}`); return; } + stream.on(event.name, (...args) => event.execute(...args, client)); - stream.on(event.name, (...args) => event.execute(...args, client)); - } + console.log(`${getHorodateConsole()}\t[LOADED]\t${dir} ${file}`); + } + }) } function handleExit(signal: NodeJS.Signals) { - console.info(`${getHorodateConsole()} Signal ${signal} reçu.`); + console.info(`${getHorodateConsole()}\t[STOP]\tSignal ${signal} reçu.`); SingletonClient.user?.setPresence({ status: "idle", activities: [{ name: "ArrĂȘt en cours", type: "COMPETING" }] }) SingletonClient.destroy(); - console.log(`${getHorodateConsole()} ArrĂȘt du bot.`); + console.log(`${getHorodateConsole()}\t[STOP]\tArrĂȘt du bot.`); process.exit(0); } From 619124b3c45c39e3aa07fd48668d96b4cb9a3fed Mon Sep 17 00:00:00 2001 From: Tenebrosful Date: Fri, 17 Sep 2021 02:29:19 +0200 Subject: [PATCH 29/29] Version 2.0.0 --- package-lock.json | 21 ++++++++------------- package.json | 4 ++-- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 67c8217..028fa8d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bot-discord-iut-nancy-charlemagne", - "version": "1.1.1", + "version": "2.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bot-discord-iut-nancy-charlemagne", - "version": "1.1.1", + "version": "2.0.0", "license": "MIT", "dependencies": { "discord.js": "^13.1.0", @@ -131,9 +131,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "16.9.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.9.1.tgz", - "integrity": "sha512-QpLcX9ZSsq3YYUUnD3nFDY8H7wctAhQj/TFKL8Ya8v5fMm3CFXxo8zStsLAl780ltoYoo1WvKUVGBQK+1ifr7g==" + "version": "16.9.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.9.2.tgz", + "integrity": "sha512-ZHty/hKoOLZvSz6BtP1g7tc7nUeJhoCf3flLjh8ZEv1vFKBWHXcnMbJMyN/pftSljNyy0kNW/UqI3DccnBnZ8w==" }, "node_modules/@types/twit": { "version": "2.2.30", @@ -774,11 +774,6 @@ "safer-buffer": "^2.0.2", "tweetnacl": "~0.14.0" }, - "bin": { - "sshpk-conv": "bin/sshpk-conv", - "sshpk-sign": "bin/sshpk-sign", - "sshpk-verify": "bin/sshpk-verify" - }, "engines": { "node": ">=0.10.0" } @@ -1059,9 +1054,9 @@ "dev": true }, "@types/node": { - "version": "16.9.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.9.1.tgz", - "integrity": "sha512-QpLcX9ZSsq3YYUUnD3nFDY8H7wctAhQj/TFKL8Ya8v5fMm3CFXxo8zStsLAl780ltoYoo1WvKUVGBQK+1ifr7g==" + "version": "16.9.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.9.2.tgz", + "integrity": "sha512-ZHty/hKoOLZvSz6BtP1g7tc7nUeJhoCf3flLjh8ZEv1vFKBWHXcnMbJMyN/pftSljNyy0kNW/UqI3DccnBnZ8w==" }, "@types/twit": { "version": "2.2.30", diff --git a/package.json b/package.json index 08a0eb4..543fb05 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bot-discord-iut-nancy-charlemagne", - "version": "1.1.1", + "version": "2.0.0", "description": "", "main": "index.ts", "scripts": { @@ -32,4 +32,4 @@ "ts-node": "^10.2.1", "typescript": "^4.4.2" } -} \ No newline at end of file +}