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

Method handleQuote

quote/quote.ts:1329–1410  ·  view source on GitHub ↗
(msg: Api.Message, command: "q" | "quote")

Source from the content-addressed store, hash-verified

1327 return undefined;
1328 }
1329}
1330
1331async function toQuoteMessage(msg: Api.Message, args: QuoteArgs): Promise<any> {
1332 const entity = await senderEntity(msg);
1333 const fwd = await forwardedSource(msg);
1334 const effectiveEntity = fwd?.entity ?? entity;
1335 const effectiveName = fwd?.name || displayName(effectiveEntity);
1336 const avatarClient = (msg as any).client ?? await getGlobalClient().catch(() => undefined);
1337 const [avatarBuffer, media, replyMessage] = await Promise.all([
1338 fwd && !fwd.anonymous && fwd.entity
1339 ? downloadEntityAvatar(avatarClient, fwd.entity)
1340 : downloadSenderAvatar(msg, entity),
1341 prepareQuoteMedia(msg, args),
1342 replyPreview(msg, args.reply, args),
1343 Promise.resolve(undefined),
1344 ]);
1345 const emojiId = emojiStatusIdFromEntity(effectiveEntity);
1346 let emojiBuffer: Buffer | undefined;
1347 if (emojiId) {
1348 emojiBuffer = customEmojiCache.get(emojiId);
1349 console.warn("quote sender emoji status", emojiId, emojiBuffer ? emojiBuffer.length : 0);
1350 }
1351 const user: QuoteUser = {
1352 id: fwd?.peer ? peerIdNumber(fwd.peer) : senderIdNumber(msg),
1353 name: args.hidden ? false : effectiveName,
1354 first_name: args.hidden ? false : effectiveName,
1355 photo: {},
1356 emoji_status: args.hidden || fwd?.anonymous ? undefined : emojiStatusPayload(effectiveEntity, emojiBuffer),
1357 };
1358 return {
1359 chatId: fwd?.peer ? peerIdNumber(fwd.peer) : senderIdNumber(msg),
1360 message_id: (msg as any).id,
1361 from: user,
1362 name: user.name,
1363 avatar: !args.hidden && !!avatarBuffer,
1364 avatarBuffer: args.hidden ? undefined : avatarBuffer,
1365 avatarScale: args.scale,
1366 text: messageText(msg),
1367 entities: convertEntities(msg),
1368 caption: messageText(msg),
1369 caption_entities: convertEntities(msg),
1370 replyMessage,
1371 forward: fwd ? { label: fwd.name || "Forwarded message" } : undefined,
1372 mediaBuffer: media.mediaBuffer,
1373 mediaCanvas: media.mediaCanvas,
1374 mediaType: media.mediaType,
1375 mediaMaxSize: media.mediaMaxSize,
1376 mediaCrop: media.mediaCrop,
1377 emoji_status: args.hidden || fwd?.anonymous ? undefined : emojiStatusPayload(effectiveEntity, emojiBuffer),
1378 date: messageDate(msg),
1379 via_bot: (msg as any).viaBotId ?? (msg as any).via_bot_id,
1380 senderTag: fwd ? undefined : await senderRankInChat(msg, entity),
1381 };
1382}
1383
1384async function collectMessages(msg: Api.Message, args: QuoteArgs): Promise<Api.Message[]> {
1385 const reply = await withTimeout(safeGetReplyMessage(msg), QUOTE_RPC_TIMEOUT_MS, "collectMessages.getReply").catch(() => undefined);
1386 const count = args.count || 1;

Callers 1

QuotePluginClass · 0.95

Calls 15

getCommandArgsTextFunction · 0.85
parseArgsFunction · 0.85
editProgressFunction · 0.85
quoteResourcesReadyFunction · 0.85
withTimeoutFunction · 0.85
quoteTimingFunction · 0.85
runWithConcurrencyFunction · 0.85
toQuoteMessageFunction · 0.85
getQuoteGenFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected