feat(bots/discord): framework changes and new features

- Migrated to a new command framework which looks better and works better
- Fixed commands not being bundled correctly
- Added message (prefix) commands with argument validation
- Added a new CommandErrorType, for invalid arguments
- `/eval` is now a bit safer
- Corrected colors for the coinflip embed
- `/stop` now works even when the bot is not connected to the API
This commit is contained in:
PalmDevs
2024-07-30 21:05:12 +07:00
parent a848a9c896
commit 646ec8da87
36 changed files with 1153 additions and 616 deletions

View File

@@ -1,5 +1,5 @@
import { createLogger } from '@revanced/bot-shared'
import { cp, rename, rm } from 'fs/promises'
import { cp, rm } from 'fs/promises'
const logger = createLogger()

View File

@@ -1,53 +0,0 @@
console.log('Deprecated. New implementation to be done.')
process.exit(1)
// import { REST } from '@discordjs/rest'
// import { getMissingEnvironmentVariables } from '@revanced/bot-shared'
// import { Routes } from 'discord-api-types/v9'
// import type {
// RESTGetCurrentApplicationResult,
// RESTPutAPIApplicationCommandsResult,
// RESTPutAPIApplicationGuildCommandsResult,
// } from 'discord.js'
// import { config, discord, logger } from '../src/context'
// // Check if token exists
// const missingEnvs = getMissingEnvironmentVariables(['DISCORD_TOKEN'])
// if (missingEnvs.length) {
// for (const env of missingEnvs) logger.fatal(`${env} is not defined in environment variables`)
// process.exit(1)
// }
// // Group commands by global and guild
// const { global: globalCommands = [], guild: guildCommands = [] } = Object.groupBy(Object.values(discord.commands), c =>
// c.global ? 'global' : 'guild',
// )
// // Set commands
// const rest = new REST({ version: '10' }).setToken(process.env['DISCORD_TOKEN']!)
// try {
// const app = (await rest.get(Routes.currentApplication())) as RESTGetCurrentApplicationResult
// const data = (await rest.put(Routes.applicationCommands(app.id), {
// body: globalCommands.map(({ data }) => {
// if (!data.dm_permission) data.dm_permission = true
// logger.warn(`Command ${data.name} has no dm_permission set, forcing to true as it is a global command`)
// return data
// }),
// })) as RESTPutAPIApplicationCommandsResult
// logger.info(`Reloaded ${data.length} global commands`)
// for (const guildId of config.guilds) {
// const data = (await rest.put(Routes.applicationGuildCommands(app.id, guildId), {
// body: guildCommands.map(x => x.data),
// })) as RESTPutAPIApplicationGuildCommandsResult
// logger.info(`Reloaded ${data.length} guild commands for guild ${guildId}`)
// }
// } catch (e) {
// logger.fatal(e)
// }