(msg: Api.Message)
| 178 | const client = await getGlobalClient(); |
| 179 | if (!client) return false; |
| 180 | |
| 181 | const chat = await msg.getChat(); |
| 182 | const sender = await msg.getSender(); |
| 183 | |
| 184 | // 检查chat和sender是否存在 |
| 185 | if (!chat || !sender) return false; |
| 186 | |
| 187 | // 私聊总是允许 |
| 188 | if (chat.className === "User") { |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | // 群组/频道需要检查管理员权限 |
| 193 | if (chat.className === "Channel" || chat.className === "Chat") { |
| 194 | const result = await client.invoke(new Api.channels.GetParticipant({ channel: chat as any, participant: sender as any })) as any; |
| 195 | const participant = result?.participant; |
| 196 | return !!participant && ( |
| 197 | participant instanceof Api.ChannelParticipantAdmin || |
| 198 | participant instanceof Api.ChannelParticipantCreator || |
| 199 | participant instanceof Api.ChatParticipantAdmin || |
| 200 | participant instanceof Api.ChatParticipantCreator |
| 201 | ); |
| 202 | } |
| 203 | |
| 204 | return false; |
| 205 | } catch (error) { |
| 206 | console.error(`[${this.PLUGIN_NAME}] 权限检查失败:`, error); |
| 207 | return false; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | cmdHandlers = { |
| 212 | lu_bs: async (msg: Api.Message) => { |
| 213 | if (!this.db) await this.initDB(); |
| 214 | |
| 215 | const parts = msg.text?.trim().split(/\s+/) || []; |
| 216 | const subCommand = parts[1]?.toLowerCase() || "help"; |
no test coverage detected