Skip to content

Commit

Permalink
Merge pull request #2 from Communaute-Events/dev
Browse files Browse the repository at this point in the history
Fixed undefined serverInfo and modif. help command
  • Loading branch information
OrigamingWasTaken authored Nov 28, 2023
2 parents 52847a5 + 5eb80a2 commit 5ec73dc
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 73 deletions.
26 changes: 26 additions & 0 deletions config/commands/help.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Commands:
- name: "Aide"
command: "help"
description: "Affiche ce menu"
- name: "Latence"
command: "ping"
description: "Répond avec la latence en ms du bot"

Admin Commands:
- name: "Alertes"
command: "alert"
category: true
description: "Gère les alertes d'évents du serveur"
subcommands:
- command: "info"
description: "Affiche des informations à propos de la configuration des alertes"
- command: "enable"
description: "Active les alertes d'évents"
- command: "disable"
description: "Désactive les alertes d'évents"
- command: "setchannel"
description: "Défini le channel d'alerte pour les évents"
- command: "pick"
description: "Active/Désactive certain serveurs d'évents"
- command: "roles bind"
description: "Permet de définir le rôle à ping pour un certain event"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "node scripts/start.js && npm run build && cd dist && node src/index.js",
"build": "rimraf dist/* && tsc && tsc-alias && tscp",
"build:watch": "tsc && tscp && (concurrently \"tsc -w\" \"tsc-alias -w\")",
"build:watch": "tsc -c && tscp && (concurrently \"tsc -w\" \"tsc-alias -w\")",
"watch": "npm run build:watch",
"url": "node scripts/url.js"
},
Expand Down
11 changes: 0 additions & 11 deletions src/commands/alerts/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ export default {
subcommand
.setName("roles")
.setDescription("Séléctionne les rôles à ping lors d'un event.")
// .addSubcommand(subcommand =>
// subcommand
// .setName("add")
// .setDescription("Ajoute le rôle séléctionné")
// .addRoleOption(option =>
// option
// .setRequired(true)
// .setName("role")
// .setDescription("Le rôle à ajouter")
// )
// )
.addSubcommand(subcommand =>
subcommand
.setName("unbind")
Expand Down
38 changes: 7 additions & 31 deletions src/commands/alerts/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,50 +137,26 @@ export async function pickSource(interaction: ChatInputCommandInteraction) {
}
}

// export async function roles(interaction: ChatInputCommandInteraction, operation: boolean) {
// const roleId = interaction.options.getRole("role").id
// try {
// await mongo.connect()
// const db: Db = mongo.db("discord")
// const collection: Collection = db.collection("servers")

// let roles: string[] = (await collection.findOne({ id: interaction.guild.id })).roles || []
// if (operation) {
// roles.push(roleId)
// } else {
// roles = roles.filter(role => role !== roleId)
// }
// await collection.updateOne(
// { id: interaction.guild.id },
// { $set: { roles: [...new Set(roles)] } },
// { upsert: true }
// )
// interaction.reply({ content: operation ? `<@&${roleId}> a été **ajouté** à la liste des rôles.` : `<@&${roleId}> a été **retiré** à la liste des rôles.`, ephemeral: true })
// } catch (error) {
// logging(`Error occured while updating guild ping roles:\n${error}`, "error")
// } finally {
// if (mongo) {
// await mongo.close()
// }
// }
// }

export async function info(interaction: ChatInputCommandInteraction) {
try {
await mongo.connect()
const db: Db = mongo.db("discord")
const collection: Collection = db.collection("servers")
const serverInfo: DiscordServerInfo = await collection.findOne({ id: interaction.guild.id })
if (!serverInfo) {
interaction.reply({content: "Aucune configuration n'a été trouvée pour le serveur.",ephemeral: true})
return
}

const sources: EventSource[] = await getSources()

const formattedString: string = Object.entries(serverInfo.roles)
const formattedString: string = serverInfo.roles ? Object.entries(serverInfo.roles)
.map(([id, roleId]) => {
const user = sources.find((src) => src.guildId === id);
const userName = user ? user.name : id;
return `\n> \`${userName}\`: <@&${roleId}>`;
})
.join(', ');
.join(', ') : '@everyone';

const embed = new EmbedBuilder()
.setTitle("Paramètres des Alertes")
Expand All @@ -189,7 +165,7 @@ export async function info(interaction: ChatInputCommandInteraction) {
**Actif**: ${serverInfo.enabled ? '✅' : '🚫'}
**Channel**: ${serverInfo.channel ? '<#' + serverInfo.channel + '>' : '`Non défini`'}
**Role(s)**: ${serverInfo.roles ? formattedString : "@everyone"}
**Role(s)**: ${formattedString}
**Serveurs Évents Actifs**: ${serverInfo.sources ? "\n*" + serverInfo.sources
.map((src) => sources.find((s) => s.guildId === src)?.name)
.join("*\n*") + "*" : '`Aucun`'}`
Expand Down
29 changes: 0 additions & 29 deletions src/commands/help/folder/subfolder/help.ts

This file was deleted.

24 changes: 24 additions & 0 deletions src/commands/help/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { HelpCommandConfig } from '@src/types';
import { SlashCommandBuilder, EmbedBuilder, AttachmentBuilder } from 'discord.js'
const Theme = loadYaml("bot/info.yml")
const HelpConfig: HelpCommandConfig = loadYaml("commands/help.yml")

// @command
// here cuz otherwise tsc removes it
export default {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Shows the help menu'),
async execute(interaction) {
const embed = new EmbedBuilder()
.setTitle("Menu d'aide")
.setColor(Theme.Color)
.setThumbnail("attachment://question_mark.png")
.setDescription("Voici une liste des actions proposées par **Event Helper**.")
.setFields(
{ name: "Commandes", value: HelpConfig.Commands.map(cmd => `** **\n**${cmd.name}**\n${cmd.category ? cmd.subcommands.map(sub => "`/" + cmd.command + sub.command + "` : " + sub.description + "\n").join('') + "\n" : "`/" + cmd.command + "` : " + cmd.description + "\n"}`).join('')},
{ name: "Commandes Admins", value: HelpConfig['Admin Commands'].map(cmd => `** **\n**${cmd.name}**\n${cmd.category ? cmd.subcommands.map(sub => "`/" + cmd.command + sub.command + "` : " + sub.description + "\n").join('') + "\n" : "`/" + cmd.command + "` : " + cmd.description + "\n"}`).join('')},
)
await interaction.reply({embeds: [embed], files: [new AttachmentBuilder("src/images/question_mark.png")]});
}
};
20 changes: 19 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,34 @@ export interface EventSource {
emoji: string
}

// Config

export interface BotConfig {
'App Name': string
Color: `#${string}`
}

export interface HelpCommandCategory {
name: string,
command: string,
category: boolean,
description: string,
subcommands?: {
command: string,
description: string
}[]
}
export interface HelpCommandConfig {
Commands: HelpCommandCategory[],
'Admin Commands': HelpCommandCategory[]
}

// Mongo
export interface DiscordServerInfo {
_id: ObjectId
id?: string,
channel?: string,
enabled?: boolean,
sources?: string[],
roles?: { [id: string]: string}
roles?: { [id: string]: string }
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"files": true
},
"compilerOptions": {
"removeComments": false,
"resolveJsonModule": true,
"esModuleInterop": true,
"rootDir": "./",
Expand Down

0 comments on commit 5ec73dc

Please sign in to comment.