mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
fix(bots/discord)!: remove guilds config in favor of upcoming impl
This commit is contained in:
@@ -4,19 +4,12 @@
|
||||
* @type {import('./config.schema').Config}
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* ? ADMIN CONFIGURATION
|
||||
* Bot administrators can run destructive commands like /stop, or /register.
|
||||
*
|
||||
* ! The match condition is `any`: If the user ID matches or the member has a specific role in the list, it considers that user as admin.
|
||||
*/
|
||||
admin: {
|
||||
users: ['USER_ID_HERE'],
|
||||
roles: {
|
||||
GUILD_ID_HERE: ['ROLE_ID_HERE'],
|
||||
},
|
||||
},
|
||||
guilds: ['GUILD_ID_HERE'],
|
||||
moderation: {
|
||||
cure: {
|
||||
defaultName: 'Server member',
|
||||
|
||||
@@ -5,7 +5,6 @@ export type Config = {
|
||||
users?: string[]
|
||||
roles?: Record<string, string[]>
|
||||
}
|
||||
guilds: string[]
|
||||
moderation?: {
|
||||
roles: string[]
|
||||
cure?: {
|
||||
|
||||
@@ -1,50 +1,53 @@
|
||||
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'
|
||||
console.log('Deprecated. New implementation to be done.')
|
||||
process.exit(1)
|
||||
|
||||
// Check if token exists
|
||||
// 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'
|
||||
|
||||
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)
|
||||
}
|
||||
// // Check if token exists
|
||||
|
||||
// Group commands by global and guild
|
||||
// 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)
|
||||
// }
|
||||
|
||||
const { global: globalCommands = [], guild: guildCommands = [] } = Object.groupBy(Object.values(discord.commands), c =>
|
||||
c.global ? 'global' : 'guild',
|
||||
)
|
||||
// // Group commands by global and guild
|
||||
|
||||
// Set commands
|
||||
// const { global: globalCommands = [], guild: guildCommands = [] } = Object.groupBy(Object.values(discord.commands), c =>
|
||||
// c.global ? 'global' : 'guild',
|
||||
// )
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(process.env['DISCORD_TOKEN']!)
|
||||
// // Set commands
|
||||
|
||||
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
|
||||
// const rest = new REST({ version: '10' }).setToken(process.env['DISCORD_TOKEN']!)
|
||||
|
||||
logger.info(`Reloaded ${data.length} global commands`)
|
||||
// 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
|
||||
|
||||
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} global commands`)
|
||||
|
||||
logger.info(`Reloaded ${data.length} guild commands for guild ${guildId}`)
|
||||
}
|
||||
} catch (e) {
|
||||
logger.fatal(e)
|
||||
}
|
||||
// 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)
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user