From 05474d4a1ab8ffb15f5e473e36c47299b6d3b6b8 Mon Sep 17 00:00:00 2001 From: Lorenzo Corallo Date: Sat, 11 Apr 2026 17:41:50 +0200 Subject: [PATCH 1/2] feat: check if bot is admin before group management --- src/lib/group-management/index.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lib/group-management/index.ts b/src/lib/group-management/index.ts index a76f655..a150dc4 100644 --- a/src/lib/group-management/index.ts +++ b/src/lib/group-management/index.ts @@ -48,7 +48,17 @@ async function errorBackend(chat: ChatFullInfo, type: "CREATE" | "UPDATE", fatal type GroupDB = Parameters["tg"]["groups"]["create"]["mutate"]>[0][0] export const GroupManagement = { async create(chatId: number, addedBy: User): Promise> { + const { status } = await modules.shared.api + .getChatMember(chatId, modules.shared.botInfo.id) + .catch(() => ({ status: null })) + if (status !== "administrator") { + const reason = "The bot is not an administrator" + logger.error({ chatId, reason }, "[GroupManagement] Cannot CREATE group") + return err(reason) + } + const chat = await modules.shared.api.getChat(chatId).catch(() => null) + if (!chat) { const reason = "The bot cannot retrieve chat info, probably it is not an administrator" logger.error({ chatId, reason }, "[GroupManagement] Cannot CREATE group") @@ -79,6 +89,15 @@ export const GroupManagement = { }, async update(chatId: number, requestedBy: User): Promise> { + const { status } = await modules.shared.api + .getChatMember(chatId, modules.shared.botInfo.id) + .catch(() => ({ status: null })) + if (status !== "administrator") { + const reason = "The bot is not an administrator" + logger.error({ chatId, reason }, "[GroupManagement] Cannot CREATE group") + return err(reason) + } + const chat = await modules.shared.api.getChat(chatId).catch(() => null) if (!chat) { const reason = "The bot is not in this group or is not an administrator" From 99614025d8c947f4bd841b2d26d09bd0694d9aa2 Mon Sep 17 00:00:00 2001 From: Lorenzo Corallo Date: Sat, 11 Apr 2026 17:50:10 +0200 Subject: [PATCH 2/2] fix: typo --- src/lib/group-management/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/group-management/index.ts b/src/lib/group-management/index.ts index a150dc4..1234b54 100644 --- a/src/lib/group-management/index.ts +++ b/src/lib/group-management/index.ts @@ -94,7 +94,7 @@ export const GroupManagement = { .catch(() => ({ status: null })) if (status !== "administrator") { const reason = "The bot is not an administrator" - logger.error({ chatId, reason }, "[GroupManagement] Cannot CREATE group") + logger.error({ chatId, reason }, "[GroupManagement] Cannot UPDATE group") return err(reason) }