Lawnmower/plugins/update.py
2022-04-27 17:08:14 +08:00

32 lines
1009 B
Python

from os import sep
from pyrogram import Client, filters
from pyrogram.types import Message
from ci import app, channel_id, sqlite, scheduler
from defs.ci import get_artifact
@scheduler.scheduled_job("cron", minute="*/30", id="0")
async def run_every_30_minute():
old_artifact_id = sqlite.get("artifact_id", 0)
new_artifact = await get_artifact()
if old_artifact_id == new_artifact.id:
return
if not channel_id:
return
sqlite["artifact_id"] = new_artifact.id
try:
await new_artifact.download()
except FileNotFoundError:
return
await app.send_document(channel_id, f"data{sep}Grasscutter.zip",
caption=new_artifact.hash,
force_document=True)
@Client.on_message(filters.incoming & filters.private &
filters.command(["force_update", ]))
async def force_update(_: Client, message: Message):
await run_every_30_minute()
await message.reply("Updated!", quote=True)