From a314e23ac706c8aec1f4afad55d781813e4455d1 Mon Sep 17 00:00:00 2001 From: Adan_ea <57812567+adan-ea@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:56:04 +0200 Subject: [PATCH] feat: create jail module (#97) * refacto: move index.js higher * feat(jail): basic implementation of user context menu * refacto: change file name convention * feat: handle most cases and sends to jail * feat: add auto move back to channel * feat(logs): add permissions to error message Now, the error message will include the specific permission that is missing, making it easier for users to resolve the issue. out of scope but had to be done. But too lazy to go to develop and come back to this branch * chore: update adroi.d.ea dependency to version 1.3.0 * Update deploy-commands.ts --- Dockerfile | 8 +- src/index.ts => index.ts | 12 +-- package-lock.json | 21 ++++- package.json | 2 +- src/client.ts | 3 + src/deploy-commands.ts | 1 + src/handlers/component.handler.ts | 4 +- src/handlers/task.handler.ts | 75 +++++++++++++---- src/models/guild.model.ts | 2 + .../auditLogs/events/guild/guildBanAdd.ts | 2 +- .../auditLogs/events/guild/guildBanRemove.ts | 4 +- .../auditLogs/events/guild/guildRoleCreate.ts | 4 +- .../auditLogs/events/guild/guildRoleDelete.ts | 4 +- .../auditLogs/events/guild/guildRoleUpdate.ts | 4 +- .../events/guild_members/guildMemberAdd.ts | 4 +- .../events/guild_members/guildMemberRemove.ts | 4 +- .../events/guild_members/guildMemberUpdate.ts | 4 +- .../guild_messages/messageBulkDelete.ts | 2 +- .../events/guild_messages/messageDelete.ts | 4 +- .../events/guild_messages/messageUpdate.ts | 4 +- src/modules/core/commands/misc/report.ts | 2 +- .../core/commands/moderation/changelog.ts | 2 +- src/modules/core/commands/moderation/purge.ts | 9 +- ...hangelogBtn.ts => sendChangelog.button.ts} | 2 +- .../core/events/client/interactionCreate.ts | 19 ++++- .../core/tasks/customProfilePicture.cron.ts | 2 +- .../contextMenus/jail.contextMenu.ts | 82 +++++++++++++++++++ src/modules/jail/models/index.ts | 3 + src/modules/jail/models/jail.model.ts | 11 +++ src/modules/jail/tasks/jail.queue.ts | 14 ++++ src/modules/jail/tasks/jail.worker.ts | 38 +++++++++ src/modules/qotd/commands/qotd.ts | 4 +- src/modules/qotd/components/buttons/index.ts | 8 +- ...{qotdAcceptBtn.ts => qotdAccept.button.ts} | 2 +- ...tStealBtn.ts => qotdAcceptSteal.button.ts} | 4 +- ...ctBtn.ts => qotdBlacklistReject.button.ts} | 2 +- ...{qotdRejectBtn.ts => qotdReject.button.ts} | 2 +- src/modules/qotd/tasks/qotd.cron.ts | 4 +- .../scheduledEvents/commands/createEvent.ts | 2 +- .../guild_scheduled_events/eventUpdate.ts | 4 +- .../events/guild_scheduled_events/userAdd.ts | 2 +- .../guild_scheduled_events/userRemove.ts | 2 +- ...ntService.ts => scheduledEvent.service.ts} | 0 .../tasks/scheduledEvents.queue.ts | 2 +- .../tasks/scheduledEvents.worker.ts | 12 +-- .../tempVoice/commands/voicePrivacy.ts | 4 +- .../tempVoice/components/buttons/index.ts | 20 ++--- ...tAddBtn.ts => voiceBlacklistAdd.button.ts} | 2 +- ...eBtn.ts => voiceBlacklistRemove.button.ts} | 2 +- ...oiceDeleteBtn.ts => voiceDelete.button.ts} | 4 +- ...irmBtn.ts => voiceDeleteConfirm.button.ts} | 2 +- ...{voiceLimitBtn.ts => voiceLimit.button.ts} | 4 +- ...ferBtn.ts => voiceOwnerTransfer.button.ts} | 2 +- ...cePrivacyBtn.ts => voicePrivacy.button.ts} | 4 +- ...gionBtn.ts => voiceSetRTCRegion.button.ts} | 2 +- ...tAddBtn.ts => voiceWhitelistAdd.button.ts} | 2 +- ...eBtn.ts => voiceWhitelistRemove.button.ts} | 2 +- ...Btn.ts => voiceWhitelistTempAdd.button.ts} | 0 ...voiceLimitModal.ts => voiceLimit.modal.ts} | 2 +- .../tempVoice/components/selectMenus/index.ts | 12 +-- ...enu.ts => voiceBlacklistAdd.selectMenu.ts} | 4 +- ....ts => voiceBlacklistRemove.selectMenu.ts} | 4 +- ...nu.ts => voiceOwnerTransfer.selectMenu.ts} | 2 +- ...enu.ts => voiceSetRTCRegion.selectMenu.ts} | 0 ...enu.ts => voiceWhitelistAdd.selectMenu.ts} | 2 +- ....ts => voiceWhitelistRemove.selectMenu.ts} | 4 +- ...ts => voiceWhitelistTempAdd.selectMenu.ts} | 2 +- .../events/guild_voices/voiceStateUpdate.ts | 4 +- src/modules/twitch/tasks/twitchAlert.cron.ts | 4 +- .../twitch/tasks/twitchAssignRole.cron.ts | 2 +- src/utils/{botUtil.ts => bot.util.ts} | 38 +++++++++ src/utils/consts.ts | 62 ++++++++++++++ src/utils/{embedsUtil.ts => embeds.util.ts} | 0 src/utils/errors.ts | 19 ++++- src/utils/logger.ts | 2 +- src/utils/{memberUtil.ts => member.util.ts} | 2 +- src/utils/{modulesUil.ts => modules.uil.ts} | 58 +------------ src/utils/{twitchUtil.ts => twitch.util.ts} | 0 src/utils/{voiceUtil.ts => voice.util.ts} | 4 +- tests/unit/utils/botUtil.test.ts | 2 +- tests/unit/utils/embedsUtil.test.ts | 2 +- tests/unit/utils/twitchUtil.test.ts | 2 +- tsconfig.json | 2 +- 83 files changed, 489 insertions(+), 198 deletions(-) rename src/index.ts => index.ts (88%) rename src/modules/core/components/buttons/{sendChangelogBtn.ts => sendChangelog.button.ts} (98%) create mode 100644 src/modules/jail/components/contextMenus/jail.contextMenu.ts create mode 100644 src/modules/jail/models/index.ts create mode 100644 src/modules/jail/models/jail.model.ts create mode 100644 src/modules/jail/tasks/jail.queue.ts create mode 100644 src/modules/jail/tasks/jail.worker.ts rename src/modules/qotd/components/buttons/{qotdAcceptBtn.ts => qotdAccept.button.ts} (97%) rename src/modules/qotd/components/buttons/{qotdAcceptStealBtn.ts => qotdAcceptSteal.button.ts} (94%) rename src/modules/qotd/components/buttons/{qotdBlacklistRejectBtn.ts => qotdBlacklistReject.button.ts} (96%) rename src/modules/qotd/components/buttons/{qotdRejectBtn.ts => qotdReject.button.ts} (96%) rename src/modules/scheduledEvents/services/{scheduledEventService.ts => scheduledEvent.service.ts} (100%) rename src/modules/tempVoice/components/buttons/{voiceBlacklistAddBtn.ts => voiceBlacklistAdd.button.ts} (98%) rename src/modules/tempVoice/components/buttons/{voiceBlacklistRemoveBtn.ts => voiceBlacklistRemove.button.ts} (99%) rename src/modules/tempVoice/components/buttons/{voiceDeleteBtn.ts => voiceDelete.button.ts} (87%) rename src/modules/tempVoice/components/buttons/{voiceDeleteConfirmBtn.ts => voiceDeleteConfirm.button.ts} (93%) rename src/modules/tempVoice/components/buttons/{voiceLimitBtn.ts => voiceLimit.button.ts} (86%) rename src/modules/tempVoice/components/buttons/{voiceOwnerTransferBtn.ts => voiceOwnerTransfer.button.ts} (96%) rename src/modules/tempVoice/components/buttons/{voicePrivacyBtn.ts => voicePrivacy.button.ts} (96%) rename src/modules/tempVoice/components/buttons/{voiceSetRTCRegionBtn.ts => voiceSetRTCRegion.button.ts} (95%) rename src/modules/tempVoice/components/buttons/{voiceWhitelistAddBtn.ts => voiceWhitelistAdd.button.ts} (98%) rename src/modules/tempVoice/components/buttons/{voiceWhitelistRemoveBtn.ts => voiceWhitelistRemove.button.ts} (99%) rename src/modules/tempVoice/components/buttons/{voiceWhitelistTempAddBtn.ts => voiceWhitelistTempAdd.button.ts} (100%) rename src/modules/tempVoice/components/modals/{voiceLimitModal.ts => voiceLimit.modal.ts} (95%) rename src/modules/tempVoice/components/selectMenus/{voiceBlacklistAddMenu.ts => voiceBlacklistAdd.selectMenu.ts} (96%) rename src/modules/tempVoice/components/selectMenus/{voiceBlacklistRemoveMenu.ts => voiceBlacklistRemove.selectMenu.ts} (96%) rename src/modules/tempVoice/components/selectMenus/{voiceOwnerTransferMenu.ts => voiceOwnerTransfer.selectMenu.ts} (98%) rename src/modules/tempVoice/components/selectMenus/{voiceSetRTCRegionMenu.ts => voiceSetRTCRegion.selectMenu.ts} (100%) rename src/modules/tempVoice/components/selectMenus/{voiceWhitelistAddMenu.ts => voiceWhitelistAdd.selectMenu.ts} (97%) rename src/modules/tempVoice/components/selectMenus/{voiceWhitelistRemoveMenu.ts => voiceWhitelistRemove.selectMenu.ts} (96%) rename src/modules/tempVoice/components/selectMenus/{voiceWhitelistTempAddMenu.ts => voiceWhitelistTempAdd.selectMenu.ts} (96%) rename src/utils/{botUtil.ts => bot.util.ts} (60%) rename src/utils/{embedsUtil.ts => embeds.util.ts} (100%) rename src/utils/{memberUtil.ts => member.util.ts} (97%) rename src/utils/{modulesUil.ts => modules.uil.ts} (78%) rename src/utils/{twitchUtil.ts => twitch.util.ts} (100%) rename src/utils/{voiceUtil.ts => voice.util.ts} (99%) diff --git a/Dockerfile b/Dockerfile index d595291..02e833b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,13 +5,13 @@ RUN addgroup -S adroidea && adduser -S adan -G adroidea RUN apk add --no-cache tzdata ENV TZ=Europe/Paris -RUN mkdir -p /usr/src/adroid -WORKDIR /usr/src/adroid +RUN mkdir -p /usr/adroid/src +WORKDIR /usr/adroid/src -COPY package.json /usr/src/adroid +COPY package.json /usr/adroid/src RUN npm install --omit=dev --ignore-scripts -COPY dist /usr/src/adroid +COPY dist /usr/adroid/src USER adan CMD ["node", "index.js"] diff --git a/src/index.ts b/index.ts similarity index 88% rename from src/index.ts rename to index.ts index 733acf9..3d659f4 100644 --- a/src/index.ts +++ b/index.ts @@ -1,6 +1,6 @@ -import DiscordClient from './client'; +import DiscordClient from './src/client'; import IORedis from 'ioredis'; -import Logger from './utils/logger'; +import Logger from './src/utils/logger'; import { Partials } from 'discord.js'; import dotenv from 'dotenv'; import mongoose from 'mongoose'; @@ -19,7 +19,7 @@ export const client: any = new DiscordClient({ partials: [Partials.Channel] }); -const filePath = path.join(__dirname, 'handlers/module.handler.js'); +const filePath = path.join(__dirname, 'src/handlers/module.handler.js'); import(filePath).then(handler => handler.default(client)); mongoose.set('strictQuery', false); @@ -39,14 +39,14 @@ mongoose export const connection = new IORedis({ host: process.env.REDIS_HOST, - port: 6379 + port: 6379, + maxRetriesPerRequest: null }) .on('connect', () => { Logger.info('🔴 Redis connected'); }) .on('error', (error: any) => { - if (error.code === 'ECONNREFUSED') return; - else Logger.error(`Redis error:`, error); + Logger.error(`Redis error:`, error); }); client.login(process.env.TOKEN); diff --git a/package-lock.json b/package-lock.json index f6bb70a..b554266 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "4.1.1", "license": "AGPL-3.0", "dependencies": { - "adroi.d.ea": "^1.1.0", + "adroi.d.ea": "^1.3.0", "ansis": "^1.5.5", "bullmq": "^3.12.0", "discord.js": "^14.15.3", @@ -37,6 +37,18 @@ "typescript": "^5.3.3" } }, + "../adroi.d.ea": { + "version": "1.3.0", + "extraneous": true, + "license": "AGPL-3.0", + "devDependencies": { + "@types/jest": "^29.5.11", + "jest": "^29.7.0", + "npm-dts": "^1.3.12", + "ts-jest": "^29.1.1", + "typescript": "^5.3.3" + } + }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", @@ -1929,9 +1941,10 @@ } }, "node_modules/adroi.d.ea": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/adroi.d.ea/-/adroi.d.ea-1.1.0.tgz", - "integrity": "sha512-MO1m0KdoroNsbNIieZfG3dlOiJ61YdOoH4XJrSJqU3YpApyPxSRS54iPVm3Kp3uXAh2t7EkbhajBmERUYYF1vw==" + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/adroi.d.ea/-/adroi.d.ea-1.3.0.tgz", + "integrity": "sha512-4qaYKYixz+ZlIeT1NIVuiJu4t8ZY69KpNW6err03fWFcEgWmvicF/t3DEmxQbM1p0yTji8dgnJ6WwjbDYeoXWA==", + "license": "AGPL-3.0" }, "node_modules/ajv": { "version": "6.12.6", diff --git a/package.json b/package.json index e551373..e62ba80 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ ] }, "dependencies": { - "adroi.d.ea": "^1.1.0", + "adroi.d.ea": "^1.3.0", "ansis": "^1.5.5", "bullmq": "^3.12.0", "discord.js": "^14.15.3", diff --git a/src/client.ts b/src/client.ts index e9e413c..51b34ed 100644 --- a/src/client.ts +++ b/src/client.ts @@ -10,6 +10,7 @@ export interface IDiscordClient { buttons: Collection; modals: Collection; selectMenus: Collection; + contextMenus: Collection; cooldowns: Collection; tempVoice: Collection; } @@ -19,6 +20,7 @@ export default class DiscordClient extends Client implements IDiscordClient { public buttons: Collection; public modals: Collection; public selectMenus: Collection; + public contextMenus: Collection; public cooldowns: Collection; public tempVoice: Collection; @@ -28,6 +30,7 @@ export default class DiscordClient extends Client implements IDiscordClient { this.buttons = new Collection(); this.modals = new Collection(); this.selectMenus = new Collection(); + this.contextMenus = new Collection(); this.cooldowns = new Collection(); this.tempVoice = new Collection(); } diff --git a/src/deploy-commands.ts b/src/deploy-commands.ts index 737746a..22be17c 100644 --- a/src/deploy-commands.ts +++ b/src/deploy-commands.ts @@ -17,6 +17,7 @@ export const regCMD = async (clientId: string) => { const categoryFolders = [ path.join(__dirname, 'modules/core/commands'), + path.join(__dirname, 'modules/jail/components/contextMenus'), //path.join(__dirname, 'modules/logs/commands'), path.join(__dirname, 'modules/qotd/commands'), //path.join(__dirname, 'modules/scheduledEvents/commands'), diff --git a/src/handlers/component.handler.ts b/src/handlers/component.handler.ts index 400c27d..4bece94 100644 --- a/src/handlers/component.handler.ts +++ b/src/handlers/component.handler.ts @@ -49,7 +49,9 @@ const handleSubComponent = async ( if (stat.isDirectory()) { result += await handleSubComponent(client, subCompPath, file); - } else if (['Btn.js', 'Menu.js', 'Modal.js'].some(extension => file.endsWith(extension))) { + } else if ( + ['.button.js', 'Menu.js', '.modal.js'].some(extension => file.endsWith(extension)) + ) { const { default: component } = await import(filePath); const hasWarning = checkComponentOptions(component, filePath); diff --git a/src/handlers/task.handler.ts b/src/handlers/task.handler.ts index 9fe3408..104b4ca 100644 --- a/src/handlers/task.handler.ts +++ b/src/handlers/task.handler.ts @@ -10,8 +10,8 @@ export type TaskFunction = () => void; * @returns A Promise that resolves to the number of tasks handled. */ export const handleTask = async (taskPath: string): Promise => { - let result = 0; const files = fs.readdirSync(taskPath); + let result = 0; for (const file of files) { const filePath = path.join(taskPath, file); @@ -20,21 +20,68 @@ export const handleTask = async (taskPath: string): Promise => { if (stat.isDirectory()) { result += await handleTask(filePath); } else if (file.endsWith('.js')) { - try { - const { default: taskFunction } = await import(filePath); - - if (taskFunction) { - await taskFunction(); - result++; - } else { - Logger.warn(`File: ${file}`); - Logger.warn(`Task function not found. Skipping...`); - } - } catch (error: any) { - Logger.error(`Error importing task from file: ${file}`, error); - } + result += await processFile(file, filePath); } } return result; }; + +/** + * Processes a single file based on its type. + * @param file - The name of the file. + * @param filePath - The full path to the file. + * @returns A Promise that resolves to 1 if the file was handled, 0 otherwise. + */ +const processFile = async (file: string, filePath: string): Promise => { + try { + const { default: taskFunction } = await import(filePath); + + switch (getFileType(file)) { + case 'cron': + return await handleCronTask(file, taskFunction); + case 'worker': + case 'queue': + return 1; + default: + Logger.warn(`File: ${file}`); + Logger.warn(`File type is not supported. Skipping...`); + return 0; + } + } catch (error: any) { + Logger.error(`Error importing task from file: ${file}`, error); + return 0; + } +}; + +/** + * Determines the type of a file based on its name. + * @param file - The name of the file. + * @returns The type of the file ('cron', 'worker', 'queue', or 'unknown'). + */ +const getFileType = (file: string): string => { + if (file.endsWith('cron.js')) return 'cron'; + if (file.endsWith('worker.js')) return 'worker'; + if (file.endsWith('queue.js')) return 'queue'; + return 'unknown'; +}; + +/** + * Handles a cron task file. + * @param file - The name of the file. + * @param taskFunction - The task function to execute. + * @returns A Promise that resolves to 1 if the task was executed, 0 otherwise. + */ +const handleCronTask = async ( + file: string, + taskFunction: TaskFunction | undefined +): Promise => { + if (taskFunction) { + taskFunction(); + return 1; + } else { + Logger.warn(`File: ${file}`); + Logger.warn(`Task function not found. Skipping...`); + return 0; + } +}; diff --git a/src/models/guild.model.ts b/src/models/guild.model.ts index 41c4986..d522cbe 100644 --- a/src/models/guild.model.ts +++ b/src/models/guild.model.ts @@ -1,5 +1,6 @@ import { IGuild } from 'adroi.d.ea'; import { auditLogsSchema } from '../modules/auditLogs/models'; +import { jailSchema } from '../modules/jail/models'; import mongoose from 'mongoose'; import { qotdSchema } from '../modules/qotd/models'; import { tempVoiceSchema } from '../modules/tempVoice/models'; @@ -18,6 +19,7 @@ const guildSchema = new mongoose.Schema({ modules: { eventManagement: eventManagementSchema, auditLogs: auditLogsSchema, + jail: jailSchema, qotd: qotdSchema, tempVoice: tempVoiceSchema, twitch: twitchSchema diff --git a/src/modules/auditLogs/events/guild/guildBanAdd.ts b/src/modules/auditLogs/events/guild/guildBanAdd.ts index ff6ed02..39745a3 100644 --- a/src/modules/auditLogs/events/guild/guildBanAdd.ts +++ b/src/modules/auditLogs/events/guild/guildBanAdd.ts @@ -1,7 +1,7 @@ import { AuditLogEvent, Client, EmbedBuilder, Events, GuildBan, userMention } from 'discord.js'; import { Colors, Emojis } from '../../../../utils/consts'; import { IAuditLogsModule } from 'adroi.d.ea'; -import { addAuthor } from '../../../../utils/embedsUtil'; +import { addAuthor } from '../../../../utils/embeds.util'; import guildService from '../../../../services/guild.service'; export default { diff --git a/src/modules/auditLogs/events/guild/guildBanRemove.ts b/src/modules/auditLogs/events/guild/guildBanRemove.ts index 481882c..9f8211c 100644 --- a/src/modules/auditLogs/events/guild/guildBanRemove.ts +++ b/src/modules/auditLogs/events/guild/guildBanRemove.ts @@ -9,8 +9,8 @@ import { } from 'discord.js'; import { Colors, Emojis } from '../../../../utils/consts'; import { IAuditLogsModule } from 'adroi.d.ea'; -import { addAuthor } from '../../../../utils/embedsUtil'; -import { canSendMessage } from '../../../../utils/botUtil'; +import { addAuthor } from '../../../../utils/embeds.util'; +import { canSendMessage } from '../../../../utils/bot.util'; import guildService from '../../../../services/guild.service'; export default { diff --git a/src/modules/auditLogs/events/guild/guildRoleCreate.ts b/src/modules/auditLogs/events/guild/guildRoleCreate.ts index 61d0e7c..d139e48 100644 --- a/src/modules/auditLogs/events/guild/guildRoleCreate.ts +++ b/src/modules/auditLogs/events/guild/guildRoleCreate.ts @@ -1,7 +1,7 @@ import { AuditLogEvent, Client, EmbedBuilder, Events, Role } from 'discord.js'; import { IAuditLogsModule } from 'adroi.d.ea'; -import { addAuthor } from '../../../../utils/embedsUtil'; -import { addPermissionsNames } from '../../../../utils/modulesUil'; +import { addAuthor } from '../../../../utils/embeds.util'; +import { addPermissionsNames } from '../../../../utils/modules.uil'; import guildService from '../../../../services/guild.service'; export default { diff --git a/src/modules/auditLogs/events/guild/guildRoleDelete.ts b/src/modules/auditLogs/events/guild/guildRoleDelete.ts index 098aa38..f17ef42 100644 --- a/src/modules/auditLogs/events/guild/guildRoleDelete.ts +++ b/src/modules/auditLogs/events/guild/guildRoleDelete.ts @@ -1,7 +1,7 @@ import { AuditLogEvent, Client, EmbedBuilder, Events, Role } from 'discord.js'; import { IAuditLogsModule } from 'adroi.d.ea'; -import { addAuthor } from '../../../../utils/embedsUtil'; -import { addPermissionsNames } from '../../../../utils/modulesUil'; +import { addAuthor } from '../../../../utils/embeds.util'; +import { addPermissionsNames } from '../../../../utils/modules.uil'; import guildService from '../../../../services/guild.service'; export default { diff --git a/src/modules/auditLogs/events/guild/guildRoleUpdate.ts b/src/modules/auditLogs/events/guild/guildRoleUpdate.ts index d717c58..a1dedfd 100644 --- a/src/modules/auditLogs/events/guild/guildRoleUpdate.ts +++ b/src/modules/auditLogs/events/guild/guildRoleUpdate.ts @@ -9,8 +9,8 @@ import { } from 'discord.js'; import { Emojis } from '../../../../utils/consts'; import { IAuditLogsModule } from 'adroi.d.ea'; -import { addAuthor } from '../../../../utils/embedsUtil'; -import { addComparedPermissionsNames } from '../../../../utils/modulesUil'; +import { addAuthor } from '../../../../utils/embeds.util'; +import { addComparedPermissionsNames } from '../../../../utils/modules.uil'; import guildService from '../../../../services/guild.service'; export default { diff --git a/src/modules/auditLogs/events/guild_members/guildMemberAdd.ts b/src/modules/auditLogs/events/guild_members/guildMemberAdd.ts index 7eae169..c939d16 100644 --- a/src/modules/auditLogs/events/guild_members/guildMemberAdd.ts +++ b/src/modules/auditLogs/events/guild_members/guildMemberAdd.ts @@ -1,9 +1,9 @@ import { Client, EmbedBuilder, Events, GuildMember } from 'discord.js'; import { Colors, Emojis } from '../../../../utils/consts'; import { IAuditLogsModule } from 'adroi.d.ea'; -import { addAuthor } from '../../../../utils/embedsUtil'; +import { addAuthor } from '../../../../utils/embeds.util'; import guildService from '../../../../services/guild.service'; -import { timestampToDate } from '../../../../utils/botUtil'; +import { timestampToDate } from '../../../../utils/bot.util'; export default { name: Events.GuildMemberAdd, diff --git a/src/modules/auditLogs/events/guild_members/guildMemberRemove.ts b/src/modules/auditLogs/events/guild_members/guildMemberRemove.ts index 41906da..367a520 100644 --- a/src/modules/auditLogs/events/guild_members/guildMemberRemove.ts +++ b/src/modules/auditLogs/events/guild_members/guildMemberRemove.ts @@ -1,8 +1,8 @@ import { Client, EmbedBuilder, Events, GuildMember, inlineCode } from 'discord.js'; import { Colors, Emojis } from '../../../../utils/consts'; import { IAuditLogsModule } from 'adroi.d.ea'; -import { addAuthor } from '../../../../utils/embedsUtil'; -import { detailedShortDate } from '../../../../utils/botUtil'; +import { addAuthor } from '../../../../utils/embeds.util'; +import { detailedShortDate } from '../../../../utils/bot.util'; import guildService from '../../../../services/guild.service'; export default { diff --git a/src/modules/auditLogs/events/guild_members/guildMemberUpdate.ts b/src/modules/auditLogs/events/guild_members/guildMemberUpdate.ts index 111492e..18dcce4 100644 --- a/src/modules/auditLogs/events/guild_members/guildMemberUpdate.ts +++ b/src/modules/auditLogs/events/guild_members/guildMemberUpdate.ts @@ -7,8 +7,8 @@ import { userMention } from 'discord.js'; import { IAuditLogsModule } from 'adroi.d.ea'; -import { addAuthor } from '../../../../utils/embedsUtil'; -import { canSendMessage } from '../../../../utils/botUtil'; +import { addAuthor } from '../../../../utils/embeds.util'; +import { canSendMessage } from '../../../../utils/bot.util'; import guildService from '../../../../services/guild.service'; export default { diff --git a/src/modules/auditLogs/events/guild_messages/messageBulkDelete.ts b/src/modules/auditLogs/events/guild_messages/messageBulkDelete.ts index 0126e61..3f95e4a 100644 --- a/src/modules/auditLogs/events/guild_messages/messageBulkDelete.ts +++ b/src/modules/auditLogs/events/guild_messages/messageBulkDelete.ts @@ -12,7 +12,7 @@ import { userMention } from 'discord.js'; import { IAuditLogsModule } from 'adroi.d.ea'; -import { canSendMessage } from '../../../../utils/botUtil'; +import { canSendMessage } from '../../../../utils/bot.util'; import guildService from '../../../../services/guild.service'; export default { diff --git a/src/modules/auditLogs/events/guild_messages/messageDelete.ts b/src/modules/auditLogs/events/guild_messages/messageDelete.ts index deae547..a42967a 100644 --- a/src/modules/auditLogs/events/guild_messages/messageDelete.ts +++ b/src/modules/auditLogs/events/guild_messages/messageDelete.ts @@ -1,8 +1,8 @@ import { Client, EmbedBuilder, Events, GuildBasedChannel, Message } from 'discord.js'; import { Colors, Emojis } from '../../../../utils/consts'; import { IAuditLogsModule } from 'adroi.d.ea'; -import { addAuthor } from '../../../../utils/embedsUtil'; -import { canSendMessage } from '../../../../utils/botUtil'; +import { addAuthor } from '../../../../utils/embeds.util'; +import { canSendMessage } from '../../../../utils/bot.util'; import guildService from '../../../../services/guild.service'; export default { diff --git a/src/modules/auditLogs/events/guild_messages/messageUpdate.ts b/src/modules/auditLogs/events/guild_messages/messageUpdate.ts index 4b0f2b6..44a9039 100644 --- a/src/modules/auditLogs/events/guild_messages/messageUpdate.ts +++ b/src/modules/auditLogs/events/guild_messages/messageUpdate.ts @@ -1,7 +1,7 @@ import { Client, EmbedBuilder, Events, GuildBasedChannel, Message } from 'discord.js'; import { IAuditLogsModule } from 'adroi.d.ea'; -import { addAuthor } from '../../../../utils/embedsUtil'; -import { canSendMessage } from '../../../../utils/botUtil'; +import { addAuthor } from '../../../../utils/embeds.util'; +import { canSendMessage } from '../../../../utils/bot.util'; import guildService from '../../../../services/guild.service'; export default { diff --git a/src/modules/core/commands/misc/report.ts b/src/modules/core/commands/misc/report.ts index cbd2f01..ec92413 100644 --- a/src/modules/core/commands/misc/report.ts +++ b/src/modules/core/commands/misc/report.ts @@ -8,7 +8,7 @@ import { PermissionsBitField } from 'discord.js'; import { Channels, Colors, Guilds } from '../../../../utils/consts'; -import { addAuthor } from '../../../../utils/embedsUtil'; +import { addAuthor } from '../../../../utils/embeds.util'; export default { data: { diff --git a/src/modules/core/commands/moderation/changelog.ts b/src/modules/core/commands/moderation/changelog.ts index 849747b..1192a17 100644 --- a/src/modules/core/commands/moderation/changelog.ts +++ b/src/modules/core/commands/moderation/changelog.ts @@ -7,7 +7,7 @@ import { } from 'discord.js'; import { CustomErrors } from '../../../../utils/errors'; import { OWNER_ID } from '../../../../utils/consts'; -import { sendChangeLogRow } from '../../components/buttons/sendChangelogBtn'; +import { sendChangeLogRow } from '../../components/buttons/sendChangelog.button'; export default { data: { diff --git a/src/modules/core/commands/moderation/purge.ts b/src/modules/core/commands/moderation/purge.ts index 0e6bc25..ab70041 100644 --- a/src/modules/core/commands/moderation/purge.ts +++ b/src/modules/core/commands/moderation/purge.ts @@ -8,10 +8,10 @@ import { PermissionsBitField, TextChannel } from 'discord.js'; -import { Embed, addAuthor } from '../../../../utils/embedsUtil'; +import { Embed, addAuthor } from '../../../../utils/embeds.util'; import { CustomErrors } from '../../../../utils/errors'; import { IGuild } from 'adroi.d.ea'; -import { hasBotPermission } from '../../../../utils/botUtil'; +import { hasBotPermission } from '../../../../utils/bot.util'; export default { data: { @@ -40,8 +40,9 @@ export default { examples: ['purge 10', 'purge 100 @adan_ea'], async execute(client: Client, interaction: ChatInputCommandInteraction, guildSettings: IGuild) { - if (!hasBotPermission(interaction.guild!, [PermissionsBitField.Flags.ManageMessages])) - throw CustomErrors.SelfNoPermissionsError; + const permissions = [PermissionsBitField.Flags.ManageMessages]; + if (!hasBotPermission(interaction.guild!, permissions)) + throw CustomErrors.SelfNoPermissionsError(interaction.guild!, permissions); const amountToDelete = interaction.options.getNumber('montant', true); if (amountToDelete > 100 || amountToDelete < 0) { diff --git a/src/modules/core/components/buttons/sendChangelogBtn.ts b/src/modules/core/components/buttons/sendChangelog.button.ts similarity index 98% rename from src/modules/core/components/buttons/sendChangelogBtn.ts rename to src/modules/core/components/buttons/sendChangelog.button.ts index fc055e8..173255c 100644 --- a/src/modules/core/components/buttons/sendChangelogBtn.ts +++ b/src/modules/core/components/buttons/sendChangelog.button.ts @@ -7,7 +7,7 @@ import { GuildTextBasedChannel } from 'discord.js'; import { IGuild } from 'adroi.d.ea'; -import { client } from '../../../..'; +import { client } from '../../../../..'; import { getGuildsCache } from '../../tasks/createCache.cron'; const sendChangelogBtn = new ButtonBuilder() diff --git a/src/modules/core/events/client/interactionCreate.ts b/src/modules/core/events/client/interactionCreate.ts index 2e35046..b66afcc 100644 --- a/src/modules/core/events/client/interactionCreate.ts +++ b/src/modules/core/events/client/interactionCreate.ts @@ -15,13 +15,13 @@ import { UserSelectMenuInteraction } from 'discord.js'; import { CustomError, CustomErrors } from '../../../../utils/errors'; -import { Embed } from '../../../../utils/embedsUtil'; +import { Embed } from '../../../../utils/embeds.util'; import { IDiscordClient } from '../../../../client'; import { IGuild } from 'adroi.d.ea'; -import { client } from '../../../../'; +import { client } from '../../../../..'; import guildService from '../../../../services/guild.service'; -import { hasMemberPermission } from '../../../../utils/memberUtil'; -import { timestampToDate } from '../../../../utils/botUtil'; +import { hasMemberPermission } from '../../../../utils/member.util'; +import { timestampToDate } from '../../../../utils/bot.util'; export default { name: Events.InteractionCreate, @@ -53,6 +53,17 @@ const handleCommandInteraction = async ( interaction: CommandInteraction ) => { const guildSettings: IGuild = await guildService.getOrCreateGuild(interaction.guild!); + if (interaction.isUserContextMenuCommand()) { + try { + const contextMenu = client.contextMenus.get(interaction.commandName); + if (contextMenu) { + await contextMenu.execute(interaction, guildSettings); + } + } catch (err) { + handleError(interaction, err); + } + return; + } const command = client.commands.get(interaction.commandName); try { diff --git a/src/modules/core/tasks/customProfilePicture.cron.ts b/src/modules/core/tasks/customProfilePicture.cron.ts index a8b936d..09cf7ba 100644 --- a/src/modules/core/tasks/customProfilePicture.cron.ts +++ b/src/modules/core/tasks/customProfilePicture.cron.ts @@ -1,7 +1,7 @@ import { Guild } from 'discord.js'; import { Guilds } from '../../../utils/consts'; import Logger from '../../../utils/logger'; -import { client } from '../../../'; +import { client } from '../../../..'; import cron from 'node-cron'; const dpp = { diff --git a/src/modules/jail/components/contextMenus/jail.contextMenu.ts b/src/modules/jail/components/contextMenus/jail.contextMenu.ts new file mode 100644 index 0000000..597fd65 --- /dev/null +++ b/src/modules/jail/components/contextMenus/jail.contextMenu.ts @@ -0,0 +1,82 @@ +import { + ApplicationCommandType, + ContextMenuCommandBuilder, + GuildBasedChannel, + GuildMember, + PermissionsBitField, + UserContextMenuCommandInteraction +} from 'discord.js'; +import { IGuild, IJailModule } from 'adroi.d.ea'; +import { CustomErrors } from '../../../../utils/errors'; +import { hasBotPermission } from '../../../../utils/bot.util'; +import jailQueue from '../../tasks/jail.queue'; + +export const jailContextMenu = new ContextMenuCommandBuilder() + .setName('Prison pour temps aléatoire') + .setType(ApplicationCommandType.User) + .setDefaultMemberPermissions(PermissionsBitField.Flags.MoveMembers); + +export default { + data: jailContextMenu.toJSON(), + async execute(interaction: UserContextMenuCommandInteraction, guildSettings: IGuild) { + const permissions = [ + PermissionsBitField.Flags.MoveMembers, + PermissionsBitField.Flags.MuteMembers, + PermissionsBitField.Flags.DeafenMembers + ]; + if (!hasBotPermission(interaction.guild!, permissions)) + throw CustomErrors.SelfNoPermissionsError(interaction.guild!, permissions); + const { jail } = guildSettings.modules; + + // check if the jail module is enabled and if the jail channel is set + if (!jail.enabled) throw CustomErrors.JailDisabledError; + if (!jail.jailChannel) throw CustomErrors.JailChannelNotSetError; + + //fetch the jail channel + const jailChannel = interaction.guild!.channels.cache.get( + jail.jailChannel + ) as GuildBasedChannel; + + //check if the channel is a voice channel + if (!jailChannel?.isVoiceBased()) throw CustomErrors.JailChannelNotVoiceError; + + //check if the target is in a voice channel and not in the jail channel + const target = interaction.targetMember as GuildMember; + const targetVoiceChannel = target.voice.channel; + if (!targetVoiceChannel) throw CustomErrors.JailTargetNotInVoiceError(target.toString()); + if (targetVoiceChannel.id === jailChannel.id) + throw CustomErrors.JailTargetInPrisonError(target.user.displayName); + + // generate a random time for the jail + const jailTime = Math.floor( + Math.random() * (jail.maxTime - jail.minTime + 1) + jail.minTime + ); + + // move the target to the jail channel + await target.voice.setChannel(jailChannel); + await target.voice.setMute(true); + await target.voice.setDeaf(true); + + const message = await jailChannel.send(setMessageContent(jail, target, jailTime)); + + await jailQueue.add( + 'jailJob', + { + targetId: target.id, + guildId: interaction.guild!.id, + initialChannelId: targetVoiceChannel.id, + jailChannelId: jailChannel.id, + messageId: message.id + }, + { delay: jailTime * 1000 } + ); + } +}; + +const setMessageContent = (jail: IJailModule, target: GuildMember, timeJailed: number): string => { + const timestamp = Math.floor(Date.now() / 1000) + timeJailed; + return jail.customMessage + .replace('{target}', target.toString()) + .replace('{timestamp}', ``) + .replace('{time}', timeJailed.toString()); +}; diff --git a/src/modules/jail/models/index.ts b/src/modules/jail/models/index.ts new file mode 100644 index 0000000..5f0ae0a --- /dev/null +++ b/src/modules/jail/models/index.ts @@ -0,0 +1,3 @@ +import { jailSchema } from './jail.model'; + +export { jailSchema }; diff --git a/src/modules/jail/models/jail.model.ts b/src/modules/jail/models/jail.model.ts new file mode 100644 index 0000000..7f52f95 --- /dev/null +++ b/src/modules/jail/models/jail.model.ts @@ -0,0 +1,11 @@ +import { IJailModule } from 'adroi.d.ea'; +import mongoose from 'mongoose'; + +export const jailSchema = new mongoose.Schema({ + enabled: Boolean, + jailChannel: String, + minTime: Number, + maxTime: Number, + customMessage: String +}); + diff --git a/src/modules/jail/tasks/jail.queue.ts b/src/modules/jail/tasks/jail.queue.ts new file mode 100644 index 0000000..413a62f --- /dev/null +++ b/src/modules/jail/tasks/jail.queue.ts @@ -0,0 +1,14 @@ +import { Queue } from 'bullmq'; +import { connection } from '../../../..'; + +const connectionOptions = { + connection, + defaultJobOptions: { + removeOnComplete: true, + removeOnFail: 1000, + } +}; + +const jailQueue = new Queue('jailQueue', connectionOptions); + +export default jailQueue; diff --git a/src/modules/jail/tasks/jail.worker.ts b/src/modules/jail/tasks/jail.worker.ts new file mode 100644 index 0000000..c469b79 --- /dev/null +++ b/src/modules/jail/tasks/jail.worker.ts @@ -0,0 +1,38 @@ +import { client, connection } from '../../../..'; +import { Worker as BullWorker } from 'bullmq'; + +const connectionOptions = { + connection, + defaultJobOptions: { + removeOnComplete: true, + removeOnFail: 1000, + } +}; + +const worker = new BullWorker( + 'jailQueue', + async job => { + const { targetId, guildId, initialChannelId, jailChannelId, messageId } = job.data; + + const guild = await client.guilds.fetch(guildId); + const target = await guild.members.fetch(targetId); + + await target.voice.setMute(false); + await target.voice.setDeaf(false); + + if (!target.voice.channel) return; + const jailChannel = guild.channels.cache.get(jailChannelId); + const message = await jailChannel.messages.fetch(messageId); + + await target.voice.setChannel(initialChannelId); + + if (message.deletable) { + await message.delete(); + } + }, + connectionOptions +); + +worker.on('failed', (job, err) => { + console.error(`Job ${job?.id} failed with error ${err.message}`); +}); diff --git a/src/modules/qotd/commands/qotd.ts b/src/modules/qotd/commands/qotd.ts index f0e0a49..eb5477a 100644 --- a/src/modules/qotd/commands/qotd.ts +++ b/src/modules/qotd/commands/qotd.ts @@ -9,12 +9,12 @@ import { userMention } from 'discord.js'; import { Colors, Guilds } from '../../../utils/consts'; -import { Embed, addAuthor } from '../../../utils/embedsUtil'; +import { Embed, addAuthor } from '../../../utils/embeds.util'; import { IGuild, IQOTDModule } from 'adroi.d.ea'; import { adminRow, stealRow } from '../components/buttons'; import { CustomErrors } from '../../../utils/errors'; import { IQuestions } from '../models'; -import { isQOtDModuleEnabled } from '../../../utils/modulesUil'; +import { isQOtDModuleEnabled } from '../../../utils/modules.uil'; import qotddService from '../services/qotd.service'; export default { diff --git a/src/modules/qotd/components/buttons/index.ts b/src/modules/qotd/components/buttons/index.ts index e1b9a92..1b42b03 100644 --- a/src/modules/qotd/components/buttons/index.ts +++ b/src/modules/qotd/components/buttons/index.ts @@ -1,8 +1,8 @@ import { ActionRowBuilder, ButtonBuilder } from 'discord.js'; -import { qotdAcceptButton } from './qotdAcceptBtn'; -import { qotdAcceptStealButton } from './qotdAcceptStealBtn'; -import { qotdBlacklistRejectButton } from './qotdBlacklistRejectBtn'; -import { qotdRejectButton } from './qotdRejectBtn'; +import { qotdAcceptButton } from './qotdAccept.button'; +import { qotdAcceptStealButton } from './qotdAcceptSteal.button'; +import { qotdBlacklistRejectButton } from './qotdBlacklistReject.button'; +import { qotdRejectButton } from './qotdReject.button'; export { qotdAcceptButton, qotdAcceptStealButton, qotdBlacklistRejectButton, qotdRejectButton }; diff --git a/src/modules/qotd/components/buttons/qotdAcceptBtn.ts b/src/modules/qotd/components/buttons/qotdAccept.button.ts similarity index 97% rename from src/modules/qotd/components/buttons/qotdAcceptBtn.ts rename to src/modules/qotd/components/buttons/qotdAccept.button.ts index dd457f3..f573db1 100644 --- a/src/modules/qotd/components/buttons/qotdAcceptBtn.ts +++ b/src/modules/qotd/components/buttons/qotdAccept.button.ts @@ -6,7 +6,7 @@ import { PermissionsBitField, userMention } from 'discord.js'; -import { Embed, addAuthor } from '../../../../utils/embedsUtil'; +import { Embed, addAuthor } from '../../../../utils/embeds.util'; import { CustomErrors } from '../../../../utils/errors'; import { IQuestions } from '../../models'; import qotddService from '../../services/qotd.service'; diff --git a/src/modules/qotd/components/buttons/qotdAcceptStealBtn.ts b/src/modules/qotd/components/buttons/qotdAcceptSteal.button.ts similarity index 94% rename from src/modules/qotd/components/buttons/qotdAcceptStealBtn.ts rename to src/modules/qotd/components/buttons/qotdAcceptSteal.button.ts index 8295ff0..cd1a483 100644 --- a/src/modules/qotd/components/buttons/qotdAcceptStealBtn.ts +++ b/src/modules/qotd/components/buttons/qotdAcceptSteal.button.ts @@ -7,10 +7,10 @@ import { TextBasedChannel, userMention } from 'discord.js'; -import { Embed, addAuthor } from '../../../../utils/embedsUtil'; +import { Embed, addAuthor } from '../../../../utils/embeds.util'; import { Channels } from '../../../../utils/consts'; import { adminRow } from '.'; -import { client } from '../../../..'; +import { client } from '../../../../..'; export const qotdAcceptStealButton = new ButtonBuilder() .setCustomId('qotdAcceptStealBtn') diff --git a/src/modules/qotd/components/buttons/qotdBlacklistRejectBtn.ts b/src/modules/qotd/components/buttons/qotdBlacklistReject.button.ts similarity index 96% rename from src/modules/qotd/components/buttons/qotdBlacklistRejectBtn.ts rename to src/modules/qotd/components/buttons/qotdBlacklistReject.button.ts index 4546b20..465ab6c 100644 --- a/src/modules/qotd/components/buttons/qotdBlacklistRejectBtn.ts +++ b/src/modules/qotd/components/buttons/qotdBlacklistReject.button.ts @@ -6,7 +6,7 @@ import { PermissionsBitField, userMention } from 'discord.js'; -import { Embed, addAuthor } from '../../../../utils/embedsUtil'; +import { Embed, addAuthor } from '../../../../utils/embeds.util'; import { CustomErrors } from '../../../../utils/errors'; import qotddService from '../../services/qotd.service'; diff --git a/src/modules/qotd/components/buttons/qotdRejectBtn.ts b/src/modules/qotd/components/buttons/qotdReject.button.ts similarity index 96% rename from src/modules/qotd/components/buttons/qotdRejectBtn.ts rename to src/modules/qotd/components/buttons/qotdReject.button.ts index 635b0c3..6f619a6 100644 --- a/src/modules/qotd/components/buttons/qotdRejectBtn.ts +++ b/src/modules/qotd/components/buttons/qotdReject.button.ts @@ -6,7 +6,7 @@ import { PermissionsBitField, userMention } from 'discord.js'; -import { Embed, addAuthor } from '../../../../utils/embedsUtil'; +import { Embed, addAuthor } from '../../../../utils/embeds.util'; import { CustomErrors } from '../../../../utils/errors'; import { Emojis } from '../../../../utils/consts'; diff --git a/src/modules/qotd/tasks/qotd.cron.ts b/src/modules/qotd/tasks/qotd.cron.ts index 7a1a2f4..70ad100 100644 --- a/src/modules/qotd/tasks/qotd.cron.ts +++ b/src/modules/qotd/tasks/qotd.cron.ts @@ -1,10 +1,10 @@ -import { Embed, addAuthor } from '../../../utils/embedsUtil'; +import { Embed, addAuthor } from '../../../utils/embeds.util'; import { EmbedBuilder, Guild, MessageType, TextBasedChannel, User } from 'discord.js'; import { IQuestions, QuestionsModel } from '../models'; import { Colors } from '../../../utils/consts'; import { IQOTDModule } from 'adroi.d.ea'; import Logger from '../../../utils/logger'; -import { client } from '../../..'; +import { client } from '../../../..'; import cron from 'node-cron'; import { getGuildsCache } from '../../core/tasks/createCache.cron'; import qotddService from '../services/qotd.service'; diff --git a/src/modules/scheduledEvents/commands/createEvent.ts b/src/modules/scheduledEvents/commands/createEvent.ts index f0ce22b..a5849a1 100644 --- a/src/modules/scheduledEvents/commands/createEvent.ts +++ b/src/modules/scheduledEvents/commands/createEvent.ts @@ -7,7 +7,7 @@ import { import { CustomErrors } from '../../../utils/errors'; import { IEvent } from '../models'; import { IGuild } from 'adroi.d.ea'; -import ScheduledEventService from '../services/scheduledEventService'; +import ScheduledEventService from '../services/scheduledEvent.service'; import { addToAppropriateQueue } from '../tasks/scheduledEvents.queue'; //import { isEventManagementModuleEnabled } from '../../../utils/modulesUil'; diff --git a/src/modules/scheduledEvents/events/guild_scheduled_events/eventUpdate.ts b/src/modules/scheduledEvents/events/guild_scheduled_events/eventUpdate.ts index 73bfccc..5c6e869 100644 --- a/src/modules/scheduledEvents/events/guild_scheduled_events/eventUpdate.ts +++ b/src/modules/scheduledEvents/events/guild_scheduled_events/eventUpdate.ts @@ -8,9 +8,9 @@ import { MessageCreateOptions } from 'discord.js'; import { IGuild } from 'adroi.d.ea'; -import ScheduledEventService from '../../services/scheduledEventService'; +import ScheduledEventService from '../../services/scheduledEvent.service'; import guildService from '../../../../services/guild.service'; -import { timestampToDate } from '../../../../utils/botUtil'; +import { timestampToDate } from '../../../../utils/bot.util'; export default { name: Events.GuildScheduledEventUpdate, diff --git a/src/modules/scheduledEvents/events/guild_scheduled_events/userAdd.ts b/src/modules/scheduledEvents/events/guild_scheduled_events/userAdd.ts index 7d408e7..1de7e0c 100644 --- a/src/modules/scheduledEvents/events/guild_scheduled_events/userAdd.ts +++ b/src/modules/scheduledEvents/events/guild_scheduled_events/userAdd.ts @@ -1,6 +1,6 @@ import { Client, Events, GuildScheduledEvent, TextBasedChannel, User } from 'discord.js'; import { IGuild } from 'adroi.d.ea'; -import ScheduledEventService from '../../services/scheduledEventService'; +import ScheduledEventService from '../../services/scheduledEvent.service'; import guildService from '../../../../services/guild.service'; export default { diff --git a/src/modules/scheduledEvents/events/guild_scheduled_events/userRemove.ts b/src/modules/scheduledEvents/events/guild_scheduled_events/userRemove.ts index 2df7e10..56a67db 100644 --- a/src/modules/scheduledEvents/events/guild_scheduled_events/userRemove.ts +++ b/src/modules/scheduledEvents/events/guild_scheduled_events/userRemove.ts @@ -1,6 +1,6 @@ import { Client, Events, GuildScheduledEvent, TextBasedChannel, User } from 'discord.js'; import { IGuild } from 'adroi.d.ea'; -import ScheduledEventService from '../../services/scheduledEventService'; +import ScheduledEventService from '../../services/scheduledEvent.service'; import guildService from '../../../../services/guild.service'; export default { diff --git a/src/modules/scheduledEvents/services/scheduledEventService.ts b/src/modules/scheduledEvents/services/scheduledEvent.service.ts similarity index 100% rename from src/modules/scheduledEvents/services/scheduledEventService.ts rename to src/modules/scheduledEvents/services/scheduledEvent.service.ts diff --git a/src/modules/scheduledEvents/tasks/scheduledEvents.queue.ts b/src/modules/scheduledEvents/tasks/scheduledEvents.queue.ts index 188803a..077dceb 100644 --- a/src/modules/scheduledEvents/tasks/scheduledEvents.queue.ts +++ b/src/modules/scheduledEvents/tasks/scheduledEvents.queue.ts @@ -1,7 +1,7 @@ import { IEvent } from '../models'; import Logger from '../../../utils/logger'; import { Queue } from 'bullmq'; -import { connection } from '../../..'; +import { connection } from '../../../..'; const connectionOptions = { connection, diff --git a/src/modules/scheduledEvents/tasks/scheduledEvents.worker.ts b/src/modules/scheduledEvents/tasks/scheduledEvents.worker.ts index 1c0ac7c..6994b91 100644 --- a/src/modules/scheduledEvents/tasks/scheduledEvents.worker.ts +++ b/src/modules/scheduledEvents/tasks/scheduledEvents.worker.ts @@ -1,7 +1,7 @@ -import { Job, Worker, WorkerOptions } from 'bullmq'; -import { client, connection } from '../../..'; +import { Worker as BullWorker, Job } from 'bullmq'; +import { client, connection } from '../../../..'; import { IEvent } from '../models'; -import ScheduledEventService from '../services/scheduledEventService'; +import ScheduledEventService from '../services/scheduledEvent.service'; // Fonction pour traiter le Worker 'scheduledEventsReminder' const handleScheduledEventsReminderWorker = async (job: Job) => { @@ -24,12 +24,14 @@ const handleScheduledEventsReminderWorker = async (job: Job) => { }; export default function (): void { - const connectionOptions: WorkerOptions = { connection }; + const connectionOptions = { + connection + }; if (connection.status !== 'ready') { throw new Error('Redis connection is undefined.'); } - const workerScheduledEventsReminder = new Worker( + const workerScheduledEventsReminder = new BullWorker( 'scheduledEventsReminder', handleScheduledEventsReminderWorker, connectionOptions diff --git a/src/modules/tempVoice/commands/voicePrivacy.ts b/src/modules/tempVoice/commands/voicePrivacy.ts index c9de50d..aeac614 100644 --- a/src/modules/tempVoice/commands/voicePrivacy.ts +++ b/src/modules/tempVoice/commands/voicePrivacy.ts @@ -1,8 +1,8 @@ import { ChatInputCommandInteraction, Client, GuildMember, PermissionsBitField } from 'discord.js'; import { CustomErrors } from '../../../utils/errors'; import { IGuild } from 'adroi.d.ea'; -import { buildVoiceEmbed } from '../../../utils/voiceUtil'; -import { isTempVoiceModuleEnabled } from '../../../utils/modulesUil'; +import { buildVoiceEmbed } from '../../../utils/voice.util'; +import { isTempVoiceModuleEnabled } from '../../../utils/modules.uil'; export default { data: { diff --git a/src/modules/tempVoice/components/buttons/index.ts b/src/modules/tempVoice/components/buttons/index.ts index 7fbb68c..7f8e922 100644 --- a/src/modules/tempVoice/components/buttons/index.ts +++ b/src/modules/tempVoice/components/buttons/index.ts @@ -1,14 +1,14 @@ import { ActionRowBuilder, ButtonBuilder } from 'discord.js'; -import { voiceBlacklistAddBtn } from './voiceBlacklistAddBtn'; -import { voiceBlacklistRemoveBtn } from './voiceBlacklistRemoveBtn'; -import { voiceDeleteBtn } from './voiceDeleteBtn'; -import { voiceLimitBtn } from './voiceLimitBtn'; -import { voiceOwnerTransferBtn } from './voiceOwnerTransferBtn'; -import { voicePrivacyBtn } from './voicePrivacyBtn'; -import { voiceSetRTCRegionBtn } from './voiceSetRTCRegionBtn'; -import { voiceWhitelistAddBtn } from './voiceWhitelistAddBtn'; -import { voiceWhitelistRemoveBtn } from './voiceWhitelistRemoveBtn'; -import { voiceWhitelistTempAddBtn } from './voiceWhitelistTempAddBtn'; +import { voiceBlacklistAddBtn } from './voiceBlacklistAdd.button'; +import { voiceBlacklistRemoveBtn } from './voiceBlacklistRemove.button'; +import { voiceDeleteBtn } from './voiceDelete.button'; +import { voiceLimitBtn } from './voiceLimit.button'; +import { voiceOwnerTransferBtn } from './voiceOwnerTransfer.button'; +import { voicePrivacyBtn } from './voicePrivacy.button'; +import { voiceSetRTCRegionBtn } from './voiceSetRTCRegion.button'; +import { voiceWhitelistAddBtn } from './voiceWhitelistAdd.button'; +import { voiceWhitelistRemoveBtn } from './voiceWhitelistRemove.button'; +import { voiceWhitelistTempAddBtn } from './voiceWhitelistTempAdd.button'; export const firstRow = new ActionRowBuilder().addComponents( voiceLimitBtn, diff --git a/src/modules/tempVoice/components/buttons/voiceBlacklistAddBtn.ts b/src/modules/tempVoice/components/buttons/voiceBlacklistAdd.button.ts similarity index 98% rename from src/modules/tempVoice/components/buttons/voiceBlacklistAddBtn.ts rename to src/modules/tempVoice/components/buttons/voiceBlacklistAdd.button.ts index a5d2dfc..61a92ff 100644 --- a/src/modules/tempVoice/components/buttons/voiceBlacklistAddBtn.ts +++ b/src/modules/tempVoice/components/buttons/voiceBlacklistAdd.button.ts @@ -1,6 +1,6 @@ import { ButtonBuilder, ButtonInteraction, ButtonStyle, GuildMember } from 'discord.js'; import { IGuild } from 'adroi.d.ea'; -import { getorCreateUserSettings } from '../../../../utils/modulesUil'; +import { getorCreateUserSettings } from '../../../../utils/modules.uil'; import { voiceBlacklistAddRow } from '../selectMenus'; export const voiceBlacklistAddBtn = new ButtonBuilder() diff --git a/src/modules/tempVoice/components/buttons/voiceBlacklistRemoveBtn.ts b/src/modules/tempVoice/components/buttons/voiceBlacklistRemove.button.ts similarity index 99% rename from src/modules/tempVoice/components/buttons/voiceBlacklistRemoveBtn.ts rename to src/modules/tempVoice/components/buttons/voiceBlacklistRemove.button.ts index 138e7d4..e43be2e 100644 --- a/src/modules/tempVoice/components/buttons/voiceBlacklistRemoveBtn.ts +++ b/src/modules/tempVoice/components/buttons/voiceBlacklistRemove.button.ts @@ -1,7 +1,7 @@ import { ButtonBuilder, ButtonInteraction, ButtonStyle, GuildMember } from 'discord.js'; import { IGuild } from 'adroi.d.ea'; import { buildVoiceBlacklistRemoveRow } from '../selectMenus'; -import { getorCreateUserSettings } from '../../../../utils/modulesUil'; +import { getorCreateUserSettings } from '../../../../utils/modules.uil'; export const voiceBlacklistRemoveBtn = new ButtonBuilder() .setCustomId('voiceBlacklistRemoveBtn') diff --git a/src/modules/tempVoice/components/buttons/voiceDeleteBtn.ts b/src/modules/tempVoice/components/buttons/voiceDelete.button.ts similarity index 87% rename from src/modules/tempVoice/components/buttons/voiceDeleteBtn.ts rename to src/modules/tempVoice/components/buttons/voiceDelete.button.ts index 0b339c5..6c6a3fc 100644 --- a/src/modules/tempVoice/components/buttons/voiceDeleteBtn.ts +++ b/src/modules/tempVoice/components/buttons/voiceDelete.button.ts @@ -1,7 +1,7 @@ import { ButtonBuilder, ButtonInteraction, ButtonStyle } from 'discord.js'; import { CustomErrors } from '../../../../utils/errors'; -import { client } from '../../../..'; -import { voiceDeleteActionRow } from './voiceDeleteConfirmBtn'; +import { client } from '../../../../..'; +import { voiceDeleteActionRow } from './voiceDeleteConfirm.button'; export const voiceDeleteBtn = new ButtonBuilder() .setCustomId('voiceDeleteBtn') diff --git a/src/modules/tempVoice/components/buttons/voiceDeleteConfirmBtn.ts b/src/modules/tempVoice/components/buttons/voiceDeleteConfirm.button.ts similarity index 93% rename from src/modules/tempVoice/components/buttons/voiceDeleteConfirmBtn.ts rename to src/modules/tempVoice/components/buttons/voiceDeleteConfirm.button.ts index 2301bc5..549b84d 100644 --- a/src/modules/tempVoice/components/buttons/voiceDeleteConfirmBtn.ts +++ b/src/modules/tempVoice/components/buttons/voiceDeleteConfirm.button.ts @@ -6,7 +6,7 @@ import { GuildMember } from 'discord.js'; import { CustomErrors } from '../../../../utils/errors'; -import { isMemberVoiceOwner } from '../../../../utils/voiceUtil'; +import { isMemberVoiceOwner } from '../../../../utils/voice.util'; export const voiceDeleteActionRow = new ActionRowBuilder().addComponents( new ButtonBuilder() diff --git a/src/modules/tempVoice/components/buttons/voiceLimitBtn.ts b/src/modules/tempVoice/components/buttons/voiceLimit.button.ts similarity index 86% rename from src/modules/tempVoice/components/buttons/voiceLimitBtn.ts rename to src/modules/tempVoice/components/buttons/voiceLimit.button.ts index 7d4e7a3..b6ef3ef 100644 --- a/src/modules/tempVoice/components/buttons/voiceLimitBtn.ts +++ b/src/modules/tempVoice/components/buttons/voiceLimit.button.ts @@ -1,7 +1,7 @@ import { ButtonBuilder, ButtonInteraction, ButtonStyle } from 'discord.js'; import { CustomErrors } from '../../../../utils/errors'; -import { client } from '../../../..'; -import { voiceLimitModal } from '../modals/voiceLimitModal'; +import { client } from '../../../../..'; +import { voiceLimitModal } from '../modals/voiceLimit.modal'; export const voiceLimitBtn = new ButtonBuilder() .setCustomId('voiceLimitBtn') diff --git a/src/modules/tempVoice/components/buttons/voiceOwnerTransferBtn.ts b/src/modules/tempVoice/components/buttons/voiceOwnerTransfer.button.ts similarity index 96% rename from src/modules/tempVoice/components/buttons/voiceOwnerTransferBtn.ts rename to src/modules/tempVoice/components/buttons/voiceOwnerTransfer.button.ts index 96f7e4c..95759e6 100644 --- a/src/modules/tempVoice/components/buttons/voiceOwnerTransferBtn.ts +++ b/src/modules/tempVoice/components/buttons/voiceOwnerTransfer.button.ts @@ -7,7 +7,7 @@ import { StringSelectMenuBuilder } from 'discord.js'; import { CustomErrors } from '../../../../utils/errors'; -import { isMemberVoiceOwner } from '../../../../utils/voiceUtil'; +import { isMemberVoiceOwner } from '../../../../utils/voice.util'; export const voiceOwnerTransferBtn = new ButtonBuilder() .setCustomId('voiceOwnerTransferBtn') diff --git a/src/modules/tempVoice/components/buttons/voicePrivacyBtn.ts b/src/modules/tempVoice/components/buttons/voicePrivacy.button.ts similarity index 96% rename from src/modules/tempVoice/components/buttons/voicePrivacyBtn.ts rename to src/modules/tempVoice/components/buttons/voicePrivacy.button.ts index 5cb2f57..5686888 100644 --- a/src/modules/tempVoice/components/buttons/voicePrivacyBtn.ts +++ b/src/modules/tempVoice/components/buttons/voicePrivacy.button.ts @@ -3,10 +3,10 @@ import { isMemberVoiceOwner, isVoicePrivate, switchVoicePrivacy -} from '../../../../utils/voiceUtil'; +} from '../../../../utils/voice.util'; import { CustomErrors } from '../../../../utils/errors'; import { IGuild } from 'adroi.d.ea'; -import { getorCreateUserSettings } from '../../../../utils/modulesUil'; +import { getorCreateUserSettings } from '../../../../utils/modules.uil'; export const voicePrivacyBtn = new ButtonBuilder() .setCustomId('voicePrivacyBtn') diff --git a/src/modules/tempVoice/components/buttons/voiceSetRTCRegionBtn.ts b/src/modules/tempVoice/components/buttons/voiceSetRTCRegion.button.ts similarity index 95% rename from src/modules/tempVoice/components/buttons/voiceSetRTCRegionBtn.ts rename to src/modules/tempVoice/components/buttons/voiceSetRTCRegion.button.ts index 718807b..0a7136d 100644 --- a/src/modules/tempVoice/components/buttons/voiceSetRTCRegionBtn.ts +++ b/src/modules/tempVoice/components/buttons/voiceSetRTCRegion.button.ts @@ -1,7 +1,7 @@ import { ButtonBuilder, ButtonInteraction, ButtonStyle, Collection, VoiceRegion } from 'discord.js'; import { CustomErrors } from '../../../../utils/errors'; import { buildVoiceSetRTCRegionActionRow } from '../selectMenus'; -import { client } from '../../../..'; +import { client } from '../../../../..'; export const voiceSetRTCRegionBtn = new ButtonBuilder() .setCustomId('voiceSetRTCRegionBtn') diff --git a/src/modules/tempVoice/components/buttons/voiceWhitelistAddBtn.ts b/src/modules/tempVoice/components/buttons/voiceWhitelistAdd.button.ts similarity index 98% rename from src/modules/tempVoice/components/buttons/voiceWhitelistAddBtn.ts rename to src/modules/tempVoice/components/buttons/voiceWhitelistAdd.button.ts index 3467626..b937fb6 100644 --- a/src/modules/tempVoice/components/buttons/voiceWhitelistAddBtn.ts +++ b/src/modules/tempVoice/components/buttons/voiceWhitelistAdd.button.ts @@ -1,6 +1,6 @@ import { ButtonBuilder, ButtonInteraction, ButtonStyle, GuildMember } from 'discord.js'; import { IGuild } from 'adroi.d.ea'; -import { getorCreateUserSettings } from '../../../../utils/modulesUil'; +import { getorCreateUserSettings } from '../../../../utils/modules.uil'; import { voiceWhitelistAddRow } from '../selectMenus'; export const voiceWhitelistAddBtn = new ButtonBuilder() diff --git a/src/modules/tempVoice/components/buttons/voiceWhitelistRemoveBtn.ts b/src/modules/tempVoice/components/buttons/voiceWhitelistRemove.button.ts similarity index 99% rename from src/modules/tempVoice/components/buttons/voiceWhitelistRemoveBtn.ts rename to src/modules/tempVoice/components/buttons/voiceWhitelistRemove.button.ts index dbf73aa..972b98e 100644 --- a/src/modules/tempVoice/components/buttons/voiceWhitelistRemoveBtn.ts +++ b/src/modules/tempVoice/components/buttons/voiceWhitelistRemove.button.ts @@ -1,7 +1,7 @@ import { ButtonBuilder, ButtonInteraction, ButtonStyle, GuildMember } from 'discord.js'; import { IGuild } from 'adroi.d.ea'; import { buildVoiceWhitelistRemoveRow } from '../selectMenus'; -import { getorCreateUserSettings } from '../../../../utils/modulesUil'; +import { getorCreateUserSettings } from '../../../../utils/modules.uil'; export const voiceWhitelistRemoveBtn = new ButtonBuilder() .setCustomId('voiceWhitelistRemoveBtn') .setEmoji('<:untrust:1177755536679251978>') diff --git a/src/modules/tempVoice/components/buttons/voiceWhitelistTempAddBtn.ts b/src/modules/tempVoice/components/buttons/voiceWhitelistTempAdd.button.ts similarity index 100% rename from src/modules/tempVoice/components/buttons/voiceWhitelistTempAddBtn.ts rename to src/modules/tempVoice/components/buttons/voiceWhitelistTempAdd.button.ts diff --git a/src/modules/tempVoice/components/modals/voiceLimitModal.ts b/src/modules/tempVoice/components/modals/voiceLimit.modal.ts similarity index 95% rename from src/modules/tempVoice/components/modals/voiceLimitModal.ts rename to src/modules/tempVoice/components/modals/voiceLimit.modal.ts index 533ab58..292ec2c 100644 --- a/src/modules/tempVoice/components/modals/voiceLimitModal.ts +++ b/src/modules/tempVoice/components/modals/voiceLimit.modal.ts @@ -8,7 +8,7 @@ import { TextInputStyle } from 'discord.js'; import { CustomErrors } from '../../../../utils/errors'; -import { setVoiceLimit } from '../../../../utils/voiceUtil'; +import { setVoiceLimit } from '../../../../utils/voice.util'; export const voiceLimitModal = new ModalBuilder() .setCustomId('voiceLimitModal') diff --git a/src/modules/tempVoice/components/selectMenus/index.ts b/src/modules/tempVoice/components/selectMenus/index.ts index dcb6d68..1721d6d 100644 --- a/src/modules/tempVoice/components/selectMenus/index.ts +++ b/src/modules/tempVoice/components/selectMenus/index.ts @@ -1,9 +1,9 @@ -import { buildVoiceBlacklistRemoveRow } from './voiceBlacklistRemoveMenu'; -import { buildVoiceSetRTCRegionActionRow } from './voiceSetRTCRegionMenu'; -import { buildVoiceWhitelistRemoveRow } from './voiceWhitelistRemoveMenu'; -import { voiceBlacklistAddRow } from './voiceBlacklistAddMenu'; -import { voiceWhitelistAddRow } from './voiceWhitelistAddMenu'; -import { voiceWhitelistTempAddRow } from './voiceWhitelistTempAddMenu'; +import { buildVoiceBlacklistRemoveRow } from './voiceBlacklistRemove.selectMenu'; +import { buildVoiceSetRTCRegionActionRow } from './voiceSetRTCRegion.selectMenu'; +import { buildVoiceWhitelistRemoveRow } from './voiceWhitelistRemove.selectMenu'; +import { voiceBlacklistAddRow } from './voiceBlacklistAdd.selectMenu'; +import { voiceWhitelistAddRow } from './voiceWhitelistAdd.selectMenu'; +import { voiceWhitelistTempAddRow } from './voiceWhitelistTempAdd.selectMenu'; export { buildVoiceBlacklistRemoveRow, diff --git a/src/modules/tempVoice/components/selectMenus/voiceBlacklistAddMenu.ts b/src/modules/tempVoice/components/selectMenus/voiceBlacklistAdd.selectMenu.ts similarity index 96% rename from src/modules/tempVoice/components/selectMenus/voiceBlacklistAddMenu.ts rename to src/modules/tempVoice/components/selectMenus/voiceBlacklistAdd.selectMenu.ts index ea4e1cc..dc580e2 100644 --- a/src/modules/tempVoice/components/selectMenus/voiceBlacklistAddMenu.ts +++ b/src/modules/tempVoice/components/selectMenus/voiceBlacklistAdd.selectMenu.ts @@ -8,8 +8,8 @@ import { } from 'discord.js'; import { Colors } from '../../../../utils/consts'; import { IGuild } from 'adroi.d.ea'; -import { client } from '../../../..'; -import { formatCustomList } from '../../../../utils/embedsUtil'; +import { client } from '../../../../..'; +import { formatCustomList } from '../../../../utils/embeds.util'; import guildService from '../../../../services/guild.service'; const selectMenu = new UserSelectMenuBuilder() diff --git a/src/modules/tempVoice/components/selectMenus/voiceBlacklistRemoveMenu.ts b/src/modules/tempVoice/components/selectMenus/voiceBlacklistRemove.selectMenu.ts similarity index 96% rename from src/modules/tempVoice/components/selectMenus/voiceBlacklistRemoveMenu.ts rename to src/modules/tempVoice/components/selectMenus/voiceBlacklistRemove.selectMenu.ts index 22b3372..8bf0d50 100644 --- a/src/modules/tempVoice/components/selectMenus/voiceBlacklistRemoveMenu.ts +++ b/src/modules/tempVoice/components/selectMenus/voiceBlacklistRemove.selectMenu.ts @@ -9,8 +9,8 @@ import { } from 'discord.js'; import { Colors } from '../../../../utils/consts'; import { IGuild } from 'adroi.d.ea'; -import { client } from '../../../..'; -import { formatCustomList } from '../../../../utils/embedsUtil'; +import { client } from '../../../../..'; +import { formatCustomList } from '../../../../utils/embeds.util'; import guildService from '../../../../services/guild.service'; const buildSelectMenu = (users: string[]) => { diff --git a/src/modules/tempVoice/components/selectMenus/voiceOwnerTransferMenu.ts b/src/modules/tempVoice/components/selectMenus/voiceOwnerTransfer.selectMenu.ts similarity index 98% rename from src/modules/tempVoice/components/selectMenus/voiceOwnerTransferMenu.ts rename to src/modules/tempVoice/components/selectMenus/voiceOwnerTransfer.selectMenu.ts index d955fef..d81e57b 100644 --- a/src/modules/tempVoice/components/selectMenus/voiceOwnerTransferMenu.ts +++ b/src/modules/tempVoice/components/selectMenus/voiceOwnerTransfer.selectMenu.ts @@ -1,5 +1,5 @@ import { GuildMember, StringSelectMenuInteraction, userMention } from 'discord.js'; -import { isMemberVoiceOwner, switchVoiceOwner } from '../../../../utils/voiceUtil'; +import { isMemberVoiceOwner, switchVoiceOwner } from '../../../../utils/voice.util'; import { CustomErrors } from '../../../../utils/errors'; import { IGuild } from 'adroi.d.ea'; diff --git a/src/modules/tempVoice/components/selectMenus/voiceSetRTCRegionMenu.ts b/src/modules/tempVoice/components/selectMenus/voiceSetRTCRegion.selectMenu.ts similarity index 100% rename from src/modules/tempVoice/components/selectMenus/voiceSetRTCRegionMenu.ts rename to src/modules/tempVoice/components/selectMenus/voiceSetRTCRegion.selectMenu.ts diff --git a/src/modules/tempVoice/components/selectMenus/voiceWhitelistAddMenu.ts b/src/modules/tempVoice/components/selectMenus/voiceWhitelistAdd.selectMenu.ts similarity index 97% rename from src/modules/tempVoice/components/selectMenus/voiceWhitelistAddMenu.ts rename to src/modules/tempVoice/components/selectMenus/voiceWhitelistAdd.selectMenu.ts index 3e11260..35cce18 100644 --- a/src/modules/tempVoice/components/selectMenus/voiceWhitelistAddMenu.ts +++ b/src/modules/tempVoice/components/selectMenus/voiceWhitelistAdd.selectMenu.ts @@ -8,7 +8,7 @@ import { } from 'discord.js'; import { Colors } from '../../../../utils/consts'; import { IGuild } from 'adroi.d.ea'; -import { formatCustomList } from '../../../../utils/embedsUtil'; +import { formatCustomList } from '../../../../utils/embeds.util'; import guildService from '../../../../services/guild.service'; const selectMenu = new UserSelectMenuBuilder() diff --git a/src/modules/tempVoice/components/selectMenus/voiceWhitelistRemoveMenu.ts b/src/modules/tempVoice/components/selectMenus/voiceWhitelistRemove.selectMenu.ts similarity index 96% rename from src/modules/tempVoice/components/selectMenus/voiceWhitelistRemoveMenu.ts rename to src/modules/tempVoice/components/selectMenus/voiceWhitelistRemove.selectMenu.ts index da11236..cb20b74 100644 --- a/src/modules/tempVoice/components/selectMenus/voiceWhitelistRemoveMenu.ts +++ b/src/modules/tempVoice/components/selectMenus/voiceWhitelistRemove.selectMenu.ts @@ -9,8 +9,8 @@ import { } from 'discord.js'; import { Colors } from '../../../../utils/consts'; import { IGuild } from 'adroi.d.ea'; -import { client } from '../../../..'; -import { formatCustomList } from '../../../../utils/embedsUtil'; +import { client } from '../../../../..'; +import { formatCustomList } from '../../../../utils/embeds.util'; import guildService from '../../../../services/guild.service'; const buildSelectMenu = (users: string[]) => { diff --git a/src/modules/tempVoice/components/selectMenus/voiceWhitelistTempAddMenu.ts b/src/modules/tempVoice/components/selectMenus/voiceWhitelistTempAdd.selectMenu.ts similarity index 96% rename from src/modules/tempVoice/components/selectMenus/voiceWhitelistTempAddMenu.ts rename to src/modules/tempVoice/components/selectMenus/voiceWhitelistTempAdd.selectMenu.ts index 755c5b1..9366000 100644 --- a/src/modules/tempVoice/components/selectMenus/voiceWhitelistTempAddMenu.ts +++ b/src/modules/tempVoice/components/selectMenus/voiceWhitelistTempAdd.selectMenu.ts @@ -7,7 +7,7 @@ import { UserSelectMenuInteraction } from 'discord.js'; import { Colors } from '../../../../utils/consts'; -import { formatCustomList } from '../../../../utils/embedsUtil'; +import { formatCustomList } from '../../../../utils/embeds.util'; const selectMenu = new UserSelectMenuBuilder() .setCustomId('voiceWhitelistTempAddMenu') diff --git a/src/modules/tempVoice/events/guild_voices/voiceStateUpdate.ts b/src/modules/tempVoice/events/guild_voices/voiceStateUpdate.ts index ceeedcf..e07dc1d 100644 --- a/src/modules/tempVoice/events/guild_voices/voiceStateUpdate.ts +++ b/src/modules/tempVoice/events/guild_voices/voiceStateUpdate.ts @@ -3,9 +3,9 @@ import { createNewTempChannel, deleteEmptyChannel, switchVoiceOwner -} from '../../../../utils/voiceUtil'; +} from '../../../../utils/voice.util'; import { IGuild } from 'adroi.d.ea'; -import { client } from '../../../..'; +import { client } from '../../../../..'; import guildService from '../../../../services/guild.service'; /** diff --git a/src/modules/twitch/tasks/twitchAlert.cron.ts b/src/modules/twitch/tasks/twitchAlert.cron.ts index 2cab323..3276288 100644 --- a/src/modules/twitch/tasks/twitchAlert.cron.ts +++ b/src/modules/twitch/tasks/twitchAlert.cron.ts @@ -5,9 +5,9 @@ import { buildLiveStartTitle, fetchTwitchStream, randomizeArray -} from '../../../utils/twitchUtil'; +} from '../../../utils/twitch.util'; import { Colors } from '../../../utils/consts'; -import { client } from '../../../index'; +import { client } from '../../../../index'; import cron from 'node-cron'; import { getGuildsCache } from '../../core/tasks/createCache.cron'; import logger from '../../../utils/logger'; diff --git a/src/modules/twitch/tasks/twitchAssignRole.cron.ts b/src/modules/twitch/tasks/twitchAssignRole.cron.ts index 0790aa0..532ba23 100644 --- a/src/modules/twitch/tasks/twitchAssignRole.cron.ts +++ b/src/modules/twitch/tasks/twitchAssignRole.cron.ts @@ -1,6 +1,6 @@ import { Guild, GuildMember, Role } from 'discord.js'; import { ITMStreamersData } from 'adroi.d.ea'; -import { client } from '../../../index'; +import { client } from '../../../../index'; import cron from 'node-cron'; import { getGuildsCache } from '../../core/tasks/createCache.cron'; import logger from '../../../utils/logger'; diff --git a/src/utils/botUtil.ts b/src/utils/bot.util.ts similarity index 60% rename from src/utils/botUtil.ts rename to src/utils/bot.util.ts index 4fa31a4..2f32dd8 100644 --- a/src/utils/botUtil.ts +++ b/src/utils/bot.util.ts @@ -1,4 +1,5 @@ import { Guild, GuildBasedChannel, PermissionsBitField } from 'discord.js'; +import { Emojis } from './consts'; export const hasBotPermission = (guild: Guild, permissionsFlag: bigint[]) => { return guild.members.me!.permissions.has(permissionsFlag); @@ -62,3 +63,40 @@ export const canSendMessage = (channel: GuildBasedChannel | undefined) => { PermissionsBitField.Flags.SendMessagesInThreads ]); }; + +/** + * Checks if the bot has each permission in the provided list and returns a formatted string. + * @param guild - The guild to check permissions in. + * @param permissions - An array of permission flags to check. + * @returns A string with each permission and its status (allowed or denied). + */ +export const listBotPermissions = (guild: Guild, permissions: bigint[]): string => { + let result = ''; + + permissions.forEach(perm => { + const permName = getPermissionName(perm); + const permWithSpaces = permName.replace(/([a-z])([A-Z])|([A-Z])([A-Z][a-z])/g, '$1$3 $2$4'); + + if (hasBotPermission(guild, [perm])) { + result += `> ${Emojis.check} ${permWithSpaces}\n`; + } else { + result += `> ${Emojis.cross} ${permWithSpaces}\n`; + } + }); + + return result; +}; + +/** + * Retrieves the permission name from a permission flag. + * @param perm - The permission flag as a bigint. + * @returns The human-readable name of the permission. + */ +const getPermissionName = (perm: bigint): string => { + for (const [key, value] of Object.entries(PermissionsBitField.Flags)) { + if (value === perm) { + return key; + } + } + return perm.toString(); +}; diff --git a/src/utils/consts.ts b/src/utils/consts.ts index bcd84f7..ed7a29e 100644 --- a/src/utils/consts.ts +++ b/src/utils/consts.ts @@ -54,6 +54,12 @@ export const Modules: Record = { description: 'Module de logs', emoji: '📜' }, + jail: { + name: 'jail', + label: 'Jail', + description: 'Module de la prison', + emoji: '🔒' + }, // party: { // name: 'party', // label: 'Party', @@ -99,3 +105,59 @@ export enum Channels { } export const OWNER_ID = '294916386072035328'; + +export const categories = { + [`${Emojis.cog} Générales`]: [ + 'ManageChannels', + 'ManageGuild', + 'ViewAuditLog', + 'ViewChannel', + 'ViewGuildInsights', + 'ManageRoles', + 'ManageWebhooks', + 'ManageEmojisAndStickers', + 'ManageGuildExpressions' + ], + [`${Emojis.members} Membres`]: [ + 'CreateInstantInvite', + 'KickMembers', + 'BanMembers', + 'ChangeNickname', + 'ManageNicknames', + 'ModerateMembers' + ], + [`${Emojis.event} Evènements`]: ['ManageEvents'], + [`${Emojis.textChannel} Salon textuel`]: [ + 'AddReactions', + 'SendMessages', + 'SendTTSMessages', + 'ManageMessages', + 'EmbedLinks', + 'AttachFiles', + 'ReadMessageHistory', + 'MentionEveryone', + 'UseExternalEmojis', + 'UseApplicationCommands', + 'ManageThreads', + 'CreatePublicThreads', + 'CreatePrivateThreads', + 'UseExternalStickers', + 'SendMessagesInThreads', + 'SendVoiceMessages' + ], + [`${Emojis.voiceChannel} Salon vocal`]: [ + 'PrioritySpeaker', + 'Stream', + 'Connect', + 'Speak', + 'MuteMembers', + 'DeafenMembers', + 'MoveMembers', + 'UseVAD', + 'UseEmbeddedActivities', + 'UseSoundboard', + 'UseExternalSounds' + ], + [`${Emojis.stageChannel} Salon de conférence`]: ['RequestToSpeak'], + [`${Emojis.advanced} Avancées`]: ['Administrator'] +}; \ No newline at end of file diff --git a/src/utils/embedsUtil.ts b/src/utils/embeds.util.ts similarity index 100% rename from src/utils/embedsUtil.ts rename to src/utils/embeds.util.ts diff --git a/src/utils/errors.ts b/src/utils/errors.ts index 8361ca4..c3a7fc7 100644 --- a/src/utils/errors.ts +++ b/src/utils/errors.ts @@ -1,3 +1,6 @@ +import { Guild } from 'discord.js'; +import { listBotPermissions } from './bot.util'; + export class CustomError extends Error {} export const CustomErrors = { @@ -9,7 +12,11 @@ export const CustomErrors = { `Comme dirait Orel San, ça va trop vite. Cette fonction est en cooldown. tu pourras l'utiliser .` ), UserNoPermissionsError: new CustomError("Eh non, t'as pas les droits, cheh !"), - SelfNoPermissionsError: new CustomError("Peux pas faire ça, j'ai pas les droits."), + SelfNoPermissionsError: (guild: Guild, permissions: bigint[]) => + new CustomError( + "Peux pas faire ça, j'ai pas les droits. J'ai besoin de :\n" + + listBotPermissions(guild, permissions) + ), ToDoError: new CustomError("Ca fonctionne, mais t'as pas setup d'erreur pour ce cas encore."), UnknownCommandError: new CustomError( 'Mmh, il semblerait que je ne connais pas cette commande.' @@ -42,6 +49,16 @@ export const CustomErrors = { SwitchVoicePrivacyError: new CustomError("Whoops, j'ai pas réussi à switch l'état du salon."), + //////////////////////////////////////////////////// + // Jail related err // + //////////////////////////////////////////////////// + JailDisabledError: new CustomError("Le module Jail n'est pas activé sur ce serveur."), + JailChannelNotSetError: new CustomError("Le salon de prison n'a pas été défini."), + JailChannelNotVoiceError: new CustomError("Le salon de prison n'est pas un salon vocal."), + JailTargetNotInVoiceError: (target: string) => + new CustomError(`${target} n'est pas dans un salon vocal.`), + JailTargetInPrisonError: (target: string) => new CustomError(`${target} est déjà en prison.`), + //////////////////////////////////////////////////// // Events related err // //////////////////////////////////////////////////// diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 19ea8aa..229fcd8 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,7 +1,7 @@ import { Channels, Colors } from './consts'; import { EmbedBuilder, WebhookClient, codeBlock } from 'discord.js'; import ansis, { AnsiColors } from 'ansis'; -import { client as discordClient } from '../'; +import { client as discordClient } from '../..'; const write = ( content: string, diff --git a/src/utils/memberUtil.ts b/src/utils/member.util.ts similarity index 97% rename from src/utils/memberUtil.ts rename to src/utils/member.util.ts index c3f3b6d..64bea2e 100644 --- a/src/utils/memberUtil.ts +++ b/src/utils/member.util.ts @@ -1,5 +1,5 @@ import { GuildMember, PermissionFlagsBits, PermissionsBitField, Role } from 'discord.js'; -import { hasBotPermission } from './botUtil'; +import { hasBotPermission } from './bot.util'; /** * Adds a role to a guild member if the bot has the necessary permissions. diff --git a/src/utils/modulesUil.ts b/src/utils/modules.uil.ts similarity index 78% rename from src/utils/modulesUil.ts rename to src/utils/modules.uil.ts index c31ea2a..9adf0ca 100644 --- a/src/utils/modulesUil.ts +++ b/src/utils/modules.uil.ts @@ -1,7 +1,7 @@ import { EmbedBuilder, GuildMember, PermissionsBitField } from 'discord.js'; +import { Emojis, categories } from './consts'; import { IGuild, ITVMUserSettings } from 'adroi.d.ea'; import { CustomErrors } from './errors'; -import { Emojis } from './consts'; import guildService from '../services/guild.service'; /** @@ -73,62 +73,6 @@ export const getorCreateUserSettings = async ( return userSettings; }; -const categories = { - [`${Emojis.cog} Générales`]: [ - 'ManageChannels', - 'ManageGuild', - 'ViewAuditLog', - 'ViewChannel', - 'ViewGuildInsights', - 'ManageRoles', - 'ManageWebhooks', - 'ManageEmojisAndStickers', - 'ManageGuildExpressions' - ], - [`${Emojis.members} Membres`]: [ - 'CreateInstantInvite', - 'KickMembers', - 'BanMembers', - 'ChangeNickname', - 'ManageNicknames', - 'ModerateMembers' - ], - [`${Emojis.event} Evènements`]: ['ManageEvents'], - [`${Emojis.textChannel} Salon textuel`]: [ - 'AddReactions', - 'SendMessages', - 'SendTTSMessages', - 'ManageMessages', - 'EmbedLinks', - 'AttachFiles', - 'ReadMessageHistory', - 'MentionEveryone', - 'UseExternalEmojis', - 'UseApplicationCommands', - 'ManageThreads', - 'CreatePublicThreads', - 'CreatePrivateThreads', - 'UseExternalStickers', - 'SendMessagesInThreads', - 'SendVoiceMessages' - ], - [`${Emojis.voiceChannel} Salon vocal`]: [ - 'PrioritySpeaker', - 'Stream', - 'Connect', - 'Speak', - 'MuteMembers', - 'DeafenMembers', - 'MoveMembers', - 'UseVAD', - 'UseEmbeddedActivities', - 'UseSoundboard', - 'UseExternalSounds' - ], - [`${Emojis.stageChannel} Salon de conférence`]: ['RequestToSpeak'], - [`${Emojis.advanced} Avancées`]: ['Administrator'] -}; - export const addPermissionsNames = (permissions: PermissionsBitField, embed: EmbedBuilder) => { const permissionNames: string[] = permissions.toArray(); diff --git a/src/utils/twitchUtil.ts b/src/utils/twitch.util.ts similarity index 100% rename from src/utils/twitchUtil.ts rename to src/utils/twitch.util.ts diff --git a/src/utils/voiceUtil.ts b/src/utils/voice.util.ts similarity index 99% rename from src/utils/voiceUtil.ts rename to src/utils/voice.util.ts index ee93487..f45d32f 100644 --- a/src/utils/voiceUtil.ts +++ b/src/utils/voice.util.ts @@ -13,10 +13,10 @@ import { } from 'discord.js'; import { CustomError, CustomErrors } from './errors'; import { Colors } from './consts'; -import { Embed } from './embedsUtil'; +import { Embed } from './embeds.util'; import { ITempVoiceModule } from 'adroi.d.ea'; import Logger from './logger'; -import { client } from '..'; +import { client } from '../..'; import { handleCooldown } from '../modules/core/events/client/interactionCreate'; import path from 'path'; import { tempVoiceComponents } from '../modules/tempVoice/components/buttons'; diff --git a/tests/unit/utils/botUtil.test.ts b/tests/unit/utils/botUtil.test.ts index d356dd6..159de25 100644 --- a/tests/unit/utils/botUtil.test.ts +++ b/tests/unit/utils/botUtil.test.ts @@ -1,4 +1,4 @@ -import { timestampToDate } from '../../../src/utils/botUtil'; +import { timestampToDate } from '../../../src/utils/bot.util'; describe('timestampToDate', () => { it('correctly converts a timestamp to a date in seconds', () => { diff --git a/tests/unit/utils/embedsUtil.test.ts b/tests/unit/utils/embedsUtil.test.ts index 394c657..0f24db7 100644 --- a/tests/unit/utils/embedsUtil.test.ts +++ b/tests/unit/utils/embedsUtil.test.ts @@ -1,5 +1,5 @@ import { APIEmbedField, channelMention, roleMention, userMention } from 'discord.js'; -import { formatCustomList, formatFields } from '../../../src/utils/embedsUtil'; +import { formatCustomList, formatFields } from '../../../src/utils/embeds.util'; jest.mock('discord.js', () => ({ roleMention: jest.fn((id: string) => `<@&${id}>`), diff --git a/tests/unit/utils/twitchUtil.test.ts b/tests/unit/utils/twitchUtil.test.ts index 7e3294c..e89e9d5 100644 --- a/tests/unit/utils/twitchUtil.test.ts +++ b/tests/unit/utils/twitchUtil.test.ts @@ -1,4 +1,4 @@ -import { Stream, buildLiveStartTitle, randomizeArray } from './../../../src/utils/twitchUtil'; +import { Stream, buildLiveStartTitle, randomizeArray } from './../../../src/utils/twitch.util'; import { ITMAlerts } from 'adroi.d.ea'; describe('randomizeArray', () => { diff --git a/tsconfig.json b/tsconfig.json index ddeeae4..2cb47ed 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -34,5 +34,5 @@ /* Completeness */ "skipLibCheck": true }, - "include": ["src/**/*.ts"] + "include": ["src/**/*.ts", "index.ts"] }