mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
update v0.1.5.8
This commit is contained in:
parent
d4d6e736a4
commit
74e9c55a09
@ -243,6 +243,13 @@ __Docker 最新版本由 [Sakuracio](https://github.com/Sakuracio) 提供__
|
|||||||
|
|
||||||
## 更新
|
## 更新
|
||||||
|
|
||||||
|
### 2022/6/5 \[v0.1.5.9]
|
||||||
|
|
||||||
|
* webui修复plugin2setting中cmd从list转变为str
|
||||||
|
* 当命令`我的金币`被风控时将以图片形式发送
|
||||||
|
* fix gold_redbag [@pull/763](https://github.com/HibiKier/zhenxun_bot/pull/763)
|
||||||
|
* 金币红包功能增加更多封面 [@pull/764](https://github.com/HibiKier/zhenxun_bot/pull/764)
|
||||||
|
|
||||||
### 2022/6/3
|
### 2022/6/3
|
||||||
|
|
||||||
* 修复了webUI插件相关API问题
|
* 修复了webUI插件相关API问题
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
__version__: v0.1.5.8
|
__version__: v0.1.5.9
|
||||||
@ -1,9 +1,10 @@
|
|||||||
from nonebot import on_command
|
from nonebot import on_command
|
||||||
from nonebot.adapters.onebot.v11 import GroupMessageEvent, Message
|
from nonebot.adapters.onebot.v11 import GroupMessageEvent, Message, ActionFailed
|
||||||
from nonebot.params import CommandArg
|
from nonebot.params import CommandArg
|
||||||
from nonebot.adapters.onebot.v11.permission import GROUP
|
from nonebot.adapters.onebot.v11.permission import GROUP
|
||||||
from utils.data_utils import init_rank
|
from utils.data_utils import init_rank
|
||||||
from models.bag_user import BagUser
|
from models.bag_user import BagUser
|
||||||
|
from utils.image_utils import text2image
|
||||||
from utils.message_builder import image
|
from utils.message_builder import image
|
||||||
from utils.utils import is_number
|
from utils.utils import is_number
|
||||||
|
|
||||||
@ -34,7 +35,11 @@ gold_rank = on_command("金币排行", priority=5, block=True, permission=GROUP)
|
|||||||
|
|
||||||
@my_gold.handle()
|
@my_gold.handle()
|
||||||
async def _(event: GroupMessageEvent):
|
async def _(event: GroupMessageEvent):
|
||||||
await my_gold.finish(await BagUser.get_user_total_gold(event.user_id, event.group_id))
|
msg = await BagUser.get_user_total_gold(event.user_id, event.group_id)
|
||||||
|
try:
|
||||||
|
await my_gold.send(msg)
|
||||||
|
except ActionFailed:
|
||||||
|
await my_gold.send(image(b64=(await text2image(msg, color="#f9f6f2", padding=10)).pic2bs4()))
|
||||||
|
|
||||||
|
|
||||||
@gold_rank.handle()
|
@gold_rank.handle()
|
||||||
|
|||||||
@ -26,7 +26,7 @@ class GoodsUseFuncManager:
|
|||||||
判断商品使用方法是否被注册
|
判断商品使用方法是否被注册
|
||||||
:param goods_name: 商品名称
|
:param goods_name: 商品名称
|
||||||
"""
|
"""
|
||||||
return bool(self._data.get(goods_name))
|
return bool(self ._data.get(goods_name))
|
||||||
|
|
||||||
def get_max_num_limit(self, goods_name: str) -> int:
|
def get_max_num_limit(self, goods_name: str) -> int:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -80,8 +80,8 @@ async def _(
|
|||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
await bt.finish(f"搜索 {keyword} 超时...")
|
await bt.finish(f"搜索 {keyword} 超时...")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await bt.finish(f"bt 其他未知错误..")
|
|
||||||
logger.error(f"bt 错误 {type(e)}:{e}")
|
logger.error(f"bt 错误 {type(e)}:{e}")
|
||||||
|
await bt.finish(f"bt 其他未知错误..")
|
||||||
if not send_flag:
|
if not send_flag:
|
||||||
await bt.send(f"{keyword} 未搜索到...")
|
await bt.send(f"{keyword} 未搜索到...")
|
||||||
logger.info(f"USER {event.user_id} BT搜索 {keyword} 第 {page} 页")
|
logger.info(f"USER {event.user_id} BT搜索 {keyword} 第 {page} 页")
|
||||||
|
|||||||
@ -189,6 +189,9 @@ def _file_handle(latest_version: str) -> str:
|
|||||||
local_update_info_file.unlink()
|
local_update_info_file.unlink()
|
||||||
with open(_version_file, "w", encoding="utf8") as f:
|
with open(_version_file, "w", encoding="utf8") as f:
|
||||||
f.write(f"__version__: {latest_version}")
|
f.write(f"__version__: {latest_version}")
|
||||||
|
os.system(
|
||||||
|
f"poetry run pip install -r {(Path() / 'pyproject.toml').absolute()}"
|
||||||
|
)
|
||||||
return error
|
return error
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -58,4 +58,4 @@ async def _(group: GroupResult, user: User = Depends(token_to_user)) -> Result:
|
|||||||
group_manager.turn_on_group_bot_status(group_id)
|
group_manager.turn_on_group_bot_status(group_id)
|
||||||
else:
|
else:
|
||||||
group_manager.shutdown_group_bot_status(group_id)
|
group_manager.shutdown_group_bot_status(group_id)
|
||||||
return Result(code=200)
|
return Result(code=200, data="修改成功!")
|
||||||
|
|||||||
@ -121,7 +121,17 @@ def _(plugin: Plugin, user: User = Depends(token_to_user)) -> Result:
|
|||||||
isinstance(Config.get_config(plugin.model, c.key, c.value), list)
|
isinstance(Config.get_config(plugin.model, c.key, c.value), list)
|
||||||
or isinstance(c.default_value, list)
|
or isinstance(c.default_value, list)
|
||||||
):
|
):
|
||||||
|
default_value = Config.get_config(plugin.model, c.key, c.value)
|
||||||
c.value = c.value.split(",")
|
c.value = c.value.split(",")
|
||||||
|
if default_value and isinstance(default_value[0], int):
|
||||||
|
c.value = [int(x) for x in c.value]
|
||||||
|
elif default_value and isinstance(default_value[0], float):
|
||||||
|
c.value = [float(x) for x in c.value]
|
||||||
|
elif default_value and isinstance(default_value[0], bool):
|
||||||
|
temp = []
|
||||||
|
for x in c.value:
|
||||||
|
temp.append(x.lower() == "true")
|
||||||
|
c.value = temp
|
||||||
Config.set_config(plugin.model, c.key, c.value)
|
Config.set_config(plugin.model, c.key, c.value)
|
||||||
Config.save(None, True)
|
Config.save(None, True)
|
||||||
else:
|
else:
|
||||||
@ -139,4 +149,4 @@ def _(plugin: Plugin, user: User = Depends(token_to_user)) -> Result:
|
|||||||
code=500,
|
code=500,
|
||||||
data=f"WEB_UI POST /webui/plugins model:{plugin.model} 发生错误 {type(e)}:{e}",
|
data=f"WEB_UI POST /webui/plugins model:{plugin.model} 发生错误 {type(e)}:{e}",
|
||||||
)
|
)
|
||||||
return Result(code=200)
|
return Result(code=200, data="修改成功!")
|
||||||
|
|||||||
@ -34,7 +34,7 @@ async def _(parma: RequestParma, user: User = Depends(token_to_user)) -> Result:
|
|||||||
操作请求
|
操作请求
|
||||||
:param parma: 参数
|
:param parma: 参数
|
||||||
"""
|
"""
|
||||||
result = "ok"
|
result = "操作成功!"
|
||||||
flag = 3
|
flag = 3
|
||||||
if bot := get_bot():
|
if bot := get_bot():
|
||||||
if parma.handle == "approve":
|
if parma.handle == "approve":
|
||||||
|
|||||||
@ -29,7 +29,7 @@ disk_data = {"data": []}
|
|||||||
|
|
||||||
|
|
||||||
@app.get("/webui/system")
|
@app.get("/webui/system")
|
||||||
async def _(user: User = Depends(token_to_user)) -> Result:
|
async def _() -> Result:
|
||||||
return await get_system_data()
|
return await get_system_data()
|
||||||
|
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ async def _(user: User = Depends(token_to_user)) -> Result:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def get_system_data():
|
async def get_system_data(user: User = Depends(token_to_user)):
|
||||||
"""
|
"""
|
||||||
说明:
|
说明:
|
||||||
获取系统信息,资源文件大小,网络状态等
|
获取系统信息,资源文件大小,网络状态等
|
||||||
@ -92,7 +92,7 @@ async def get_system_data():
|
|||||||
logger.warning(f"访问Google失败... {type(e)}: {e}")
|
logger.warning(f"访问Google失败... {type(e)}: {e}")
|
||||||
google = 404
|
google = 404
|
||||||
network = SystemNetwork(baidu=baidu, google=google)
|
network = SystemNetwork(baidu=baidu, google=google)
|
||||||
disk = await asyncio.get_event_loop().run_in_executor(None, _get_system_disk)
|
disk = await asyncio.get_event_loop().run_in_executor(None, _get_system_disk, None)
|
||||||
status = await asyncio.get_event_loop().run_in_executor(None, _get_system_status)
|
status = await asyncio.get_event_loop().run_in_executor(None, _get_system_status)
|
||||||
return Result(
|
return Result(
|
||||||
code=200,
|
code=200,
|
||||||
@ -105,7 +105,7 @@ async def get_system_data():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _get_system_status() -> SystemStatus:
|
def _get_system_status(user: User = Depends(token_to_user)) -> SystemStatus:
|
||||||
"""
|
"""
|
||||||
说明:
|
说明:
|
||||||
获取系统信息等
|
获取系统信息等
|
||||||
@ -123,7 +123,7 @@ def _get_system_status() -> SystemStatus:
|
|||||||
|
|
||||||
|
|
||||||
def _get_system_disk(
|
def _get_system_disk(
|
||||||
type_: Optional[str],
|
type_: Optional[str], user: User = Depends(token_to_user)
|
||||||
) -> Union[SystemFolderSize, Dict[str, Union[float, datetime]]]:
|
) -> Union[SystemFolderSize, Dict[str, Union[float, datetime]]]:
|
||||||
"""
|
"""
|
||||||
说明:
|
说明:
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
|
import json
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from configs.path_config import DATA_PATH
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from starlette import status
|
from starlette import status
|
||||||
from fastapi import Depends, HTTPException
|
from fastapi import Depends, HTTPException
|
||||||
@ -8,6 +10,8 @@ from configs.config import Config
|
|||||||
from jose import JWTError, jwt
|
from jose import JWTError, jwt
|
||||||
import nonebot
|
import nonebot
|
||||||
|
|
||||||
|
from ..config import Result
|
||||||
|
|
||||||
app = nonebot.get_app()
|
app = nonebot.get_app()
|
||||||
|
|
||||||
|
|
||||||
@ -18,6 +22,13 @@ ACCESS_TOKEN_EXPIRE_MINUTES = 30
|
|||||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="webui/login")
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="webui/login")
|
||||||
|
|
||||||
|
|
||||||
|
token_file = DATA_PATH / "web_ui" / "token.json"
|
||||||
|
token_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
token_data = {"token": []}
|
||||||
|
if token_file.exists():
|
||||||
|
token_data = json.load(open(token_file, 'r', encoding='utf8'))
|
||||||
|
|
||||||
|
|
||||||
class User(BaseModel):
|
class User(BaseModel):
|
||||||
username: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
@ -62,6 +73,9 @@ async def login_get_token(form_data: OAuth2PasswordRequestForm = Depends()):
|
|||||||
if not user or user.password != form_data.password:
|
if not user or user.password != form_data.password:
|
||||||
raise form_exception
|
raise form_exception
|
||||||
access_token = create_token(user=user, expires_delta=timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES))
|
access_token = create_token(user=user, expires_delta=timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES))
|
||||||
|
token_data["token"].append(access_token)
|
||||||
|
if len(token_data["token"]) > 3:
|
||||||
|
token_data["token"] = token_data["token"][1:]
|
||||||
return {"access_token": access_token, "token_type": "bearer"}
|
return {"access_token": access_token, "token_type": "bearer"}
|
||||||
|
|
||||||
|
|
||||||
@ -72,16 +86,18 @@ credentials_exception = HTTPException(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/webui/auth")
|
||||||
def token_to_user(token: str = Depends(oauth2_scheme)):
|
def token_to_user(token: str = Depends(oauth2_scheme)):
|
||||||
try:
|
if token not in token_data["token"]:
|
||||||
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
try:
|
||||||
username, expire = payload.get("sub"), payload.get("exp")
|
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
|
||||||
user = get_user(username)
|
username, expire = payload.get("sub"), payload.get("exp")
|
||||||
if user is None:
|
user = get_user(username)
|
||||||
raise JWTError
|
if user is None:
|
||||||
except JWTError:
|
raise JWTError
|
||||||
raise credentials_exception
|
except JWTError:
|
||||||
return user
|
return Result(code=401)
|
||||||
|
return Result(code=200, data="ok")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import nonebot
|
|||||||
|
|
||||||
app = nonebot.get_app()
|
app = nonebot.get_app()
|
||||||
|
|
||||||
origins = ["http://localhost"]
|
origins = ["*"]
|
||||||
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
|
|||||||
@ -1509,7 +1509,7 @@ async def text2image(
|
|||||||
)
|
)
|
||||||
cur_h = ph
|
cur_h = ph
|
||||||
for img in image_list:
|
for img in image_list:
|
||||||
await A.apaste(img, (pw, cur_h + ph), True)
|
await A.apaste(img, (pw, cur_h), True)
|
||||||
cur_h += img.h + line_height
|
cur_h += img.h + line_height
|
||||||
return A
|
return A
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user