From a55f7f660e9c065cc0e5b45fd05eedc09a14fe06 Mon Sep 17 00:00:00 2001 From: itzdrli Date: Sun, 27 Apr 2025 17:26:14 +0200 Subject: [PATCH] validate IP address format and handle errors in mcs command --- src/commands/mcs.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/commands/mcs.ts b/src/commands/mcs.ts index 58a7d08..0a9b70a 100644 --- a/src/commands/mcs.ts +++ b/src/commands/mcs.ts @@ -36,6 +36,12 @@ const options = { export default class McsCommand extends Command { async run(ctx: CommandContext) { + 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({ where: { channelId: ctx.channelId @@ -65,7 +71,10 @@ export default class McsCommand extends Command { }) } catch (e) { console.error(e) - return `ERROR, ${e}` + await ctx.write({ + content: `${e}` + }) + return } const page = await browser.newPage();