misskey2telegram/modules/timeline.py

44 lines
1.3 KiB
Python
Raw Permalink Normal View History

2023-07-05 12:10:41 +00:00
import contextlib
from datetime import datetime, timedelta
2023-07-05 12:10:41 +00:00
2024-09-30 13:34:58 +00:00
from typing import TYPE_CHECKING
2024-09-30 13:59:28 +00:00
from pyrogram import Client, filters
2024-09-30 13:34:58 +00:00
from defs.announcement import UnreadAnnouncement
2022-12-22 14:18:43 +00:00
from init import bot
2023-07-05 12:10:41 +00:00
from misskey_init import init_misskey_bot, misskey_bot_map
from models.services.scheduler import scheduler
2022-12-24 13:19:24 +00:00
2024-09-30 13:34:58 +00:00
if TYPE_CHECKING:
from mipac import MeDetailed
from misskey_init import MisskeyBot
2023-01-27 12:36:41 +00:00
bot.loop.create_task(init_misskey_bot())
2023-07-05 12:10:41 +00:00
2024-09-30 13:34:58 +00:00
async def get_unread_announcements(me: "MeDetailed", m_bot: "MisskeyBot"):
if not me:
return
un = [UnreadAnnouncement(an, m_bot) for an in me.unread_announcements]
for an in un:
try:
await an.send_notice()
finally:
await an.mark_as_read()
@scheduler.scheduled_job("cron", minute="*/30", id="daily_status")
@scheduler.scheduled_job("date", run_date=datetime.now() + timedelta(minutes=1), id="daily_status_start")
2023-07-05 12:10:41 +00:00
async def daily_status():
for m_bot in misskey_bot_map.values():
with contextlib.suppress(Exception):
2024-09-30 13:34:58 +00:00
me = await m_bot.core.api.get_me()
2024-09-30 13:59:28 +00:00
me._MeDetailedOnly__client = me._client
2024-09-30 13:34:58 +00:00
await get_unread_announcements(me, m_bot)
2024-09-30 13:59:28 +00:00
@Client.on_message(filters.incoming & filters.private & filters.command(["daily_status"]))
async def daily_status_command(_: Client, __):
await daily_status()