mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-07 12:50:03 +08:00
⚡️ 代码优化与修复
This commit is contained in:
@@ -88,7 +88,7 @@ class BanManage:
|
||||
session: EventSession,
|
||||
is_superuser: bool = False,
|
||||
) -> bool:
|
||||
"""ban掉目标用户
|
||||
"""unban目标用户
|
||||
|
||||
参数:
|
||||
user_id: 用户id
|
||||
@@ -102,7 +102,7 @@ class BanManage:
|
||||
user_level = 9999
|
||||
if not is_superuser and user_id and session.id1:
|
||||
user_level = await LevelUser.get_user_level(session.id1, group_id)
|
||||
if await BanConsole.check_ban_level(user_id, group_id, user_level):
|
||||
if not await BanConsole.check_ban_level(user_id, group_id, user_level):
|
||||
await BanConsole.unban(user_id, group_id)
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -65,7 +65,9 @@ _blmt = BanCheckLimiter(
|
||||
# 恶意触发命令检测
|
||||
@run_preprocessor
|
||||
async def _(matcher: Matcher, bot: Bot, session: EventSession, state: T_State):
|
||||
module = None
|
||||
if plugin := matcher.plugin:
|
||||
module = plugin.module_name
|
||||
if metadata := plugin.metadata:
|
||||
extra = metadata.extra
|
||||
if extra.get("plugin_type") == PluginType.HIDDEN:
|
||||
@@ -76,14 +78,8 @@ async def _(matcher: Matcher, bot: Bot, session: EventSession, state: T_State):
|
||||
if not malicious_ban_time:
|
||||
raise ValueError("模块: [hook], 配置项: [MALICIOUS_BAN_TIME] 为空或小于0")
|
||||
if user_id:
|
||||
command = state["_prefix"]["raw_command"]
|
||||
if state.get("_alc_result"):
|
||||
try:
|
||||
command = state["_alc_result"].source.command
|
||||
except AttributeError:
|
||||
pass
|
||||
if command:
|
||||
if _blmt.check(f"{user_id}__{command}"):
|
||||
if module:
|
||||
if _blmt.check(f"{user_id}__{module}"):
|
||||
await BanConsole.ban(
|
||||
user_id, group_id, 9, malicious_ban_time * 60, bot.self_id
|
||||
)
|
||||
@@ -104,4 +100,4 @@ async def _(matcher: Matcher, bot: Bot, session: EventSession, state: T_State):
|
||||
session=session,
|
||||
)
|
||||
raise IgnoredException("检测到恶意触发命令")
|
||||
_blmt.add(f"{user_id}__{command}")
|
||||
_blmt.add(f"{user_id}__{module}")
|
||||
|
||||
@@ -76,7 +76,7 @@ class BanConsole(Model):
|
||||
f"检测用户被ban等级,user_level: {user.ban_level},level: {level}",
|
||||
target=f"{group_id}:{user_id}",
|
||||
)
|
||||
return bool(user and user.ban_level >= level)
|
||||
return user.ban_level >= level
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -50,7 +50,7 @@ __plugin_meta__ = PluginMetadata(
|
||||
碧蓝航线/碧蓝[重型/轻型/特型/活动][1-300]抽: 碧蓝航线重型/轻型/特型/活动卡池
|
||||
fgo[1-300]抽: fgo卡池 (已失效)
|
||||
阴阳师[1-300]抽: 阴阳师卡池
|
||||
ba/碧蓝档案[1-200]抽:碧蓝档案卡池 (已失效)
|
||||
ba/碧蓝档案[1-200]抽:碧蓝档案卡池
|
||||
* 以上指令可以通过 XX一井 来指定最大抽取数量 *
|
||||
* 示例:原神一井 *
|
||||
""".strip(),
|
||||
|
||||
@@ -7,7 +7,7 @@ from nonebot_plugin_saa import Image, MessageFactory, Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.configs.path_config import IMAGE_PATH, TEMP_PATH
|
||||
from zhenxun.configs.path_config import TEMP_PATH
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.http_utils import AsyncHttpx
|
||||
@@ -34,7 +34,7 @@ headers = {
|
||||
}
|
||||
|
||||
_matcher = on_alconna(
|
||||
Alconna("p搜", Args["pid", int]), aliases={"P搜"}, priority=5, block=True
|
||||
Alconna("p搜", Args["pid", str]), aliases={"P搜"}, priority=5, block=True
|
||||
)
|
||||
|
||||
|
||||
@@ -44,11 +44,13 @@ async def _(pid: Match[int]):
|
||||
_matcher.set_path_arg("pid", pid.result)
|
||||
|
||||
|
||||
@_matcher.got_path("pid", prompt="需要查询的图片PID是?")
|
||||
async def _(bot: Bot, session: EventSession, arparma: Arparma, pid: int):
|
||||
@_matcher.got_path("pid", prompt="需要查询的图片PID是?或发送'取消'结束搜索")
|
||||
async def _(bot: Bot, session: EventSession, arparma: Arparma, pid: str):
|
||||
url = Config.get_config("hibiapi", "HIBIAPI") + "/api/pixiv/illust"
|
||||
if pid in ["取消", "算了"]:
|
||||
await Text("已取消操作...").finish()
|
||||
if not pid.isdigit():
|
||||
await Text("pid必须为数字...").finish()
|
||||
for _ in range(3):
|
||||
try:
|
||||
data = (
|
||||
@@ -61,6 +63,12 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, pid: int):
|
||||
except TimeoutError:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"pixiv pid 搜索发生了一些错误...",
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
e=e,
|
||||
)
|
||||
await Text(f"发生了一些错误..{type(e)}:{e}").finish()
|
||||
else:
|
||||
if data.get("error"):
|
||||
|
||||
@@ -185,11 +185,12 @@ class RussianManage:
|
||||
return MessageFactory(message_list)
|
||||
|
||||
async def accept(
|
||||
self, group_id: str, user_id: str, uname: str
|
||||
self, bot: Bot, group_id: str, user_id: str, uname: str
|
||||
) -> Text | MessageFactory:
|
||||
"""接受对决
|
||||
|
||||
参数:
|
||||
bot: Bot
|
||||
group_id: 群组id
|
||||
user_id: 用户id
|
||||
uname: 用户名称
|
||||
@@ -209,6 +210,7 @@ class RussianManage:
|
||||
return Text("你没有足够的钱来接受这场挑战...")
|
||||
russian.player2 = (user_id, uname)
|
||||
russian.next_user = russian.player1[0]
|
||||
self.__build_job(bot, group_id, True)
|
||||
return MessageFactory(
|
||||
[
|
||||
Text("决斗已经开始!请"),
|
||||
|
||||
@@ -28,7 +28,7 @@ async def login_get_token(form_data: OAuth2PasswordRequestForm = Depends()):
|
||||
password = Config.get_config("web-ui", "password")
|
||||
if not username or not password:
|
||||
return Result.fail("你滴配置文件里用户名密码配置项为空", 998)
|
||||
if username != form_data.username or password != form_data.password:
|
||||
if username != form_data.username or str(password) != form_data.password:
|
||||
return Result.fail("真笨, 账号密码都能记错!", 999)
|
||||
user = get_user(form_data.username)
|
||||
if not user:
|
||||
|
||||
Reference in New Issue
Block a user