From 6fda837421b5a1c3daa1bd2e5dce7c62057dfa7a Mon Sep 17 00:00:00 2001 From: Ayaka Date: Mon, 15 Aug 2022 14:43:31 +0800 Subject: [PATCH 1/2] Fix kicking users without banning --- src/helpers/newcomers/kickChatMember.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/helpers/newcomers/kickChatMember.ts b/src/helpers/newcomers/kickChatMember.ts index bcfd4294..a6f28baa 100644 --- a/src/helpers/newcomers/kickChatMember.ts +++ b/src/helpers/newcomers/kickChatMember.ts @@ -11,11 +11,12 @@ export async function kickChatMember(chat: DocumentType, user: User) { // Try kicking the member try { await addKickedUser(chat, user.id) - await bot.telegram.kickChatMember( - chat.id, - user.id, - chat.banUsers ? 0 : parseInt(`${new Date().getTime() / 1000 + 45}`) - ) + if (chat.banUsers) { + await bot.telegram.kickChatMember(chat.id, user.id) + } else { + // unban will kick user from the chat, but will not ban + await bot.telegram.unbanChatMember(chat.id, user.id) + } } catch (err) { report(err, kickChatMember.name) } From a5b9de69daeece6bb60d36b15a08da93a22c01aa Mon Sep 17 00:00:00 2001 From: Ayaka Mikazuki Date: Tue, 16 Aug 2022 09:53:32 +0800 Subject: [PATCH 2/2] Fix infinite ban --- src/helpers/newcomers/kickCandidates.ts | 10 +++++++--- src/helpers/newcomers/kickChatMember.ts | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/helpers/newcomers/kickCandidates.ts b/src/helpers/newcomers/kickCandidates.ts index 2536c55e..ecbda0c0 100644 --- a/src/helpers/newcomers/kickCandidates.ts +++ b/src/helpers/newcomers/kickCandidates.ts @@ -30,7 +30,7 @@ export async function kickCandidates(chat: Chat, candidates: Candidate[]) { kickChatMemberProxy( chat.id, candidate.id, - chat.banUsers ? 0 : parseInt(`${new Date().getTime() / 1000 + 45}`) + chat.banUsers ) } catch (err) { report(err, addKickedUser.name) @@ -52,14 +52,18 @@ export async function kickCandidates(chat: Chat, candidates: Candidate[]) { async function kickChatMemberProxy( id: number, candidateId: number, - duration: number + banUsers: boolean ) { try { if (!chatMembersBeingKicked[id]) { chatMembersBeingKicked[id] = {} } chatMembersBeingKicked[id][candidateId] = true - await bot.telegram.kickChatMember(id, candidateId, duration) + if (banUsers) { + await bot.telegram.kickChatMember(id, candidateId) + } else { + await bot.telegram.unbanChatMember(id, candidateId) // kick without ban + } } catch (err) { report(err, kickChatMemberProxy.name) } finally { diff --git a/src/helpers/newcomers/kickChatMember.ts b/src/helpers/newcomers/kickChatMember.ts index a6f28baa..c662e71e 100644 --- a/src/helpers/newcomers/kickChatMember.ts +++ b/src/helpers/newcomers/kickChatMember.ts @@ -14,8 +14,7 @@ export async function kickChatMember(chat: DocumentType, user: User) { if (chat.banUsers) { await bot.telegram.kickChatMember(chat.id, user.id) } else { - // unban will kick user from the chat, but will not ban - await bot.telegram.unbanChatMember(chat.id, user.id) + await bot.telegram.unbanChatMember(chat.id, user.id) // kick without ban } } catch (err) { report(err, kickChatMember.name)