(
client: TelegramClient,
groups: ManagedGroup[],
userId: number,
participant?: any
)
| 1037 | participant?: any |
| 1038 | ): Promise<boolean> { |
| 1039 | try { |
| 1040 | if (this.getChatKind(chatId) === 'chat') { |
| 1041 | return await this.banUser(client, chatId, userId, 0, participant); |
| 1042 | } |
| 1043 | |
| 1044 | const banned = await this.banUser(client, chatId, userId, 0, participant); |
| 1045 | if (!banned) { |
| 1046 | return false; |
| 1047 | } |
| 1048 | |
| 1049 | return await this.unbanUser(client, chatId, userId, participant); |
| 1050 | } catch (error) { |
| 1051 | console.error(`[BanManager] 踢出失败: ${error}`); |
| 1052 | return false; |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | // 删除用户在当前会话的消息(sb命令优化) |
| 1057 | static async deleteHistoryInCurrentChat( |
| 1058 | client: TelegramClient, |
| 1059 | chatId: any, |
| 1060 | userId: number, |
| 1061 | participant?: any |
| 1062 | ): Promise<boolean> { |
| 1063 | try { |
| 1064 | const canDelete = await PermissionManager.canDeleteMessages(client, chatId); |
| 1065 | if (!canDelete) { |
| 1066 | console.log(`[BanManager] 无删除消息权限`); |
| 1067 | return false; |
| 1068 | } |
| 1069 | |
| 1070 | const resolvedParticipant = participant || await client.getEntity(userId); |
| 1071 | |
| 1072 | await client.invoke( |
| 1073 | new Api.channels.DeleteParticipantHistory({ |
| 1074 | channel: chatId, |
| 1075 | participant: resolvedParticipant, |
| 1076 | }) |
| 1077 | ); |
| 1078 | |
| 1079 | console.log(`[BanManager] 成功删除用户 ${userId} 在当前会话的所有消息`); |
| 1080 | return true; |
| 1081 | } catch (error: any) { |
| 1082 | // 静默处理常见错误 |
| 1083 | if (!/CHANNEL_INVALID|CHAT_ADMIN_REQUIRED|USER_NOT_PARTICIPANT/.test(error?.message || "")) { |
| 1084 | console.error(`[BanManager] 删除消息失败: ${error?.message}`); |
| 1085 | } |
| 1086 | return false; |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | static async batchBanUser( |
| 1091 | client: TelegramClient, |
| 1092 | groups: ManagedGroup[], |
| 1093 | userId: number, |
| 1094 | participant?: any, |
| 1095 | reason: string = "跨群违规" |
| 1096 | ): Promise<BatchBanResult> { |
no test coverage detected