Enka_Genshin_bot/ci.py
2022-06-04 12:32:48 +08:00

43 lines
1.3 KiB
Python

from configparser import RawConfigParser
from os import mkdir, sep
from os.path import exists
import pyromod.listen
from pyrogram import Client
from httpx import AsyncClient, get
from sqlitedict import SqliteDict
try:
import uvloop
uvloop.install()
except ImportError:
pass
# init folders
if not exists("data"):
mkdir("data")
sqlite = SqliteDict(f"data{sep}data.sqlite", autocommit=True)
# 读取配置文件
config = RawConfigParser()
config.read("config.ini")
bot_token: str = ""
api_id: int = 0
api_hash: str = ""
channel_id: int = 0
admin_id: int = 0
bot_token = config.get("basic", "bot_token", fallback=bot_token)
channel_id = config.get("basic", "channel_id", fallback=channel_id)
admin_id = config.get("basic", "admin_id", fallback=admin_id)
api_id = config.get("pyrogram", "api_id", fallback=api_id)
api_hash = config.get("pyrogram", "api_hash", fallback=api_hash)
guess_time = 30 # 猜语音游戏持续时间
""" 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"
}
client = AsyncClient(timeout=10.0, headers=headers)
me = get(f"https://api.telegram.org/bot{bot_token}/getme").json()
# 初始化客户端
app = Client("bot", bot_token=bot_token, api_id=api_id, api_hash=api_hash, plugins={"root": "plugins"})