main
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3from loguru import logger
4from pyrogram.client import Client
5from pyrogram.types import Message
6
7from asr.voice_recognition import voice_to_text
8from config import cache
9from custom.config import ACCOUNT_NAME, CHANNEL_CYF_BAK, GROUP_67373, USER_CYF
10from messages.parser import parse_msg
11from utils import to_int
12
13
14async def message_backup(client: Client, message: Message):
15 async def copy_msg(target_cid: int | str):
16 info = parse_msg(message, silent=True)
17 if info["mtype"] == "voice":
18 await voice_to_text(client, message, target_chat=to_int(target_cid), reply_msg_id=-1, asr_need_prefix=False)
19 elif message.media_group_id:
20 if not cache.get(f"{message.media_group_id}"):
21 cache.set(f"{message.media_group_id}", "1", ttl=120)
22 caption = f"{info['text']}\n{info['message_url']}".strip()
23 await client.copy_media_group(chat_id=to_int(target_cid), from_chat_id=message.chat.id, message_id=message.id, captions=caption)
24 elif message.media:
25 caption = f"{info['text']}\n{info['message_url']}".strip()
26 await client.copy_message(chat_id=to_int(target_cid), from_chat_id=message.chat.id, message_id=message.id, caption=caption)
27 elif info["entity_urls"]:
28 text = f"{info['text']}\n{info['message_url']}".strip()
29 await client.send_message(chat_id=to_int(target_cid), text=text)
30 else:
31 text = f"[{info['text']}]({info['message_url']})".strip()
32 await client.send_message(chat_id=to_int(target_cid), text=text)
33
34 if message.chat.id == GROUP_67373 and message.from_user.id == USER_CYF and ACCOUNT_NAME == "xiaohao":
35 info = parse_msg(message, silent=True)
36 logger.success(info["summary"])
37 await copy_msg(CHANNEL_CYF_BAK)
38
39 # 风哥
40 if message.chat.id == 2049194302 and message.from_user.id == 2049194302:
41 info = parse_msg(message, silent=True)
42 logger.success(info["summary"])
43 await copy_msg(-1002465020912) # 开发专用频道