from configparser import RawConfigParser from apscheduler.schedulers.asyncio import AsyncIOScheduler from httpx import get from os.path import exists from os import mkdir, sep import pyromod.listen from pyrogram import Client from sqlitedict import SqliteDict if not exists("data"): mkdir("data") sqlite = SqliteDict(f"data{sep}sqlite.db", autocommit=True) # 结构如下 # { # "artifact_id": 0, # } config = RawConfigParser() config.read("config.ini") bot_token: str = "" api_id: int = 0 api_hash: str = "" ghp: str = "" channel_id: int = 0 bot_token = config.get("basic", "bot_token", fallback=bot_token) api_id = config.get("pyrogram", "api_id", fallback=api_id) api_hash = config.get("pyrogram", "api_hash", fallback=api_hash) channel_id = config.get("basic", "channel_id", fallback=channel_id) ghp = config.get("basic", "ghp", fallback=ghp) # 自定义类型 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"]) # 初始化客户端 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"))