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

Function forwardToTarget

bs/bs.ts:443–531  ·  view source on GitHub ↗
(options: {
  client: any;
  fromPeer: any;
  target: TargetRecord;
  messageIds: number[];
})

Source from the content-addressed store, hash-verified

441}
442
443async function forwardToTarget(options: {
444 client: any;
445 fromPeer: any;
446 target: TargetRecord;
447 messageIds: number[];
448}) {
449 const { client, fromPeer, target, messageIds } = options;
450 const lookup = getTargetLookup(target);
451 let entity: any;
452 try {
453 entity = await client.getEntity(lookup as any);
454 } catch (error) {
455 console.warn(`[bs] 获取对话 ${target.target} 失败`, error);
456 return { success: false, error: getRpcErrorMessage(error) };
457 }
458
459 if (!entity) return { success: false, error: "未找到目标" };
460
461 let updated = false;
462 const resolvedId = toStrInt(entity.id);
463 if (resolvedId && target.chatId !== resolvedId) {
464 target.chatId = resolvedId;
465 updated = true;
466 }
467
468 if (
469 !target.display ||
470 target.display === `<code>${escapeHtml(target.target)}</code>`
471 ) {
472 const info = await formatEntity(entity).catch(() => null);
473 if (info?.display) {
474 target.display = info.display;
475 updated = true;
476 }
477 }
478
479 let retryFlood = false;
480 const toPeer = await client.getInputEntity(entity);
481
482 while (true) {
483 try {
484 const result = await client.invoke(
485 new Api.messages.ForwardMessages({
486 fromPeer,
487 id: messageIds,
488 toPeer,
489 ...(target.topicId
490 ? { topMsgId: toInt(target.topicId) ?? undefined }
491 : {}),
492 })
493 );
494 return {
495 success: true,
496 entity,
497 forwarded: extractForwardedMessages(result),
498 updated,
499 };
500 } catch (error) {

Callers 1

BsPluginClass · 0.85

Calls 10

getTargetLookupFunction · 0.85
getRpcErrorMessageFunction · 0.85
extractForwardedMessagesFunction · 0.85
isPermissionErrorFunction · 0.85
warnMethod · 0.80
toStrIntFunction · 0.70
escapeHtmlFunction · 0.70
formatEntityFunction · 0.70
toIntFunction · 0.70
sleepFunction · 0.50

Tested by

no test coverage detected