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

Method findAndSendVideo

search/search.ts:422–582  ·  view source on GitHub ↗
(
    msg: Api.Message,
    query: string | null,
    useSpoiler: boolean,
    useRandom: boolean,
    type: "kkp" | "search"
  )

Source from the content-addressed store, hash-verified

420 }
421
422 private async findAndSendVideo(
423 msg: Api.Message,
424 query: string | null,
425 useSpoiler: boolean,
426 useRandom: boolean,
427 type: "kkp" | "search"
428 ) {
429 if (this.config.channelList.length === 0)
430 throw new Error(`请至少使用 \`${mainPrefix}so add\` 添加一个搜索频道。`);
431
432 const initialMessage = type === "kkp" ? "🎲 正在随机寻找视频..." : "🔍 正在搜索视频...";
433 await msg.edit({ text: initialMessage });
434
435 const searchOrder = [...new Set([this.config.defaultChannel, ...this.config.channelList.map((c) => c.handle)].filter(Boolean) as string[])];
436
437 let validVideos: Api.Message[] = [];
438 const processedGroupIds = new Set<string>();
439
440 for (const [index, channelHandle] of searchOrder.entries()) {
441 if (index > 0) {
442 await new Promise(resolve => setTimeout(resolve, 750));
443 }
444
445 const channelInfo = this.config.channelList.find((c) => c.handle === channelHandle);
446 if (!channelInfo) continue;
447
448 let videosInCurrentChannel: Api.Message[] = [];
449
450 try {
451 await msg.edit({ text: `- 正在搜索... (源: ${index + 1}/${searchOrder.length})` });
452 const entity = await this.client.getEntity(channelInfo.handle);
453
454 if (type === "search" && query) {
455 if (channelInfo.linkedGroup) {
456 const linkedVideos = await this.searchInChannelWithLinkedGroup(channelInfo, query);
457 if (linkedVideos.length > 0) videosInCurrentChannel.push(...linkedVideos);
458 }
459
460 const allQueryMessages = await safeGetMessages(this.client, entity, { limit: 200, search: query });
461
462 for (const foundMsg of allQueryMessages) {
463 if (this.isMessageMatching(foundMsg, query)) {
464 if (foundMsg.groupedId) {
465 const groupIdStr = foundMsg.groupedId.toString();
466 if (processedGroupIds.has(groupIdStr)) continue;
467
468 const surroundingMessages = await safeGetMessages(this.client, entity, {
469 limit: 20,
470 offsetId: foundMsg.id + 10,
471 });
472
473 const groupedId = foundMsg.groupedId;
474 if (!groupedId) continue;
475 const albumMessages = surroundingMessages.filter((m: Api.Message) => m.groupedId?.equals(groupedId));
476 const videosInAlbum = albumMessages.filter((m: Api.Message) => m.video && !this.isAdContent(m));
477
478 if (videosInAlbum.length > 0) {
479 videosInCurrentChannel.push(...videosInAlbum);

Callers 2

handleKkpMethod · 0.95
handleSearchMethod · 0.95

Calls 12

isMessageMatchingMethod · 0.95
isAdContentMethod · 0.95
saveConfigMethod · 0.95
selectRandomVideoMethod · 0.95
normalizeSearchTermMethod · 0.95
sendVideoMethod · 0.95
errorMethod · 0.80
warnMethod · 0.80
editMethod · 0.45
addMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected