misskey2telegram/init.py

49 lines
1.5 KiB
Python
Raw Normal View History

2023-01-17 03:26:10 +00:00
from logging import getLogger, INFO, ERROR, StreamHandler, basicConfig
2022-12-22 14:18:43 +00:00
import httpx
import pyrogram
2023-01-17 03:26:10 +00:00
from fix_topic import fix_topic
from glover import api_id, api_hash, ipv6, timeline_topic_id, notice_topic_id
2022-12-22 14:18:43 +00:00
from scheduler import scheduler
# Enable logging
logs = getLogger("misskey2telegram")
logging_handler = StreamHandler()
root_logger = getLogger("pyrogram")
root_logger.setLevel(ERROR)
root_logger.addHandler(logging_handler)
basicConfig(level=INFO)
logs.setLevel(INFO)
if not scheduler.running:
scheduler.start()
# Init client
bot = pyrogram.Client("bot", api_id=api_id, api_hash=api_hash, ipv6=ipv6, plugins=dict(root="modules"))
2023-01-17 03:26:10 +00:00
# fix topic group
setattr(pyrogram.types.Message, "old_parse", getattr(pyrogram.types.Message, "_parse"))
setattr(pyrogram.types.Message, "_parse", fix_topic)
def private_filter(topic_id: int = 0):
if not topic_id:
return pyrogram.filters.private
async def func(_, __, m: pyrogram.types.Message):
if m.chat.type == pyrogram.enums.ChatType.PRIVATE:
return True
elif m.reply_to_top_message_id == topic_id:
return True
else:
return False
return pyrogram.filters.create(func)
timeline_filter = private_filter(timeline_topic_id)
notice_filter = private_filter(notice_topic_id)
2022-12-22 14:18:43 +00:00
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.72 Safari/537.36"
}
request = httpx.AsyncClient(timeout=60.0, headers=headers)