diff --git a/.vscode/settings.json b/.vscode/settings.json index ca32420b..bc89a074 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,7 +25,8 @@ "ujson", "unban", "userinfo", - "zhenxun" + "zhenxun", + "jsdelivr" ], "python.analysis.autoImportCompletions": true, "python.testing.pytestArgs": ["tests"], diff --git a/zhenxun/builtin_plugins/nickname.py b/zhenxun/builtin_plugins/nickname.py index 60779e8b..0ad2cdc5 100644 --- a/zhenxun/builtin_plugins/nickname.py +++ b/zhenxun/builtin_plugins/nickname.py @@ -1,30 +1,31 @@ import random -from typing import Any, List +from typing import Any from nonebot import on_regex +from nonebot.rule import to_me from nonebot.adapters import Bot -from nonebot.params import Depends, RegexGroup from nonebot.plugin import PluginMetadata -from nonebot.rule import to_me -from nonebot_plugin_alconna import Alconna, Option, on_alconna, store_true +from nonebot.params import Depends, RegexGroup from nonebot_plugin_session import EventSession -from nonebot_plugin_userinfo import EventUserInfo, UserInfo +from nonebot_plugin_userinfo import UserInfo, EventUserInfo +from nonebot_plugin_alconna import Option, Alconna, on_alconna, store_true -from zhenxun.configs.config import BotConfig, Config -from zhenxun.configs.utils import PluginExtraData, RegisterConfig -from zhenxun.models.ban_console import BanConsole -from zhenxun.models.friend_user import FriendUser -from zhenxun.models.group_member_info import GroupInfoUser from zhenxun.services.log import logger -from zhenxun.utils.depends import UserName from zhenxun.utils.enum import PluginType +from zhenxun.utils.depends import UserName from zhenxun.utils.message import MessageUtils +from zhenxun.models.ban_console import BanConsole +from zhenxun.models.friend_user import FriendUser +from zhenxun.configs.config import Config, BotConfig +from zhenxun.models.group_member_info import GroupInfoUser +from zhenxun.configs.utils import RegisterConfig, PluginExtraData __plugin_meta__ = PluginMetadata( name="昵称系统", description="区区昵称,才不想叫呢!", usage=f""" - 个人昵称,将替换{BotConfig.self_nickname}称呼你的名称,群聊 与 私聊 昵称相互独立,全局昵称设置将更改您目前所有群聊中及私聊的昵称 + 个人昵称,将替换{BotConfig.self_nickname}称呼你的名称,群聊 与 私聊 昵称相互独立, + 全局昵称设置将更改您目前所有群聊中及私聊的昵称 指令: 以后叫我 [昵称]: 设置当前群聊/私聊的昵称 全局昵称设置 [昵称]: 设置当前所有群聊和私聊的昵称 @@ -39,9 +40,10 @@ RegisterConfig( key="BLACK_WORD", value=["爸", "爹", "爷", "父"], - help="昵称所屏蔽的关键词,已设置的昵称会被替换为 *,未设置的昵称会在设置时提示", + help="昵称所屏蔽的关键词,已设置的昵称会被替换为 *," + "未设置的昵称会在设置时提示", default_value=None, - type=List[str], + type=list[str], ) ], ).dict(), @@ -167,9 +169,8 @@ async def _( ): if session.id1: (name,) = reg_group - if len(name) < 5: - if random.random() < 0.3: - name = "~".join(name) + if len(name) < 5 and random.random() < 0.3: + name = "~".join(name) if gid := session.id3 or session.id2: await GroupInfoUser.set_user_nickname( session.id1, @@ -181,9 +182,6 @@ async def _( session.platform, ) logger.info(f"设置群昵称成功: {name}", "昵称设置", session=session) - await MessageUtils.build_message( - random.choice(CALL_NAME).format(name) - ).finish(reply_to=True) else: await FriendUser.set_user_nickname( session.id1, @@ -194,9 +192,9 @@ async def _( session.platform, ) logger.info(f"设置私聊昵称成功: {name}", "昵称设置", session=session) - await MessageUtils.build_message( - random.choice(CALL_NAME).format(name) - ).finish(reply_to=True) + await MessageUtils.build_message(random.choice(CALL_NAME).format(name)).finish( + reply_to=True + ) await MessageUtils.build_message("用户id为空...").send() diff --git a/zhenxun/utils/_image_template.py b/zhenxun/utils/_image_template.py index 6d81285d..56cd2fe4 100644 --- a/zhenxun/utils/_image_template.py +++ b/zhenxun/utils/_image_template.py @@ -159,9 +159,11 @@ async def table( column_data = [] for i in range(len(column_name)): c = [] - for lst in data_list: - if len(lst) > i: - c.append(str(lst[i])) + for item in data_list: + if len(item) > i: + c.append( + item[i] if isinstance(item[i], tuple | list) else str(item[i]) + ) else: c.append("") column_data.append(c) @@ -197,7 +199,7 @@ async def table( style = RowStyle(font=font) if text_style: style = text_style(column_name[i], item) - if isinstance(item, tuple): + if isinstance(item, tuple | list): """图片""" data, width, height = item image_ = None @@ -219,8 +221,6 @@ async def table( ) cur_h += base_h + row_space column_image_list.append(background) - # height = max([bk.height for bk in column_image_list]) - # width = sum([bk.width for bk in column_image_list]) return await BuildImage.auto_paste( column_image_list, len(column_image_list), column_space )