Lawnmower/plugins/update.py

32 lines
1009 B
Python
Raw Normal View History

2022-04-27 09:08:14 +00:00
from os import sep
2022-04-27 08:08:33 +00:00
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
2022-04-27 09:08:14 +00:00
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",
2022-04-27 08:08:33 +00:00
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)