mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 00:32:06 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c4b515093 | ||
|
|
6d43989a4d | ||
|
|
fb1f15bcb4 | ||
|
|
81ad585a18 | ||
|
|
eb3bd2b4a6 | ||
|
|
e401914790 | ||
|
|
fef5dadaba | ||
|
|
c1348d08ed |
@@ -321,6 +321,12 @@ python bot.py
|
||||
|
||||
## 更新
|
||||
|
||||
### 2021/11/29 \[v0.0.6.4]
|
||||
|
||||
* 新增cos图撤回配置项
|
||||
* 新增默认群权限配置项
|
||||
* 修复权限等级类配置无法正常应用
|
||||
|
||||
### 2021/11/24 \[v0.0.6.3]
|
||||
|
||||
* 修复在线搜索色图出错
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
__version__: v0.0.6.3
|
||||
__version__: v0.0.6.4
|
||||
|
||||
@@ -92,11 +92,14 @@ def init_plugins_config(data_path):
|
||||
if user_config_file.exists():
|
||||
with open(user_config_file, "r", encoding="utf8") as f:
|
||||
_data = _yaml.load(f)
|
||||
# 数据替换
|
||||
for plugin in Config.keys():
|
||||
_tmp_data[plugin] = {}
|
||||
for k in Config[plugin].keys():
|
||||
if _data.get(plugin) and k in _data[plugin].keys():
|
||||
Config.set_config(plugin, k, _data[plugin][k])
|
||||
if level2module := Config.get_level2module(plugin, k):
|
||||
admin_manager.set_admin_level(level2module, _data[plugin][k])
|
||||
_tmp_data[plugin][k] = Config.get_config(plugin, k)
|
||||
Config.save()
|
||||
temp_file = Path() / "configs" / "temp_config.yaml"
|
||||
@@ -145,3 +148,4 @@ def init_plugins_config(data_path):
|
||||
logger.error(f"生成简易配置注释错误 {type(e)}:{e}")
|
||||
if temp_file.exists():
|
||||
temp_file.unlink()
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class ConfigsManager:
|
||||
name: Optional[str] = None,
|
||||
help_: Optional[str] = None,
|
||||
default_value: Optional[str] = None,
|
||||
_override: bool = False
|
||||
_override: bool = False,
|
||||
):
|
||||
"""
|
||||
为插件添加一个配置,不会被覆盖,只有第一个生效
|
||||
@@ -61,6 +61,7 @@ class ConfigsManager:
|
||||
"name": name.strip() if isinstance(name, str) else name,
|
||||
"help": help_.strip() if isinstance(help_, str) else help_,
|
||||
"default_value": default_value,
|
||||
"level_module": _module,
|
||||
}
|
||||
|
||||
def remove_plugin_config(self, module: str):
|
||||
@@ -119,6 +120,17 @@ class ConfigsManager:
|
||||
return self._data[module][key]["value"]
|
||||
return None
|
||||
|
||||
def get_level2module(self, module: str, key: str) -> Optional[str]:
|
||||
"""
|
||||
获取指定key所绑定的module,一般为权限等级
|
||||
:param module: 模块名
|
||||
:param key: 配置名称
|
||||
:return:
|
||||
"""
|
||||
if self._data.get(module) is not None:
|
||||
if self._data[module].get(key) is not None:
|
||||
return self._data[module][key].get("level_module")
|
||||
|
||||
def get(self, key: str):
|
||||
"""
|
||||
获取插件配置数据
|
||||
@@ -158,3 +170,4 @@ class ConfigsManager:
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self._data[key]
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ from nonebot.typing import T_State
|
||||
from nonebot.adapters.cqhttp import Bot, MessageEvent
|
||||
from utils.message_builder import image
|
||||
from services.log import logger
|
||||
from utils.manager import withdraw_message_manager
|
||||
from configs.config import Config
|
||||
|
||||
__zx_plugin_name__ = "coser"
|
||||
__plugin_usage__ = """
|
||||
@@ -21,6 +23,13 @@ __plugin_settings__ = {
|
||||
"limit_superuser": False,
|
||||
"cmd": ["cos", "coser", "括丝", "COS", "Cos", "cOS", "coS"],
|
||||
}
|
||||
__plugin_configs__ = {
|
||||
"WITHDRAW_COS_MESSAGE": {
|
||||
"value": (0, 1),
|
||||
"help": "自动撤回,参1:延迟撤回色图时间(秒),0 为关闭 | 参2:监控聊天类型,0(私聊) 1(群聊) 2(群聊+私聊)",
|
||||
"default_value": (0, 1),
|
||||
},
|
||||
}
|
||||
|
||||
coser = on_command(
|
||||
"cos", aliases={"coser", "括丝", "COS", "Cos", "cOS", "coS"}, priority=5, block=True
|
||||
@@ -33,7 +42,13 @@ url = "http://iw233.cn/API/cos.php"
|
||||
@coser.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
try:
|
||||
await coser.send(image(url))
|
||||
msg_id = await coser.send(image(url))
|
||||
withdraw_message_manager.withdraw_message(
|
||||
event,
|
||||
msg_id["message_id"],
|
||||
Config.get_config("coser", "WITHDRAW_COS_MESSAGE"),
|
||||
)
|
||||
except Exception as e:
|
||||
await coser.send("你cos给我看!")
|
||||
logger.error(f"coser 发送了未知错误 {type(e)}:{e}")
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from urllib.parse import unquote
|
||||
from services.log import logger
|
||||
from .util import remove_prohibited_str
|
||||
from utils.http_utils import AsyncHttpx
|
||||
from httpx import ConnectTimeout, CloseError
|
||||
import bs4
|
||||
import re
|
||||
try:
|
||||
@@ -57,9 +58,12 @@ async def update_info(url: str, game_name: str, info_list: list = None) -> 'dict
|
||||
data[name] = member_dict
|
||||
logger.info(f'{name} is update...')
|
||||
data = await _last_check(data, game_name)
|
||||
except TimeoutError:
|
||||
except (TimeoutError, ConnectTimeout, CloseError):
|
||||
logger.warning(f'更新 {game_name} 超时...')
|
||||
return {}, 999
|
||||
except Exception as e:
|
||||
logger.error(f"更新 {game_name} 未知错误 {type(e)}:{e}")
|
||||
return {}, 998
|
||||
with open(DRAW_PATH + f'{game_name}.json', 'w', encoding='utf8') as wf:
|
||||
wf.write(json.dumps(data, ensure_ascii=False, indent=4))
|
||||
return data, 200
|
||||
|
||||
@@ -5,6 +5,7 @@ from bs4 import BeautifulSoup
|
||||
from .util import remove_prohibited_str
|
||||
from utils.http_utils import AsyncHttpx
|
||||
from services.log import logger
|
||||
from httpx import ConnectTimeout, CloseError
|
||||
import asyncio
|
||||
|
||||
try:
|
||||
@@ -50,9 +51,12 @@ async def update_requests_info(game_name: str):
|
||||
data = add_to_data(data, x, game_name)
|
||||
logger.info(f"{key} is update...")
|
||||
data = await _last_check(data, game_name)
|
||||
except TimeoutError:
|
||||
except (TimeoutError, ConnectTimeout, CloseError):
|
||||
logger.warning(f"更新 {game_name} 超时...")
|
||||
return {}, 999
|
||||
except Exception as e:
|
||||
logger.error(f"更新 {game_name} 未知错误 {type(e)}:{e}")
|
||||
return {}, 998
|
||||
with open(DRAW_PATH + f"{game_name}.json", "w", encoding="utf8") as wf:
|
||||
json.dump(data, wf, ensure_ascii=False, indent=4)
|
||||
return data, 200
|
||||
@@ -150,6 +154,8 @@ async def _async_update_fgo_extra_info(url: str, key: str, _id: str, semaphore):
|
||||
x = {key: {}}
|
||||
x[key]["入手方式"] = obtain
|
||||
return x
|
||||
except TimeoutError:
|
||||
except (TimeoutError, ConnectTimeout, CloseError):
|
||||
logger.warning(f"访问{url}{_id} 第 {i}次 超时...已再次访问")
|
||||
except Exception as e:
|
||||
logger.error(f"访问{url}{_id} 第 {i}次 未知错误 {type(e)}:{e}...已再次访问")
|
||||
return {}
|
||||
|
||||
@@ -6,6 +6,7 @@ from .util import remove_prohibited_str
|
||||
from urllib.parse import unquote
|
||||
from services.log import logger
|
||||
from utils.http_utils import AsyncHttpx
|
||||
from httpx import ConnectTimeout, CloseError
|
||||
import bs4
|
||||
import asyncio
|
||||
|
||||
@@ -36,10 +37,13 @@ async def update_simple_info(url: str, game_name: str) -> 'dict, int':
|
||||
except AttributeError:
|
||||
continue
|
||||
for char in contents[1:]:
|
||||
data = await retrieve_char_data(char, game_name, data, index)
|
||||
try:
|
||||
data = await retrieve_char_data(char, game_name, data, index)
|
||||
except AttributeError:
|
||||
continue
|
||||
index += 1
|
||||
data = await _last_check(data, game_name)
|
||||
except TimeoutError:
|
||||
except (TimeoutError, ConnectTimeout, CloseError):
|
||||
logger.warning(f'更新 {game_name} 超时...')
|
||||
return {}, 999
|
||||
with open(DRAW_PATH + f'{game_name}.json', 'w', encoding='utf8') as wf:
|
||||
@@ -127,7 +131,6 @@ async def retrieve_char_data(char: bs4.element.Tag, game_name: str, data: dict,
|
||||
'名称': remove_prohibited_str(char.find('a')['title']),
|
||||
'星级': 3 - index}
|
||||
if game_name == 'azur':
|
||||
print(char)
|
||||
char = char.find('div').find('div').find('div').find('div')
|
||||
avatar_img = char.find('a').find('img')
|
||||
try:
|
||||
@@ -186,7 +189,9 @@ async def _async_update_azur_extra_info(key: str, semaphore):
|
||||
x = {key: {'获取途径': []}}
|
||||
logger.warning(f'碧蓝航线获取额外信息错误 {key}...{[]}')
|
||||
return x
|
||||
except TimeoutError:
|
||||
logger.warning(f'访问 https://wiki.biligame.com/blhx/{key} 第 {i}次 超时...已再次访问')
|
||||
except (TimeoutError, ConnectTimeout, CloseError):
|
||||
logger.warning(f'访问 https://wiki.biligame.com/blhx/{key} 第 {i}次 超时/失败...已再次访问')
|
||||
except Exception as e:
|
||||
logger.error(f'访问 https://wiki.biligame.com/blhx/{key} 第 {i}次 未知错误 {type(e)}:{e}...已再次访问')
|
||||
return {}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"models",
|
||||
"basic_plugins",
|
||||
"utils",
|
||||
"services"
|
||||
],
|
||||
"add_file": [],
|
||||
"delete_file": []
|
||||
|
||||
@@ -2,9 +2,15 @@ from typing import Optional, List, Union, Dict
|
||||
from pathlib import Path
|
||||
from .data_class import StaticData
|
||||
from utils.utils import get_matchers, get_bot
|
||||
from configs.config import Config
|
||||
import nonebot
|
||||
|
||||
|
||||
Config.add_plugin_config(
|
||||
"group_manager", "DEFAULT_GROUP_LEVEL", 5, help_="默认群权限", default_value=5
|
||||
)
|
||||
|
||||
|
||||
class GroupManager(StaticData):
|
||||
"""
|
||||
群权限 | 功能 | 聊天时间 管理器
|
||||
@@ -274,7 +280,7 @@ class GroupManager(StaticData):
|
||||
参数:
|
||||
:param group_id: 群号
|
||||
"""
|
||||
default_group_level = 5 # Config.get_config("group_manager")
|
||||
default_group_level = Config.get_config("group_manager", "DEFAULT_GROUP_LEVEL")
|
||||
if not default_group_level:
|
||||
default_group_level = 5
|
||||
if not self._data["group_manager"].get(group_id):
|
||||
@@ -293,3 +299,4 @@ class GroupManager(StaticData):
|
||||
del self._data["super"]["close_plugins"]
|
||||
return _x
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user