MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / checkPermission

Method checkPermission

lu_bs/lu_bs.ts:180–213  ·  view source on GitHub ↗
(msg: Api.Message)

Source from the content-addressed store, hash-verified

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";

Callers 2

handleSubscribeMethod · 0.95
handleUnsubscribeMethod · 0.95

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected