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

Method handleRestorePin

restore_pin/restore_pin.ts:166–240  ·  view source on GitHub ↗

* 主命令处理器

(msg: Api.Message)

Source from the content-addressed store, hash-verified

164 if (!client) {
165 await msg.edit({ text: "❌ 客户端未初始化", parseMode: "html" });
166 return;
167 }
168
169 try {
170 // 检查是否为群组
171 const chat = await msg.getChat();
172 if (!(chat instanceof Api.Chat || chat instanceof Api.Channel)) {
173 await msg.edit({ text: "❌ 此命令仅在群组或频道中可用", parseMode: "html" });
174 return;
175 }
176
177 // 检查管理员权限
178 const sender = await msg.getSender();
179 if (!sender) {
180 await msg.edit({ text: "❌ 无法获取发送者信息", parseMode: "html" });
181 return;
182 }
183
184 const participant = await client.invoke(
185 new Api.channels.GetParticipant({
186 channel: chat.id,
187 participant: sender as unknown as Api.InputUser
188 })
189 );
190
191 const isAdmin = participant.participant instanceof Api.ChannelParticipantAdmin ||
192 participant.participant instanceof Api.ChannelParticipantCreator;
193
194 if (!isAdmin) {
195 await msg.edit({ text: "❌ 需要管理员权限才能使用此命令", parseMode: "html" });
196 return;
197 }
198
199 await msg.edit({ text: "📋 正在获取管理员日志...", parseMode: "html" });
200
201 // 获取管理员日志
202 const adminLog = await this.getAdminLog(chat.id);
203
204 // 提取取消置顶的消息ID
205 const messageIds = this.getUnpinMessages(adminLog);
206
207 if (messageIds.length === 0) {
208 await msg.edit({ text: "✅ 未找到可恢复的置顶消息", parseMode: "html" });
209 return;
210 }
211
212 await msg.edit({
213 text: `🔍 找到 ${messageIds.length} 条可恢复的置顶消息,开始自动恢复...`,
214 parseMode: "html"
215 });
216
217 // 直接恢复所有置顶消息
218 await this.restorePins(msg, chat.id, messageIds);
219
220 } catch (error: any) {
221 console.error(`[restore_pin] 错误:`, error);
222
223 let errorMessage = "❌ 操作失败";

Callers

nothing calls this directly

Calls 6

getAdminLogMethod · 0.95
getUnpinMessagesMethod · 0.95
restorePinsMethod · 0.95
errorMethod · 0.80
htmlEscapeFunction · 0.70
editMethod · 0.45

Tested by

no test coverage detected