mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-22 22:37:37 +08:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
d2b693b1e0
@ -11,9 +11,9 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
||||
import json
|
||||
import os.path
|
||||
import platform
|
||||
|
||||
import requests
|
||||
from aiohttp import ClientSession
|
||||
from git import Repo
|
||||
|
||||
from liteyuki.plugin import PluginMetadata
|
||||
from liteyuki import get_bot, logger
|
||||
|
||||
@ -25,7 +25,7 @@ liteyuki = get_bot()
|
||||
commit_hash = Repo(".").head.commit.hexsha
|
||||
|
||||
|
||||
def register_bot():
|
||||
async def register_bot():
|
||||
url = "https://api.liteyuki.icu/register"
|
||||
data = {
|
||||
"name" : "LiteyukiBot",
|
||||
@ -37,16 +37,18 @@ def register_bot():
|
||||
}
|
||||
try:
|
||||
logger.info("Waiting for register to Liteyuki...")
|
||||
resp = requests.post(url, json=data, timeout=(10, 15))
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
if liteyuki_id := data.get("liteyuki_id"):
|
||||
with open("data/liteyuki/liteyuki.json", "wb") as f:
|
||||
f.write(json.dumps(data).encode("utf-8"))
|
||||
logger.success(f"Register {liteyuki_id} to Liteyuki successfully")
|
||||
else:
|
||||
raise ValueError(f"Register to Liteyuki failed: {data}")
|
||||
|
||||
async with ClientSession() as session:
|
||||
async with session.post(url, json=data, timeout=15) as resp:
|
||||
if resp.status == 200:
|
||||
data = await resp.json()
|
||||
if liteyuki_id := data.get("liteyuki_id"):
|
||||
with open("data/liteyuki/liteyuki.json", "wb") as f:
|
||||
f.write(json.dumps(data).encode("utf-8"))
|
||||
logger.success(f"Register {liteyuki_id} to Liteyuki successfully")
|
||||
else:
|
||||
raise ValueError(f"Register to Liteyuki failed: {data}")
|
||||
else:
|
||||
raise ValueError(f"Register to Liteyuki failed: {resp.status}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Register to Liteyuki failed, but it's no matter: {e}")
|
||||
|
||||
@ -54,4 +56,6 @@ def register_bot():
|
||||
@liteyuki.on_before_start
|
||||
async def _():
|
||||
if not os.path.exists("data/liteyuki/liteyuki.json"):
|
||||
register_bot()
|
||||
if not os.path.exists("data/liteyuki"):
|
||||
os.makedirs("data/liteyuki")
|
||||
await register_bot()
|
||||
|
Loading…
Reference in New Issue
Block a user