(
msg: Api.Message,
channel: any,
arg?: string
)
| 916 | const client = await getGlobalClient(); |
| 917 | if (!client) throw new Error("Telegram 客户端未初始化"); |
| 918 | |
| 919 | if (messageHasReply(msg)) { |
| 920 | const reply = await safeGetReplyMessage(msg); |
| 921 | if (!reply) return {}; |
| 922 | |
| 923 | let sender: any; |
| 924 | try { |
| 925 | sender = await (reply as any).getSender?.(); |
| 926 | } catch { |
| 927 | sender = undefined; |
| 928 | } |
| 929 | |
| 930 | if (sender instanceof Api.User) { |
| 931 | const input = await client.getInputEntity(sender.id); |
| 932 | return { id: Number(sender.id), entity: input }; |
| 933 | } |
| 934 | |
| 935 | const fromId: any = reply.fromId as any; |
| 936 | const uid = Number(fromId?.userId); |
| 937 | if (!uid) return {}; |
| 938 | |
| 939 | try { |
| 940 | const input = await client.getInputEntity(uid); |
| 941 | const full = await client.getEntity(input); |
| 942 | if (full instanceof Api.User) { |
| 943 | return { id: Number(full.id), entity: input }; |
| 944 | } |
| 945 | } catch { |
| 946 | return {}; |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | if (!arg) return {}; |
| 951 | |
| 952 | try { |
| 953 | const full = await client.getEntity(arg as any); |
| 954 | if (!(full instanceof Api.User)) return {}; |
| 955 | const input = await client.getInputEntity(full.id); |
| 956 | return { id: Number(full.id), entity: input }; |
| 957 | } catch { |
| 958 | const numericId = Number(arg); |
| 959 | if (!Number.isFinite(numericId)) return {}; |
| 960 | |
| 961 | try { |
| 962 | let offset = 0; |
| 963 | const limit = 200; |
| 964 | for (let i = 0; i < 5; i++) { |
| 965 | const result: any = await client.invoke( |
| 966 | new Api.channels.GetParticipants({ |
| 967 | channel, |
| 968 | filter: new Api.ChannelParticipantsRecent(), |
| 969 | offset, |
| 970 | limit, |
| 971 | hash: 0 as any, |
| 972 | }) |
| 973 | ); |
| 974 | const participants: any[] = result?.participants || []; |
| 975 | const users: any[] = result?.users || []; |
no test coverage detected