()
| 1316 | class CommandHandlers { |
| 1317 | // 单群基础命令处理 |
| 1318 | static async handleBasicCommand( |
| 1319 | client: TelegramClient, |
| 1320 | message: Api.Message, |
| 1321 | action: 'kick' | 'ban' | 'unban' | 'mute' | 'unmute' |
| 1322 | ): Promise<void> { |
| 1323 | try { |
| 1324 | // 解析参数 |
| 1325 | const args = message.message?.split(" ").slice(1) || []; |
| 1326 | const { user, uid, participant, resolutionError, chatType } = await UserResolver.resolveTarget(client, message, args); |
| 1327 | |
| 1328 | if (!uid) { |
| 1329 | await MessageManager.smartEdit(message, "❌ 获取用户失败"); |
| 1330 | return; |
| 1331 | } |
| 1332 | |
| 1333 | const basicGroupActionAllowedWithoutParticipant = chatType === 'chat' && ['ban', 'kick'].includes(action); |
| 1334 | if (!participant && ['ban', 'unban', 'mute', 'unmute', 'kick'].includes(action) && !basicGroupActionAllowedWithoutParticipant) { |
| 1335 | const errorText = resolutionError === 'TARGET_ENTITY_UNRESOLVABLE' |
| 1336 | ? '❌ 无法解析该用户ID(会话未见过且不在管理群中)。可先回复其一则消息,或确认 ID 正确' |
| 1337 | : '❌ 获取用户失败'; |
| 1338 | await MessageManager.smartEdit(message, errorText); |
| 1339 | return; |
| 1340 | } |
| 1341 | |
| 1342 | // 检查目标是否为管理员 |
| 1343 | const isAdmin = await PermissionManager.isTargetAdmin(client, message.peerId, uid); |
| 1344 | if (isAdmin) { |
| 1345 | const hasConfirm = args.includes('true'); |
| 1346 | if (!hasConfirm) { |
| 1347 | await MessageManager.smartEdit(message, "⚠️ 目标是管理员,请在命令后加上 <code>true</code> 确认执行"); |
| 1348 | return; |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | const display = UserResolver.formatUser(user, uid); |
| 1353 | const status = await MessageManager.smartEdit( |
| 1354 | message, |
| 1355 | `⏳ ${this.getActionName(action)}${htmlEscape(display)}...`, |
| 1356 | 0 |
| 1357 | ); |
| 1358 | |
| 1359 | let success = false; |
| 1360 | let resultText = ""; |
| 1361 | |
| 1362 | switch (action) { |
| 1363 | case 'kick': |
| 1364 | success = await BanManager.kickUser(client, message.peerId, uid, participant); |
| 1365 | resultText = `✅ 已踢出 ${htmlEscape(display)}`; |
| 1366 | break; |
| 1367 | case 'ban': |
| 1368 | // 先删除消息,再封禁 |
| 1369 | const deleteSuccess = await BanManager.deleteHistoryInCurrentChat(client, message.peerId, uid, participant); |
| 1370 | success = await BanManager.banUser(client, message.peerId, uid, 0, participant); |
| 1371 | const deleteText = deleteSuccess ? '(已清理消息)' : ''; |
| 1372 | resultText = chatType === 'chat' |
| 1373 | ? `✅ 已移出 ${htmlEscape(display)} ${deleteText}` |
| 1374 | : `✅ 已封禁 ${htmlEscape(display)} ${deleteText}`; |
| 1375 | break; |
nothing calls this directly
no test coverage detected