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

Method handleAdd

search/search.ts:229–266  ·  view source on GitHub ↗
(msg: Api.Message, args: string)

Source from the content-addressed store, hash-verified

227 }
228
229 private async handleAdd(msg: Api.Message, args: string) {
230 if (!args) throw new Error("请提供频道链接或 @username,使用 \\ 分隔。");
231 const channels = args.split("\\");
232 let addedCount = 0;
233
234 for (const channelHandle of channels) {
235 try {
236 const normalizedHandle = channelHandle.trim();
237 const entity = await this.client.getEntity(normalizedHandle);
238
239 if (!(entity instanceof Api.Channel) && !(entity instanceof Api.Chat)) {
240 await msg.edit({ text: `错误:${normalizedHandle} 不是公开频道、群组或讨论组。` });
241 continue;
242 }
243 if (this.config.channelList.some((c) => c.handle === normalizedHandle)) {
244 await msg.edit({ text: `目标 "${entity.title}" 已存在。` });
245 continue;
246 }
247
248 let linkedGroup: string | undefined;
249 if (entity instanceof Api.Channel && !entity.megagroup && entity.broadcast) {
250 linkedGroup = await this.discoverLinkedGroup(entity);
251 }
252
253 this.config.channelList.push({
254 title: entity.title,
255 handle: normalizedHandle,
256 linkedGroup: linkedGroup,
257 });
258 if (!this.config.defaultChannel) this.config.defaultChannel = normalizedHandle;
259 addedCount++;
260 } catch (error: any) {
261 await msg.edit({ text: `添加频道 ${channelHandle.trim()} 时出错:${error.message}` });
262 }
263 }
264 await this.saveConfig();
265 await msg.edit({ text: `✅ 成功添加 ${addedCount} 个频道。` });
266 }
267
268 private async handleDelete(msg: Api.Message, args: string) {
269 if (!args) throw new Error(`用法: ${mainPrefix}so del <频道链接|序号> [...] 或 ${mainPrefix}so del all。`);

Callers 2

handleMethod · 0.95
handleImportMethod · 0.95

Calls 3

discoverLinkedGroupMethod · 0.95
saveConfigMethod · 0.95
editMethod · 0.45

Tested by

no test coverage detected