| 88 | (msg: Api.Message, trigger?: Api.Message) => Promise<void> |
| 89 | > = { |
| 90 | manage_admin: async (msg: Api.Message, trigger?: Api.Message) => { |
| 91 | const parts = msg.message.trim().split(/\s+/); |
| 92 | const sub = (parts[1] || "").toLowerCase(); |
| 93 | |
| 94 | const isInGroup = (msg as any).isGroup || (msg as any).isChannel; |
| 95 | if (!isInGroup) { |
| 96 | await msg.edit({ |
| 97 | text: `请在群组/频道对话中使用 <code>${commandName}</code> 命令`, |
| 98 | parseMode: "html", |
| 99 | }); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | const channel = await msg.getInputChat(); |
| 104 | const chatEntity = await msg.getChat(); |
| 105 | if (!channel || !chatEntity) { |
| 106 | await msg.edit({ text: "无法获取当前对话实体" }); |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | async function resolveUserFromReplyOrArg(arg?: string) { |
| 111 | const client = await getGlobalClient(); |
| 112 | if (msg.isReply) { |
| 113 | const r = await safeGetReplyMessage(msg); |
| 114 | if (!r) return { id: undefined as any, entity: undefined as any }; |
| 115 | // Prefer real sender entity and ensure it's a user |
| 116 | let sender: any; |
| 117 | try { |
| 118 | sender = await (r as any).getSender?.(); |
| 119 | } catch {} |
| 120 | if (!(sender instanceof Api.User)) { |
| 121 | // Fallback to fromId user only |
| 122 | const fromId: any = r.fromId as any; |
| 123 | const uid = Number(fromId?.userId); |
| 124 | if (uid && client) { |
| 125 | try { |
| 126 | const input = await client.getInputEntity(uid); |
| 127 | const full = await client.getEntity(input); |
| 128 | if (full instanceof Api.User) { |
| 129 | return { id: Number(full.id), entity: input }; |
| 130 | } |
| 131 | } catch {} |
| 132 | } |
| 133 | return { id: undefined as any, entity: undefined as any }; |
| 134 | } |
| 135 | const input = await client?.getInputEntity(sender.id); |
| 136 | return { id: Number(sender.id), entity: input }; |
| 137 | } else if (arg) { |
| 138 | try { |
| 139 | const full = await client?.getEntity(arg as any); |
| 140 | if (!(full instanceof Api.User)) { |
| 141 | return { id: undefined as any, entity: undefined as any }; |
| 142 | } |
| 143 | const input = await client?.getInputEntity(full.id); |
| 144 | return { id: Number(full.id), entity: input }; |
| 145 | } catch (e) { |
| 146 | // Fallback: if arg is numeric and current chat is channel, scan participants to resolve access hash |
| 147 | const numericId = Number(arg); |
nothing calls this directly
no test coverage detected