Skip to content

Commit ae5df38

Browse files
committed
🐛 修复图片模板方法
1 parent 545f6fd commit ae5df38

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"ujson",
2626
"unban",
2727
"userinfo",
28-
"zhenxun"
28+
"zhenxun",
29+
"jsdelivr"
2930
],
3031
"python.analysis.autoImportCompletions": true,
3132
"python.testing.pytestArgs": ["tests"],

zhenxun/builtin_plugins/nickname.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
import random
2-
from typing import Any, List
2+
from typing import Any
33

44
from nonebot import on_regex
5+
from nonebot.rule import to_me
56
from nonebot.adapters import Bot
6-
from nonebot.params import Depends, RegexGroup
77
from nonebot.plugin import PluginMetadata
8-
from nonebot.rule import to_me
9-
from nonebot_plugin_alconna import Alconna, Option, on_alconna, store_true
8+
from nonebot.params import Depends, RegexGroup
109
from nonebot_plugin_session import EventSession
11-
from nonebot_plugin_userinfo import EventUserInfo, UserInfo
10+
from nonebot_plugin_userinfo import UserInfo, EventUserInfo
11+
from nonebot_plugin_alconna import Option, Alconna, on_alconna, store_true
1212

13-
from zhenxun.configs.config import BotConfig, Config
14-
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
15-
from zhenxun.models.ban_console import BanConsole
16-
from zhenxun.models.friend_user import FriendUser
17-
from zhenxun.models.group_member_info import GroupInfoUser
1813
from zhenxun.services.log import logger
19-
from zhenxun.utils.depends import UserName
2014
from zhenxun.utils.enum import PluginType
15+
from zhenxun.utils.depends import UserName
2116
from zhenxun.utils.message import MessageUtils
17+
from zhenxun.models.ban_console import BanConsole
18+
from zhenxun.models.friend_user import FriendUser
19+
from zhenxun.configs.config import Config, BotConfig
20+
from zhenxun.models.group_member_info import GroupInfoUser
21+
from zhenxun.configs.utils import RegisterConfig, PluginExtraData
2222

2323
__plugin_meta__ = PluginMetadata(
2424
name="昵称系统",
2525
description="区区昵称,才不想叫呢!",
2626
usage=f"""
27-
个人昵称,将替换{BotConfig.self_nickname}称呼你的名称,群聊 与 私聊 昵称相互独立,全局昵称设置将更改您目前所有群聊中及私聊的昵称
27+
个人昵称,将替换{BotConfig.self_nickname}称呼你的名称,群聊 与 私聊 昵称相互独立,
28+
全局昵称设置将更改您目前所有群聊中及私聊的昵称
2829
指令:
2930
以后叫我 [昵称]: 设置当前群聊/私聊的昵称
3031
全局昵称设置 [昵称]: 设置当前所有群聊和私聊的昵称
@@ -39,9 +40,10 @@
3940
RegisterConfig(
4041
key="BLACK_WORD",
4142
value=["爸", "爹", "爷", "父"],
42-
help="昵称所屏蔽的关键词,已设置的昵称会被替换为 *,未设置的昵称会在设置时提示",
43+
help="昵称所屏蔽的关键词,已设置的昵称会被替换为 *,"
44+
"未设置的昵称会在设置时提示",
4345
default_value=None,
44-
type=List[str],
46+
type=list[str],
4547
)
4648
],
4749
).dict(),
@@ -167,9 +169,8 @@ async def _(
167169
):
168170
if session.id1:
169171
(name,) = reg_group
170-
if len(name) < 5:
171-
if random.random() < 0.3:
172-
name = "~".join(name)
172+
if len(name) < 5 and random.random() < 0.3:
173+
name = "~".join(name)
173174
if gid := session.id3 or session.id2:
174175
await GroupInfoUser.set_user_nickname(
175176
session.id1,
@@ -181,9 +182,6 @@ async def _(
181182
session.platform,
182183
)
183184
logger.info(f"设置群昵称成功: {name}", "昵称设置", session=session)
184-
await MessageUtils.build_message(
185-
random.choice(CALL_NAME).format(name)
186-
).finish(reply_to=True)
187185
else:
188186
await FriendUser.set_user_nickname(
189187
session.id1,
@@ -194,9 +192,9 @@ async def _(
194192
session.platform,
195193
)
196194
logger.info(f"设置私聊昵称成功: {name}", "昵称设置", session=session)
197-
await MessageUtils.build_message(
198-
random.choice(CALL_NAME).format(name)
199-
).finish(reply_to=True)
195+
await MessageUtils.build_message(random.choice(CALL_NAME).format(name)).finish(
196+
reply_to=True
197+
)
200198
await MessageUtils.build_message("用户id为空...").send()
201199

202200

zhenxun/utils/_image_template.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ async def table(
159159
column_data = []
160160
for i in range(len(column_name)):
161161
c = []
162-
for lst in data_list:
163-
if len(lst) > i:
164-
c.append(str(lst[i]))
162+
for item in data_list:
163+
if len(item) > i:
164+
c.append(
165+
item[i] if isinstance(item[i], tuple | list) else str(item[i])
166+
)
165167
else:
166168
c.append("")
167169
column_data.append(c)
@@ -197,7 +199,7 @@ async def table(
197199
style = RowStyle(font=font)
198200
if text_style:
199201
style = text_style(column_name[i], item)
200-
if isinstance(item, tuple):
202+
if isinstance(item, tuple | list):
201203
"""图片"""
202204
data, width, height = item
203205
image_ = None
@@ -219,8 +221,6 @@ async def table(
219221
)
220222
cur_h += base_h + row_space
221223
column_image_list.append(background)
222-
# height = max([bk.height for bk in column_image_list])
223-
# width = sum([bk.width for bk in column_image_list])
224224
return await BuildImage.auto_paste(
225225
column_image_list, len(column_image_list), column_space
226226
)

0 commit comments

Comments
 (0)