validate IP address format and handle errors in mcs command

This commit is contained in:
Letian Li 2025-04-27 17:26:14 +02:00
parent b8e11d5c5c
commit a55f7f660e

View File

@ -36,6 +36,12 @@ const options = {
export default class McsCommand extends Command { export default class McsCommand extends Command {
async run(ctx: CommandContext<typeof options>) { async run(ctx: CommandContext<typeof options>) {
if (ctx.options.ip && !/^(?!:\/\/)([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(:\d+)?$/.test(ctx.options.ip)) {
await ctx.write({
content: 'Invalid IP address'
})
return
}
const res = await prisma.mcsBind.findFirst({ const res = await prisma.mcsBind.findFirst({
where: { where: {
channelId: ctx.channelId channelId: ctx.channelId
@ -65,7 +71,10 @@ export default class McsCommand extends Command {
}) })
} catch (e) { } catch (e) {
console.error(e) console.error(e)
return `ERROR, ${e}` await ctx.write({
content: `${e}`
})
return
} }
const page = await browser.newPage(); const page = await browser.newPage();