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

Function checkAdminPermissions

clean_member/clean_member.ts:170–206  ·  view source on GitHub ↗
(msg: Api.Message)

Source from the content-addressed store, hash-verified

168 if (!msg.peerId || !msg.client) return false;
169 const me = await msg.client.getMe();
170 try {
171 const result = await msg.client.invoke(new Api.channels.GetParticipant({
172 channel: msg.peerId,
173 participant: me.id
174 }));
175 if (result.participant instanceof Api.ChannelParticipantAdmin ||
176 result.participant instanceof Api.ChannelParticipantCreator) {
177 return true;
178 }
179 } catch (participantError) {
180 console.log('GetParticipant failed, trying alternative method:', participantError);
181 }
182 try {
183 const result = await msg.client.invoke(new Api.channels.GetParticipants({
184 channel: msg.peerId,
185 filter: new Api.ChannelParticipantsAdmins(),
186 offset: 0,
187 limit: 100,
188 hash: 0 as any
189 }));
190 if ('users' in result) {
191 const admins = result.users as Api.User[];
192 return admins.some(admin => Number(admin.id) === Number(me.id));
193 }
194 } catch (adminListError) {
195 console.log('GetParticipants admin list failed:', adminListError);
196 }
197 return false;
198 } catch (error) {
199 console.error('Permission check failed:', error);
200 return false;
201 }
202}
203
204async function resolveParticipantEntity(client: TelegramClient, user: Api.User | number): Promise<any> {
205 // 已注销账号只能用完整 User 上的 accessHash;裸 id 会 getInputEntity 失败
206 if (typeof user === "number") {
207 return await client.getInputEntity(user);
208 }
209 try {

Callers 1

clean_memberFunction · 0.85

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected