From 5406d113f51cccbb86d5af5ab4c6adb671462836 Mon Sep 17 00:00:00 2001 From: Li Productions <172457372+goldstac@users.noreply.github.com> Date: Fri, 4 Sep 2026 15:03:34 +0400 Subject: [PATCH 1/3] fix: require ManageMessages permission to reset another user's context --- src/commands/ai/resetctx.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/commands/ai/resetctx.ts b/src/commands/ai/resetctx.ts index 16c4fb7..96cfb9e 100644 --- a/src/commands/ai/resetctx.ts +++ b/src/commands/ai/resetctx.ts @@ -1,3 +1,4 @@ +import { PermissionFlagsBits } from "discord.js"; import type { CommandCallbackOpts } from "../../types/command.ts"; import { resetContext } from "../../utils/context.ts"; @@ -5,15 +6,27 @@ export default { name: "resetctx", description: "Reset conversation context for a user", aliases: ["resetcontext", "clearctx", "resetai"], - async execute({ message, args }: CommandCallbackOpts) { + async execute({ message }: CommandCallbackOpts) { if (message.author.bot) return; const targetUser = message.mentions.users.first() || message.author; - const userId = targetUser.id; + const isSelf = targetUser.id === message.author.id; - resetContext(userId); + if (!isSelf) { + const hasPerms = message.member?.permissions.has( + PermissionFlagsBits.ManageMessages, + ); + if (!hasPerms) { + await message.reply( + "You need the **Manage Messages** permission to reset someone else's context.", + ); + return; + } + } + + resetContext(targetUser.id); - if (targetUser.id === message.author.id) { + if (isSelf) { await message.reply("Your conversation context has been reset."); } else { await message.reply( From e7a2f0223b3e83fc862dbdab933ffd2f77d89b0e Mon Sep 17 00:00:00 2001 From: Li Productions <172457372+goldstac@users.noreply.github.com> Date: Fri, 4 Sep 2026 15:06:48 +0400 Subject: [PATCH 2/3] fix: handle null message.member in permission check --- src/commands/ai/resetctx.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/ai/resetctx.ts b/src/commands/ai/resetctx.ts index 96cfb9e..36087f2 100644 --- a/src/commands/ai/resetctx.ts +++ b/src/commands/ai/resetctx.ts @@ -13,9 +13,9 @@ export default { const isSelf = targetUser.id === message.author.id; if (!isSelf) { - const hasPerms = message.member?.permissions.has( - PermissionFlagsBits.ManageMessages, - ); + const hasPerms = + message.member?.permissions.has(PermissionFlagsBits.ManageMessages) ?? + false; if (!hasPerms) { await message.reply( "You need the **Manage Messages** permission to reset someone else's context.", From 47a60cb3399225a728278fc92b82c51d21b197b9 Mon Sep 17 00:00:00 2001 From: Li Productions <172457372+goldstac@users.noreply.github.com> Date: Fri, 4 Sep 2026 20:03:10 +0400 Subject: [PATCH 3/3] fix: only allow users to reset their own context --- src/commands/ai/resetctx.ts | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/src/commands/ai/resetctx.ts b/src/commands/ai/resetctx.ts index 36087f2..4d4b5d9 100644 --- a/src/commands/ai/resetctx.ts +++ b/src/commands/ai/resetctx.ts @@ -1,37 +1,20 @@ -import { PermissionFlagsBits } from "discord.js"; import type { CommandCallbackOpts } from "../../types/command.ts"; import { resetContext } from "../../utils/context.ts"; export default { name: "resetctx", - description: "Reset conversation context for a user", + description: "Reset your conversation context", aliases: ["resetcontext", "clearctx", "resetai"], async execute({ message }: CommandCallbackOpts) { if (message.author.bot) return; - const targetUser = message.mentions.users.first() || message.author; - const isSelf = targetUser.id === message.author.id; - - if (!isSelf) { - const hasPerms = - message.member?.permissions.has(PermissionFlagsBits.ManageMessages) ?? - false; - if (!hasPerms) { - await message.reply( - "You need the **Manage Messages** permission to reset someone else's context.", - ); - return; - } + const mentioned = message.mentions.users.first(); + if (mentioned && mentioned.id !== message.author.id) { + await message.reply("You can only reset your own context."); + return; } - resetContext(targetUser.id); - - if (isSelf) { - await message.reply("Your conversation context has been reset."); - } else { - await message.reply( - `Conversation context for <@${targetUser.id}> has been reset.`, - ); - } + resetContext(message.author.id); + await message.reply("Your conversation context has been reset."); }, };