Réécriture complète 4.0
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 6m16s

This commit is contained in:
2025-06-09 16:29:12 +02:00
parent f2c6388da6
commit ddd617317c
133 changed files with 8092 additions and 4332 deletions

View File

@@ -1,141 +1,101 @@
// PACKAGES
import { Client, Collection, GatewayIntentBits, REST, Routes, ChatInputCommandInteraction, AutocompleteInteraction, ButtonInteraction, SlashCommandBuilder } from 'discord.js'
import { Player } from 'discord-player'
import { connection, Connection } from 'mongoose'
import path from 'path'
import fs from 'fs'
import 'dotenv/config'
// CUSTOM TYPES
interface CConnection extends Connection {
once: (event: string, listener: (...args: unknown[]) => void) => this
on: (event: string, listener: (...args: unknown[]) => void) => this
}
interface Command {
name: string
description: string
data: SlashCommandBuilder
autocompleteRun: (interaction: AutocompleteInteraction) => unknown
execute: (interaction: ChatInputCommandInteraction) => unknown
}
interface Button {
name: string
description: string
id: string
execute: (interaction: ButtonInteraction) => unknown
}
declare module 'discord.js' {
export interface Client {
commands: Collection<string, Command>
buttons: Collection<string, Button>
disco: { interval: NodeJS.Timeout }
rss: { interval: NodeJS.Timeout }
}
}
// CLIENT INITIALIZATION
const client = new Client({
intents: [
GatewayIntentBits.AutoModerationConfiguration,
GatewayIntentBits.AutoModerationExecution,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildScheduledEvents,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent
],
allowedMentions: { parse: ['roles', 'users', 'everyone'] }
})
client.commands = new Collection()
client.buttons = new Collection()
// PLAYER INITIALIZATION
const player = new Player(client)
// COMMANDS HANDLING
let commands = [] as Command[]
let commandsParsed = 0
let commandsTotal = 0
let commandFolders = fs.readdirSync(path.join(__dirname, './commands'))
commandFolders.forEach(folder => {
if (folder === 'salonpostam' && process.env.DISCORD_APP_ID === '660961595006124052') return
let folderPath = path.join(__dirname, './commands', folder)
let commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith('.ts'))
commandsTotal += commandFiles.length
commandFiles.forEach(async file => {
let command = await import(path.join(folderPath, file))
command = command.default
if ('data' in command && 'execute' in command) {
let commandData = command.data.toJSON()
if (commandData) { client.commands.set(commandData.name, command); commands.push(commandData) }
} else console.log(`[WARNING] The command at ${`${folderPath}/${file}`} is missing a required "data" or "execute" property.`)
commandsParsed++
if (commandsParsed === commandsTotal) {
console.log(`[INFO] ${commandsParsed} commands parsed.`)
// COMMANDS REGISTRATION
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN as string);
(async () => {
try { await rest.put(Routes.applicationCommands(process.env.DISCORD_APP_ID as string), { body: commands }) }
catch (error) { console.error(error) }
})()
}
})
})
// BUTTONS HANDLING
let buttonFiles = fs.readdirSync(path.join(__dirname, './buttons')).filter(file => file.endsWith('.ts'))
buttonFiles.forEach(async file => {
let button = await import(path.join(__dirname, './buttons', file))
button = button.default
if ('id' in button && 'execute' in button) client.buttons.set(button.id, button)
else console.log(`[WARNING] The button ${file} is missing a required "id" or "execute" property.`)
})
// EVENTS HANDLING
let eventClientFiles = fs.readdirSync(path.join(__dirname, './events/client')).filter(file => file.endsWith('.ts'))
eventClientFiles.forEach(async file => {
let event = await import(path.join(__dirname, './events/client', file))
event = event.default
if (event.once) client.once(event.name, (...args: unknown[]) => { event.execute(...args) })
else client.on(event.name, (...args: unknown[]) => { event.execute(...args) })
})
// PLAYER EVENTS HANDLING
let eventsPlayer = fs.readdirSync(path.join(__dirname, './events/player')).filter(file => file.endsWith('.ts'))
eventsPlayer.forEach(async file => {
let event = await import(path.join(__dirname, './events/player', file))
event = event.default
if (event.name === 'debug') return
player.events.on(event.name, (...args: unknown[]) => event.execute(...args))
})
// MONGO EVENTS HANDLING
let eventsMongo = fs.readdirSync(path.join(__dirname, './events/mongo')).filter(file => file.endsWith('.ts'))
eventsMongo.forEach(async file => {
let event = await import(path.join(__dirname, './events/mongo', file))
event = event.default
if (event.once) (connection as CConnection).once(event.name, (...args: unknown[]) => { event.execute(...args, client) })
else (connection as CConnection).on(event.name, (...args: unknown[]) => { event.execute(...args, client) })
})
// LAUNCH
client.login()
// ENVIRONMENT VARIABLES
import "dotenv/config"
const appId = process.env.DISCORD_APP_ID
const token = process.env.DISCORD_TOKEN
if (!appId || !token) {
console.warn(chalk.red("[DiscordJS] Missing DISCORD_APP_ID or DISCORD_TOKEN in environment variables!"))
process.exit(1)
}
// PACKAGES
import { Client, GatewayIntentBits, REST, Routes } from "discord.js"
import { Player } from "discord-player"
import { connection } from "mongoose"
import type { GuildQueueEvents } from "discord-player"
import chalk from "chalk"
import { commandFolders } from "./commands"
import clientEvents from "./events/client"
import mongoEvents from "./events/mongo"
import playerEvents from "./events/player"
import { logConsole, logConsoleDev } from "@/utils/console"
// CLIENT INITIALIZATION
const client = new Client({
intents: [
GatewayIntentBits.AutoModerationConfiguration,
GatewayIntentBits.AutoModerationExecution,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildExpressions,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildScheduledEvents,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent
],
allowedMentions: { parse: ["roles", "users", "everyone"] }
})
// PLAYER INITIALIZATION
const player = new Player(client)
// COMMANDS REGISTRATION
const rest = new REST({ version: "10" }).setToken(token)
void (async () => {
try {
const commands = commandFolders.flatMap(folder => folder.name !== "salonpostam" ? folder.commands.map(command => command.data) : [])
logConsole('discordjs', 'commands_registered', { count: commands.length.toString() })
await rest.put(Routes.applicationCommands(process.env.DISCORD_APP_ID ?? ""), { body: commands })
const sptGuildId = process.env.DISCORD_SPT_GUILD_ID
if (!sptGuildId) return
const commandsSpt = commandFolders.flatMap(folder => folder.name === "salonpostam" ? folder.commands.map(command => command.data) : [])
logConsole('discordjs', 'commands_registered_guild', { count: commandsSpt.length.toString(), guild: 'salonpostam' })
await rest.put(Routes.applicationGuildCommands(appId, sptGuildId), { body: commandsSpt })
}
catch (error) { console.error(error) }
})()
// CLIENT EVENTS REGISTRATION
clientEvents.forEach(event => {
const callback = (...args: unknown[]) => {
logConsoleDev('discordjs', 'event_triggered', { event: event.name.toString() })
event.execute(...args)
}
if (event.once) client.once(event.name, callback)
else client.on(event.name, callback)
})
// MONGO EVENTS REGISTRATION
mongoEvents.forEach(event => {
const callback = (...args: unknown[]) => {
logConsoleDev('mongoose', 'event_triggered', { event: event.name.toString() })
event.execute(...args)
}
if (event.once) connection.once(event.name, callback)
else connection.on(event.name, callback)
})
// PLAYER EVENTS REGISTRATION
playerEvents.forEach(event => {
if (event.name === "debug") return
const callback = (...args: unknown[]) => {
logConsoleDev('discord_player', 'event_triggered', { event: event.name.toString() })
event.execute(...args)
}
player.events.on(event.name as keyof GuildQueueEvents, callback)
})
// LAUNCH
void client.login()
export default client