Lsposed_Modules_Updates_Tra.../ci.py

59 lines
1.8 KiB
Python
Raw Normal View History

2022-03-20 05:02:17 +00:00
import json
2022-03-19 17:44:35 +00:00
from configparser import RawConfigParser
from os import sep, mkdir
from os.path import exists
from pyrogram import Client
from apscheduler.schedulers.asyncio import AsyncIOScheduler
2022-08-15 02:50:53 +00:00
from httpx import get
2022-03-19 17:44:35 +00:00
from sqlitedict import SqliteDict
if not exists("data"):
mkdir("data")
2022-03-20 05:02:17 +00:00
sqlite = SqliteDict(f"data{sep}data.sqlite", encode=json.dumps, decode=json.loads, autocommit=True)
2022-03-19 17:44:35 +00:00
# data.sqlite 结构如下:
# {
# "module 名称": {
2022-03-20 05:02:17 +00:00
# "msg_link": str,
# "subscribes": List[订阅id: int],
2022-03-19 17:44:35 +00:00
# },
2022-03-20 05:02:17 +00:00
# "update_time": str,
2022-03-19 17:44:35 +00:00
# }
# 读取配置文件
config = RawConfigParser()
config.read("config.ini")
bot_token: str = ""
admin_id: int = 0
channel_id: int = 0
2022-08-15 03:08:16 +00:00
max_update_file: int = 10
2022-08-08 06:43:26 +00:00
api_id: int = 0
api_hash: str = ""
api_id = config.getint("pyrogram", "api_id", fallback=api_id)
api_hash = config.get("pyrogram", "api_hash", fallback=api_hash)
2022-03-19 17:44:35 +00:00
bot_token = config.get("basic", "bot_token", fallback=bot_token)
admin_id = config.getint("basic", "admin", fallback=admin_id)
channel_id = config.getint("basic", "channel_id", fallback=channel_id)
2022-08-15 03:08:16 +00:00
max_update_file = config.getint("basic", "max_update_file", fallback=max_update_file)
2022-03-19 17:44:35 +00:00
""" Init httpx client """
# 使用自定义 UA
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
}
# 自定义类型
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()
2022-08-08 06:43:26 +00:00
app = Client("bot", api_id=api_id, api_hash=api_hash, bot_token=bot_token, plugins=dict(root="plugins"))