Lawnmower/ci.py

47 lines
1.3 KiB
Python
Raw Normal View History

2022-04-23 16:18:35 +00:00
from configparser import RawConfigParser
2022-04-27 08:08:33 +00:00
from apscheduler.schedulers.asyncio import AsyncIOScheduler
2022-04-30 14:47:55 +00:00
from httpx import get
2022-04-27 08:08:33 +00:00
from os.path import exists
from os import mkdir, sep
2022-04-30 14:47:55 +00:00
import pyromod.listen
2022-04-23 16:18:35 +00:00
from pyrogram import Client
2022-04-27 08:08:33 +00:00
from sqlitedict import SqliteDict
2022-04-23 16:18:35 +00:00
2022-04-27 08:08:33 +00:00
if not exists("data"):
mkdir("data")
sqlite = SqliteDict(f"data{sep}sqlite.db", autocommit=True)
# 结构如下
# {
# "artifact_id": 0,
# }
2022-04-23 16:18:35 +00:00
config = RawConfigParser()
config.read("config.ini")
bot_token: str = ""
2022-04-27 08:08:33 +00:00
api_id: int = 0
api_hash: str = ""
2022-04-27 09:08:14 +00:00
ghp: str = ""
2022-04-27 08:08:33 +00:00
channel_id: int = 0
2022-04-27 09:08:14 +00:00
bot_token = config.get("basic", "bot_token", fallback=bot_token)
2022-04-27 08:08:33 +00:00
api_id = config.get("pyrogram", "api_id", fallback=api_id)
2022-04-27 09:08:14 +00:00
api_hash = config.get("pyrogram", "api_hash", fallback=api_hash)
2022-04-27 08:08:33 +00:00
channel_id = config.get("basic", "channel_id", fallback=channel_id)
2022-04-27 09:08:14 +00:00
ghp = config.get("basic", "ghp", fallback=ghp)
2022-04-23 16:18:35 +00:00
# 自定义类型
class Bot:
def __init__(self, data: dict):
self.uid = data["id"]
self.username = data["username"]
self.name = data["first_name"]
me = Bot(get(f"https://api.telegram.org/bot{bot_token}/getme").json()["result"])
# 初始化客户端
2022-04-27 08:08:33 +00:00
scheduler = AsyncIOScheduler()
if not scheduler.running:
scheduler.configure(timezone="Asia/ShangHai")
scheduler.start()
app = Client("bot", api_id=api_id, api_hash=api_hash, bot_token=bot_token, plugins=dict(root="plugins"))