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

Method parseGroupIdentifier

autorepeat/autorepeat.ts:457–577  ·  view source on GitHub ↗
(
    client: TelegramClient, 
    message: Api.Message,
    identifier?: string
  )

Source from the content-addressed store, hash-verified

455 ): Promise<{ success: boolean; chatId?: number; title?: string; error?: string }> {
456 try {
457 // 1. 如果有回复消息,尝试从转发信息中获取
458 if (message.replyTo) {
459 try {
460 const repliedMsg = await safeGetReplyMessage(message);
461 if (repliedMsg && repliedMsg.fwdFrom) {
462 const fwdChatId = repliedMsg.fwdFrom.fromId;
463 if (fwdChatId) {
464 const entity: any = await client.getEntity(fwdChatId);
465 if (entity.className === 'Chat' || (entity.className === 'Channel' && entity.megagroup)) {
466 const chatId = Number(utils.getPeerId(entity));
467 return {
468 success: true,
469 chatId: chatId,
470 title: entity.title || `群组 ${chatId}`
471 };
472 }
473 }
474 }
475 } catch (e) {
476 // 继续尝试其他方式
477 }
478 }
479
480 // 2. 如果没有提供标识符,检查是否在群组中
481 if (!identifier) {
482 if (message.isGroup || (message.isChannel && !message.isPrivate)) {
483 const chatId = Number(message.chatId);
484 try {
485 const entity: any = await client.getEntity(chatId);
486 return {
487 success: true,
488 chatId: chatId,
489 title: entity.title || `群组 ${chatId}`
490 };
491 } catch (e) {
492 return {
493 success: true,
494 chatId: chatId,
495 title: `群组 ${chatId}`
496 };
497 }
498 } else {
499 return {
500 success: false,
501 error: '❌ 请提供群组标识符或在群组中使用此命令\n支持格式:\n• 群组ID: <code>-1001234567890</code>\n• 公开群组: <code>@groupname</code>\n• Telegram链接: <code>https://t.me/groupname</code>\n• 转发消息: 回复来自目标群组的转发消息'
502 };
503 }
504 }
505
506 // 3. 尝试解析为群组ID(负数)
507 if (identifier.startsWith('-') && !identifier.startsWith('@')) {
508 const chatId = Number(identifier);
509 if (!isNaN(chatId)) {
510 try {
511 const entity: any = await client.getEntity(chatId);
512 return {
513 success: true,
514 chatId: chatId,

Callers 1

Calls 2

htmlEscapeFunction · 0.70

Tested by

no test coverage detected