mirror of
https://github.com/ChenXu233/nonebot_plugin_dialectlist.git
synced 2026-01-25 21:22:16 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7baa9b04b | ||
|
|
df2cd495c0 | ||
|
|
d2e185c189 | ||
|
|
a753305282 | ||
|
|
ad5f556229 | ||
|
|
3efaafe81c | ||
|
|
e62f2ed488 | ||
|
|
e5d107c520 |
@@ -74,14 +74,17 @@ def wrapper(slot: Union[int, str], content: Optional[str], context) -> str:
|
|||||||
return content
|
return content
|
||||||
return "" # pragma: no cover
|
return "" # pragma: no cover
|
||||||
|
|
||||||
|
|
||||||
build_cache_cmd = on_command("build_cache", aliases={"重建缓存"}, block=True)
|
build_cache_cmd = on_command("build_cache", aliases={"重建缓存"}, block=True)
|
||||||
|
|
||||||
|
|
||||||
@build_cache_cmd.handle()
|
@build_cache_cmd.handle()
|
||||||
async def _build_cache(bot: Bot, event: Event):
|
async def _build_cache(bot: Bot, event: Event):
|
||||||
await saa.Text("正在重建缓存,请稍等。").send(reply=True)
|
await saa.Text("正在重建缓存,请稍等。").send(reply=True)
|
||||||
await build_cache()
|
await build_cache()
|
||||||
await saa.Text("重建缓存完成。").send(reply=True)
|
await saa.Text("重建缓存完成。").send(reply=True)
|
||||||
|
|
||||||
|
|
||||||
rank_cmd = on_alconna(
|
rank_cmd = on_alconna(
|
||||||
Alconna(
|
Alconna(
|
||||||
"B话榜",
|
"B话榜",
|
||||||
@@ -256,6 +259,8 @@ async def handle_rank(
|
|||||||
logger.debug(f"获取用户信息花费时间:{t.time() - t1}")
|
logger.debug(f"获取用户信息花费时间:{t.time() - t1}")
|
||||||
|
|
||||||
string: str = ""
|
string: str = ""
|
||||||
|
|
||||||
|
if plugin_config.show_text_rank:
|
||||||
for i in rank2:
|
for i in rank2:
|
||||||
logger.debug(i.user_name)
|
logger.debug(i.user_name)
|
||||||
for i in range(len(rank2)):
|
for i in range(len(rank2)):
|
||||||
@@ -267,17 +272,18 @@ async def handle_rank(
|
|||||||
string += str_example
|
string += str_example
|
||||||
|
|
||||||
msg = saa.Text(string)
|
msg = saa.Text(string)
|
||||||
t1 = t.time()
|
|
||||||
|
|
||||||
if plugin_config.visualization:
|
if plugin_config.visualization:
|
||||||
|
t1 = t.time()
|
||||||
image = await get_rank_image(rank2)
|
image = await get_rank_image(rank2)
|
||||||
msg += saa.Image(image)
|
msg += saa.Image(image)
|
||||||
|
logger.debug(f"群聊消息渲染图片花费时间:{t.time() - t1}")
|
||||||
|
|
||||||
if plugin_config.suffix:
|
if plugin_config.suffix:
|
||||||
timecost = t.time() - state["t1"]
|
timecost = t.time() - state["t1"]
|
||||||
suffix = saa.Text(plugin_config.string_suffix.format(timecost=timecost))
|
suffix = saa.Text(plugin_config.string_suffix.format(timecost=timecost))
|
||||||
msg += suffix
|
msg += suffix
|
||||||
|
if not msg:
|
||||||
logger.debug(f"群聊消息渲染图片花费时间:{t.time() - t1}")
|
await saa.Text("你把可视化都关了哪来的排行榜?").finish()
|
||||||
|
|
||||||
await msg.finish(reply=True)
|
await msg.finish(reply=True)
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ class ScopedConfig(BaseModel):
|
|||||||
suffix: bool = True # 是否显示后缀
|
suffix: bool = True # 是否显示后缀
|
||||||
excluded_self: bool = True # 是否排除自己
|
excluded_self: bool = True # 是否排除自己
|
||||||
visualization: bool = True # 是否可视化
|
visualization: bool = True # 是否可视化
|
||||||
|
show_text_rank:bool = True # 是否显示文本排名
|
||||||
counting_cache: bool = False # 计数缓存(能够提高回复速度)
|
counting_cache: bool = False # 计数缓存(能够提高回复速度)
|
||||||
excluded_people: List[str] = [] # 排除的人的QQ号
|
excluded_people: List[str] = [] # 排除的人的QQ号
|
||||||
|
use_user_info_cache: bool = False # 是否使用用户信息缓存
|
||||||
timezone: Optional[str] = "Asia/Shanghai" # 时区,影响统计时间
|
timezone: Optional[str] = "Asia/Shanghai" # 时区,影响统计时间
|
||||||
string_suffix: str = "统计花费时间:{timecost}秒" # 消息格式后缀
|
string_suffix: str = "统计花费时间:{timecost}秒" # 消息格式后缀
|
||||||
template_path: str = "./template/rank_template.j2" # 模板路径
|
template_path: str = "./template/rank_template.j2" # 模板路径
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ async def build_cache():
|
|||||||
where.append(
|
where.append(
|
||||||
or_(
|
or_(
|
||||||
MessageCountCache.time
|
MessageCountCache.time
|
||||||
== remove_timezone(msg.time.replace(hour=1, minute=0, second=0, microsecond=0))
|
== remove_timezone(
|
||||||
|
msg.time.replace(hour=1, minute=0, second=0, microsecond=0)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
statement = select(MessageCountCache).where(*where)
|
statement = select(MessageCountCache).where(*where)
|
||||||
@@ -68,7 +70,9 @@ async def build_cache():
|
|||||||
else:
|
else:
|
||||||
user_cache = MessageCountCache(
|
user_cache = MessageCountCache(
|
||||||
session_id=msg.session_persist_id,
|
session_id=msg.session_persist_id,
|
||||||
time=remove_timezone(msg.time.replace(hour=1, minute=0, second=0, microsecond=0)),
|
time=remove_timezone(
|
||||||
|
msg.time.replace(hour=1, minute=0, second=0, microsecond=0)
|
||||||
|
),
|
||||||
session_bnum=1,
|
session_bnum=1,
|
||||||
)
|
)
|
||||||
db_session.add(user_cache)
|
db_session.add(user_cache)
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ async def _get_user_default_avatar() -> bytes:
|
|||||||
).read()
|
).read()
|
||||||
return img
|
return img
|
||||||
|
|
||||||
|
|
||||||
async def _get_user_avatar(user: UserInfo, client: httpx.AsyncClient) -> bytes:
|
async def _get_user_avatar(user: UserInfo, client: httpx.AsyncClient) -> bytes:
|
||||||
if not user.user_avatar:
|
if not user.user_avatar:
|
||||||
return await _get_user_default_avatar()
|
return await _get_user_default_avatar()
|
||||||
@@ -208,6 +209,7 @@ async def _get_user_avatar(user: UserInfo, client: httpx.AsyncClient) -> bytes:
|
|||||||
await asyncio.sleep(3)
|
await asyncio.sleep(3)
|
||||||
raise NetworkError(f"{url} 下载失败!")
|
raise NetworkError(f"{url} 下载失败!")
|
||||||
|
|
||||||
|
|
||||||
def get_default_user_info() -> UserInfo:
|
def get_default_user_info() -> UserInfo:
|
||||||
user_info = UserInfo(
|
user_info = UserInfo(
|
||||||
user_id="114514",
|
user_id="114514",
|
||||||
@@ -215,8 +217,12 @@ def get_default_user_info() -> UserInfo:
|
|||||||
)
|
)
|
||||||
return user_info
|
return user_info
|
||||||
|
|
||||||
|
|
||||||
async def get_user_infos(
|
async def get_user_infos(
|
||||||
bot: Bot, event: Event, rank: List, use_cache: bool = True
|
bot: Bot,
|
||||||
|
event: Event,
|
||||||
|
rank: List,
|
||||||
|
use_cache: bool = plugin_config.use_user_info_cache,
|
||||||
) -> List[UserRankInfo]:
|
) -> List[UserRankInfo]:
|
||||||
|
|
||||||
user_ids = [i[0] for i in rank]
|
user_ids = [i[0] for i in rank]
|
||||||
@@ -253,11 +259,13 @@ async def get_user_infos(
|
|||||||
user_nickname=_get_user_nickname(user_info),
|
user_nickname=_get_user_nickname(user_info),
|
||||||
user_avatar_bytes=user_avatars[i],
|
user_avatar_bytes=user_avatars[i],
|
||||||
)
|
)
|
||||||
user.user_gender = (
|
print(user.user_gender)
|
||||||
"♂"
|
if user.user_gender == "male":
|
||||||
if user.user_gender == "male"
|
user.user_gender = "♂"
|
||||||
else "♀" if user.user_gender == "female" else ""
|
elif user.user_gender == "female":
|
||||||
)
|
user.user_gender = "♀"
|
||||||
|
else:
|
||||||
|
user.user_gender = "🤔"
|
||||||
rank2.append(user)
|
rank2.append(user)
|
||||||
|
|
||||||
return rank2
|
return rank2
|
||||||
|
|||||||
4
pdm.lock
generated
4
pdm.lock
generated
@@ -5,10 +5,10 @@
|
|||||||
groups = ["default", "Test", "dev"]
|
groups = ["default", "Test", "dev"]
|
||||||
strategy = ["inherit_metadata"]
|
strategy = ["inherit_metadata"]
|
||||||
lock_version = "4.5.0"
|
lock_version = "4.5.0"
|
||||||
content_hash = "sha256:f31fbbd00506680ed623e0216a48314dcbb142cebec25ebe15f1dc9a50915b25"
|
content_hash = "sha256:882dfc18d7454ced6bb1f46e04172b14b83f90157475153bf0fff7b13e4d41a2"
|
||||||
|
|
||||||
[[metadata.targets]]
|
[[metadata.targets]]
|
||||||
requires_python = "~=3.9"
|
requires_python = ">=3.9,<3.13"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aiofiles"
|
name = "aiofiles"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "nonebot-plugin-dialectlist"
|
name = "nonebot-plugin-dialectlist"
|
||||||
version = "2.4.2"
|
version = "2.4.4"
|
||||||
description = "看看你群群友有多能说"
|
description = "看看你群群友有多能说"
|
||||||
authors = [
|
authors = [
|
||||||
{name = "Chen_Xu233", email = "woyerpa@outlook.com"},
|
{name = "Chen_Xu233", email = "woyerpa@outlook.com"},
|
||||||
@@ -18,7 +18,7 @@ dependencies = [
|
|||||||
"pillow>=10.4.0",
|
"pillow>=10.4.0",
|
||||||
"nonebot-plugin-uninfo>=0.1.1",
|
"nonebot-plugin-uninfo>=0.1.1",
|
||||||
]
|
]
|
||||||
requires-python = ">=3.9,<4.0"
|
requires-python = ">=3.9,<3.13"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = {text = "MIT"}
|
license = {text = "MIT"}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user