mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 11:29:39 +08:00
feat: 改为同步
This commit is contained in:
6
main.py
6
main.py
@@ -422,7 +422,7 @@ def stop():
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
def main():
|
||||||
global use_override
|
global use_override
|
||||||
# 检查是否携带了 --override 或 -r 参数
|
# 检查是否携带了 --override 或 -r 参数
|
||||||
if '--override' in sys.argv or '-r' in sys.argv:
|
if '--override' in sys.argv or '-r' in sys.argv:
|
||||||
@@ -450,7 +450,7 @@ async def main():
|
|||||||
elif len(sys.argv) > 1 and sys.argv[1] == 'update':
|
elif len(sys.argv) > 1 and sys.argv[1] == 'update':
|
||||||
print("正在进行程序更新...")
|
print("正在进行程序更新...")
|
||||||
import pkg.utils.updater as updater
|
import pkg.utils.updater as updater
|
||||||
await updater.update_all(cli=True)
|
updater.update_all(cli=True)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# 关闭urllib的http警告
|
# 关闭urllib的http警告
|
||||||
@@ -486,5 +486,5 @@ async def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
asyncio.run(main())
|
main()
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import threading
|
import threading
|
||||||
import asyncio
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from .. import aamgr
|
from .. import aamgr
|
||||||
@@ -21,9 +20,9 @@ class UpdateCommand(aamgr.AbstractCommandNode):
|
|||||||
import pkg.utils.reloader
|
import pkg.utils.reloader
|
||||||
import pkg.utils.context
|
import pkg.utils.context
|
||||||
|
|
||||||
async def update_task():
|
def update_task():
|
||||||
try:
|
try:
|
||||||
if await pkg.utils.updater.update_all():
|
if pkg.utils.updater.update_all():
|
||||||
pkg.utils.context.get_qqbot_manager().notify_admin("更新完成, 请手动重启程序。")
|
pkg.utils.context.get_qqbot_manager().notify_admin("更新完成, 请手动重启程序。")
|
||||||
else:
|
else:
|
||||||
pkg.utils.context.get_qqbot_manager().notify_admin("无新版本")
|
pkg.utils.context.get_qqbot_manager().notify_admin("无新版本")
|
||||||
@@ -32,10 +31,7 @@ class UpdateCommand(aamgr.AbstractCommandNode):
|
|||||||
pkg.utils.context.get_qqbot_manager().notify_admin("更新失败:{}".format(e0))
|
pkg.utils.context.get_qqbot_manager().notify_admin("更新失败:{}".format(e0))
|
||||||
return
|
return
|
||||||
|
|
||||||
def wrapper():
|
threading.Thread(target=update_task, daemon=True).start()
|
||||||
asyncio.run(update_task())
|
|
||||||
|
|
||||||
threading.Thread(target=wrapper).start()
|
|
||||||
|
|
||||||
reply = ["[bot]正在更新,请耐心等待,请勿重复发起更新..."]
|
reply = ["[bot]正在更新,请耐心等待,请勿重复发起更新..."]
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import abc
|
|||||||
import uuid
|
import uuid
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import aiohttp
|
import requests
|
||||||
|
|
||||||
|
|
||||||
class APIGroup(metaclass=abc.ABCMeta):
|
class APIGroup(metaclass=abc.ABCMeta):
|
||||||
@@ -28,16 +28,15 @@ class APIGroup(metaclass=abc.ABCMeta):
|
|||||||
url = self.prefix + path
|
url = self.prefix + path
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
headers['Content-Type'] = 'application/json'
|
headers['Content-Type'] = 'application/json'
|
||||||
async with aiohttp.ClientSession() as session:
|
|
||||||
async with session.request(
|
return requests.request(
|
||||||
method,
|
method,
|
||||||
url,
|
url,
|
||||||
data=data,
|
data=data,
|
||||||
params=params,
|
params=params,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
**kwargs
|
**kwargs
|
||||||
) as resp:
|
)
|
||||||
return await resp.json()
|
|
||||||
|
|
||||||
def gen_rid(
|
def gen_rid(
|
||||||
self
|
self
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class V2MainDataAPI(apigroup.APIGroup):
|
|||||||
def __init__(self, prefix: str):
|
def __init__(self, prefix: str):
|
||||||
super().__init__(prefix+"/main")
|
super().__init__(prefix+"/main")
|
||||||
|
|
||||||
async def post_update_record(
|
def post_update_record(
|
||||||
self,
|
self,
|
||||||
spent_seconds: int,
|
spent_seconds: int,
|
||||||
infer_reason: str,
|
infer_reason: str,
|
||||||
@@ -17,7 +17,7 @@ class V2MainDataAPI(apigroup.APIGroup):
|
|||||||
new_version: str,
|
new_version: str,
|
||||||
):
|
):
|
||||||
"""提交更新记录"""
|
"""提交更新记录"""
|
||||||
return await self.do(
|
return self.do(
|
||||||
"POST",
|
"POST",
|
||||||
"/update",
|
"/update",
|
||||||
data={
|
data={
|
||||||
@@ -31,12 +31,12 @@ class V2MainDataAPI(apigroup.APIGroup):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
async def post_announcement_showed(
|
def post_announcement_showed(
|
||||||
self,
|
self,
|
||||||
ids: list[int],
|
ids: list[int],
|
||||||
):
|
):
|
||||||
"""提交公告已阅"""
|
"""提交公告已阅"""
|
||||||
return await self.do(
|
return self.do(
|
||||||
"POST",
|
"POST",
|
||||||
"/announcement",
|
"/announcement",
|
||||||
data={
|
data={
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ class V2PluginDataAPI(apigroup.APIGroup):
|
|||||||
def __init__(self, prefix: str):
|
def __init__(self, prefix: str):
|
||||||
super().__init__(prefix+"/plugin")
|
super().__init__(prefix+"/plugin")
|
||||||
|
|
||||||
async def post_install_record(
|
def post_install_record(
|
||||||
self,
|
self,
|
||||||
plugin: dict
|
plugin: dict
|
||||||
):
|
):
|
||||||
"""提交插件安装记录"""
|
"""提交插件安装记录"""
|
||||||
return await self.do(
|
return self.do(
|
||||||
"POST",
|
"POST",
|
||||||
"/install",
|
"/install",
|
||||||
data={
|
data={
|
||||||
@@ -23,12 +23,12 @@ class V2PluginDataAPI(apigroup.APIGroup):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
async def post_remove_record(
|
def post_remove_record(
|
||||||
self,
|
self,
|
||||||
plugin: dict
|
plugin: dict
|
||||||
):
|
):
|
||||||
"""提交插件卸载记录"""
|
"""提交插件卸载记录"""
|
||||||
return await self.do(
|
return self.do(
|
||||||
"POST",
|
"POST",
|
||||||
"/remove",
|
"/remove",
|
||||||
data={
|
data={
|
||||||
@@ -37,14 +37,14 @@ class V2PluginDataAPI(apigroup.APIGroup):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
async def post_update_record(
|
def post_update_record(
|
||||||
self,
|
self,
|
||||||
plugin: dict,
|
plugin: dict,
|
||||||
old_version: str,
|
old_version: str,
|
||||||
new_version: str,
|
new_version: str,
|
||||||
):
|
):
|
||||||
"""提交插件更新记录"""
|
"""提交插件更新记录"""
|
||||||
return await self.do(
|
return self.do(
|
||||||
"POST",
|
"POST",
|
||||||
"/update",
|
"/update",
|
||||||
data={
|
data={
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class V2UsageDataAPI(apigroup.APIGroup):
|
|||||||
def __init__(self, prefix: str):
|
def __init__(self, prefix: str):
|
||||||
super().__init__(prefix+"/usage")
|
super().__init__(prefix+"/usage")
|
||||||
|
|
||||||
async def post_query_record(
|
def post_query_record(
|
||||||
self,
|
self,
|
||||||
session_type: str,
|
session_type: str,
|
||||||
session_id: str,
|
session_id: str,
|
||||||
@@ -20,7 +20,7 @@ class V2UsageDataAPI(apigroup.APIGroup):
|
|||||||
retry_times: int,
|
retry_times: int,
|
||||||
):
|
):
|
||||||
"""提交请求记录"""
|
"""提交请求记录"""
|
||||||
return await self.do(
|
return self.do(
|
||||||
"POST",
|
"POST",
|
||||||
"/query",
|
"/query",
|
||||||
data={
|
data={
|
||||||
@@ -40,13 +40,13 @@ class V2UsageDataAPI(apigroup.APIGroup):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
async def post_event_record(
|
def post_event_record(
|
||||||
self,
|
self,
|
||||||
plugins: list[dict],
|
plugins: list[dict],
|
||||||
event_name: str,
|
event_name: str,
|
||||||
):
|
):
|
||||||
"""提交事件触发记录"""
|
"""提交事件触发记录"""
|
||||||
return await self.do(
|
return self.do(
|
||||||
"POST",
|
"POST",
|
||||||
"/event",
|
"/event",
|
||||||
data={
|
data={
|
||||||
@@ -59,14 +59,14 @@ class V2UsageDataAPI(apigroup.APIGroup):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
async def post_function_record(
|
def post_function_record(
|
||||||
self,
|
self,
|
||||||
plugin: dict,
|
plugin: dict,
|
||||||
function_name: str,
|
function_name: str,
|
||||||
function_description: str,
|
function_description: str,
|
||||||
):
|
):
|
||||||
"""提交内容函数使用记录"""
|
"""提交内容函数使用记录"""
|
||||||
return await self.do(
|
return self.do(
|
||||||
"POST",
|
"POST",
|
||||||
"/function",
|
"/function",
|
||||||
data={
|
data={
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ def compare_version_str(v0: str, v1: str) -> int:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
async def update_all(cli: bool = False) -> bool:
|
def update_all(cli: bool = False) -> bool:
|
||||||
"""检查更新并下载源码"""
|
"""检查更新并下载源码"""
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ async def update_all(cli: bool = False) -> bool:
|
|||||||
with open("current_tag", "w") as f:
|
with open("current_tag", "w") as f:
|
||||||
f.write(current_tag)
|
f.write(current_tag)
|
||||||
|
|
||||||
await context.get_center_v2_api().main.post_update_record(
|
context.get_center_v2_api().main.post_update_record(
|
||||||
spent_seconds=int(time.time()-start_time),
|
spent_seconds=int(time.time()-start_time),
|
||||||
infer_reason="update",
|
infer_reason="update",
|
||||||
old_version=old_tag,
|
old_version=old_tag,
|
||||||
|
|||||||
Reference in New Issue
Block a user