mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-26 12:41:03 +00:00
feat(bots/discord): improve admin commands
- The reload command now properly reloads configuration changes by skipping the configuration cache - The eval command now sends a file if the output is too long - The eval command now restricts access to the bot token by removing it and sandboxing the input code execution
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { dirname, join } from 'path'
|
||||
import { AdminCommand } from '$/classes/Command'
|
||||
import { join, dirname } from 'path'
|
||||
|
||||
import type { Config } from 'config.schema'
|
||||
|
||||
@@ -8,7 +8,12 @@ export default new AdminCommand({
|
||||
description: 'Reload configuration',
|
||||
async execute(context, trigger) {
|
||||
const { api, logger, discord } = context
|
||||
context.config = ((await import(join(dirname(Bun.main), '..', 'config.js'))) as { default: Config }).default
|
||||
logger.info(`Reload triggered by ${context.executor.tag} (${context.executor.id})`)
|
||||
|
||||
// Apparently the query strings only work with non-Windows "URLs", otherwise it'd just infinitely hang
|
||||
const path = `${Bun.pathToFileURL(join(dirname(Bun.main), '..', 'config.js')).toString()}?cache=${Date.now()}`
|
||||
logger.debug(`Reloading configuration from: ${path}`)
|
||||
context.config = ((await import(path)) as { default: Config }).default
|
||||
|
||||
if ('deferReply' in trigger) await trigger.deferReply({ ephemeral: true })
|
||||
|
||||
@@ -32,6 +37,6 @@ export default new AdminCommand({
|
||||
await discord.client.login(process.env['DISCORD_TOKEN'])
|
||||
|
||||
// @ts-expect-error: TypeScript dum
|
||||
await trigger[('deferReply' in trigger ? 'editReply' : 'reply')]({ content: 'Reloaded configuration' })
|
||||
await trigger['deferReply' in trigger ? 'editReply' : 'reply']({ content: 'Reloaded configuration' })
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user