(
client: TelegramClient,
groups: ManagedGroup[],
userId: number,
participant?: any,
reason: string = "跨群违规"
)
| 905 | } |
| 906 | |
| 907 | private static getChatKind(chatId: any): ChatKind { |
| 908 | if (chatId?.kind === 'chat' || chatId?.kind === 'channel') { |
| 909 | return chatId.kind; |
| 910 | } |
| 911 | |
| 912 | const className = chatId?.className; |
| 913 | if (className === 'PeerChat' || className === 'Chat') { |
| 914 | return 'chat'; |
| 915 | } |
| 916 | return 'channel'; |
| 917 | } |
| 918 | |
| 919 | private static getBasicGroupChatId(chatId: any): number { |
| 920 | const id = Number(chatId?.chatId ?? chatId?.id ?? chatId); |
| 921 | return id; |
| 922 | } |
| 923 | |
| 924 | private static async applyBanLikeAction( |
| 925 | client: TelegramClient, |
| 926 | chatId: any, |
| 927 | resolvedParticipant: any, |
| 928 | bannedRights: Api.ChatBannedRights, |
| 929 | action: 'ban' | 'unban' | 'mute' |
| 930 | ): Promise<void> { |
| 931 | const chatKind = this.getChatKind(chatId); |
| 932 | if (chatKind === 'chat') { |
| 933 | if (action === 'unban' || action === 'mute') { |
| 934 | throw new Error('BASIC_GROUP_ACTION_UNSUPPORTED'); |
| 935 | } |
| 936 | |
| 937 | await client.invoke( |
| 938 | new Api.messages.DeleteChatUser({ |
| 939 | chatId: bigInt(this.getBasicGroupChatId(chatId)), |
| 940 | userId: resolvedParticipant, |
| 941 | }) |
| 942 | ); |
| 943 | return; |
| 944 | } |
| 945 | |
| 946 | await client.invoke( |
| 947 | new Api.channels.EditBanned({ |
| 948 | channel: chatId, |
| 949 | participant: resolvedParticipant, |
| 950 | bannedRights, |
| 951 | }) |
| 952 | ); |
| 953 | } |
| 954 | |
| 955 | static async banUser( |
| 956 | client: TelegramClient, |
| 957 | chatId: any, |
| 958 | userId: number, |
| 959 | until: number = 0, |
| 960 | participant?: any |
| 961 | ): Promise<boolean> { |
| 962 | try { |
| 963 | const resolvedParticipant = await this.resolveParticipant(client, userId, participant); |
| 964 | const rights = new Api.ChatBannedRights({ |
no test coverage detected