mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-23 04:27:38 +08:00
🐛 修复注册失败的问题
This commit is contained in:
parent
b56ec5ce38
commit
37ed3b0824
@ -11,9 +11,9 @@ Copyright (C) 2020-2024 LiteyukiStudio. All Rights Reserved
|
|||||||
import json
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
import platform
|
import platform
|
||||||
|
from aiohttp import ClientSession
|
||||||
import requests
|
|
||||||
from git import Repo
|
from git import Repo
|
||||||
|
|
||||||
from liteyuki.plugin import PluginMetadata
|
from liteyuki.plugin import PluginMetadata
|
||||||
from liteyuki import get_bot, logger
|
from liteyuki import get_bot, logger
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ liteyuki = get_bot()
|
|||||||
commit_hash = Repo(".").head.commit.hexsha
|
commit_hash = Repo(".").head.commit.hexsha
|
||||||
|
|
||||||
|
|
||||||
def register_bot():
|
async def register_bot():
|
||||||
url = "https://api.liteyuki.icu/register"
|
url = "https://api.liteyuki.icu/register"
|
||||||
data = {
|
data = {
|
||||||
"name" : "LiteyukiBot",
|
"name" : "LiteyukiBot",
|
||||||
@ -37,16 +37,18 @@ def register_bot():
|
|||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
logger.info("Waiting for register to Liteyuki...")
|
logger.info("Waiting for register to Liteyuki...")
|
||||||
resp = requests.post(url, json=data, timeout=(10, 15))
|
async with ClientSession() as session:
|
||||||
if resp.status_code == 200:
|
async with session.post(url, json=data, timeout=15) as resp:
|
||||||
data = resp.json()
|
if resp.status == 200:
|
||||||
if liteyuki_id := data.get("liteyuki_id"):
|
data = await resp.json()
|
||||||
with open("data/liteyuki/liteyuki.json", "wb") as f:
|
if liteyuki_id := data.get("liteyuki_id"):
|
||||||
f.write(json.dumps(data).encode("utf-8"))
|
with open("data/liteyuki/liteyuki.json", "wb") as f:
|
||||||
logger.success(f"Register {liteyuki_id} to Liteyuki successfully")
|
f.write(json.dumps(data).encode("utf-8"))
|
||||||
else:
|
logger.success(f"Register {liteyuki_id} to Liteyuki successfully")
|
||||||
raise ValueError(f"Register to Liteyuki failed: {data}")
|
else:
|
||||||
|
raise ValueError(f"Register to Liteyuki failed: {data}")
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Register to Liteyuki failed: {resp.status}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Register to Liteyuki failed, but it's no matter: {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
|
@liteyuki.on_before_start
|
||||||
async def _():
|
async def _():
|
||||||
if not os.path.exists("data/liteyuki/liteyuki.json"):
|
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