Skip to content

Commit

Permalink
🐛 修复图片模板方法
Browse files Browse the repository at this point in the history
  • Loading branch information
HibiKier committed Nov 16, 2024
1 parent 545f6fd commit ae5df38
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"ujson",
"unban",
"userinfo",
"zhenxun"
"zhenxun",
"jsdelivr"
],
"python.analysis.autoImportCompletions": true,
"python.testing.pytestArgs": ["tests"],
Expand Down
44 changes: 21 additions & 23 deletions zhenxun/builtin_plugins/nickname.py
Original file line number Diff line number Diff line change
@@ -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}称呼你的名称,群聊 与 私聊 昵称相互独立,
全局昵称设置将更改您目前所有群聊中及私聊的昵称
指令:
以后叫我 [昵称]: 设置当前群聊/私聊的昵称
全局昵称设置 [昵称]: 设置当前所有群聊和私聊的昵称
Expand All @@ -39,9 +40,10 @@
RegisterConfig(
key="BLACK_WORD",
value=["爸", "爹", "爷", "父"],
help="昵称所屏蔽的关键词,已设置的昵称会被替换为 *,未设置的昵称会在设置时提示",
help="昵称所屏蔽的关键词,已设置的昵称会被替换为 *,"
"未设置的昵称会在设置时提示",
default_value=None,
type=List[str],
type=list[str],
)
],
).dict(),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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()


Expand Down
12 changes: 6 additions & 6 deletions zhenxun/utils/_image_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
)
Expand Down

0 comments on commit ae5df38

Please sign in to comment.