(client: TelegramClient, channelEntity: any, userId: number)
| 206 | if (typeof user === "number") { |
| 207 | return await client.getInputEntity(user); |
| 208 | } |
| 209 | try { |
| 210 | return await client.getInputEntity(user); |
| 211 | } catch { |
| 212 | return new Api.InputPeerUser({ |
| 213 | userId: user.id, |
| 214 | accessHash: user.accessHash ?? (0 as any), |
| 215 | }); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | async function removeChatMember(client: TelegramClient, channelEntity: any, user: Api.User | number): Promise<void> { |
| 220 | const userId = typeof user === "number" ? user : Number(user.id); |
| 221 | try { |
| 222 | const userEntity = await resolveParticipantEntity(client, user); |
| 223 | console.log(`正在移出用户: ${userId}`); |
| 224 | await client.invoke(new Api.channels.EditBanned({ |
| 225 | channel: channelEntity, |
| 226 | participant: userEntity, |
| 227 | bannedRights: new Api.ChatBannedRights({ |
| 228 | untilDate: Math.floor(Date.now() / 1000) + 60, |
| 229 | viewMessages: true, |
| 230 | sendMessages: true, |
| 231 | sendMedia: true, |
| 232 | sendStickers: true, |
| 233 | sendGifs: true, |
| 234 | sendGames: true, |
| 235 | sendInline: true, |
| 236 | sendPolls: true, |
| 237 | changeInfo: true, |
| 238 | inviteUsers: true, |
| 239 | pinMessages: true, |
| 240 | }), |
| 241 | })); |
| 242 | await sleep(2000 + Math.random() * 1000); |
| 243 | await client.invoke(new Api.channels.EditBanned({ |
| 244 | channel: channelEntity, |
| 245 | participant: userEntity, |
| 246 | bannedRights: new Api.ChatBannedRights({ |
| 247 | untilDate: 0, |
| 248 | viewMessages: false, |
| 249 | sendMessages: false, |
| 250 | sendMedia: false, |
| 251 | sendStickers: false, |
| 252 | sendGifs: false, |
| 253 | sendGames: false, |
| 254 | sendInline: false, |
| 255 | sendPolls: false, |
| 256 | changeInfo: false, |
| 257 | inviteUsers: false, |
| 258 | pinMessages: false, |
| 259 | }), |
| 260 | })); |
| 261 | console.log(`用户 ${userId} 已移出并解封,可重新加入`); |
| 262 | } catch (error: any) { |
| 263 | console.error(`移出用户 ${userId} 失败:`, error); |
| 264 | if (error.errorMessage && error.errorMessage.includes("FLOOD_WAIT")) { |
| 265 | const seconds = parseInt(error.errorMessage.match(/\d+/)?.[0] || "60"); |
no test coverage detected