mirror of
https://github.com/ChenXu233/nonebot_plugin_dialectlist.git
synced 2024-11-28 02:18:02 +08:00
💄 性别显示
This commit is contained in:
parent
d514d96db6
commit
e5d107c520
@ -31,7 +31,7 @@ from nonebot_plugin_alconna import (
|
||||
from nonebot_plugin_chatrecorder import get_message_records
|
||||
from nonebot_plugin_session import Session, SessionIdType, extract_session
|
||||
|
||||
from .storage import get_cache,build_cache
|
||||
from .storage import get_cache, build_cache
|
||||
from .config import Config, plugin_config
|
||||
from .usage import __usage__
|
||||
from .time import (
|
||||
@ -74,14 +74,17 @@ def wrapper(slot: Union[int, str], content: Optional[str], context) -> str:
|
||||
return content
|
||||
return "" # pragma: no cover
|
||||
|
||||
|
||||
build_cache_cmd = on_command("build_cache", aliases={"重建缓存"}, block=True)
|
||||
|
||||
|
||||
@build_cache_cmd.handle()
|
||||
async def _build_cache(bot: Bot, event: Event):
|
||||
await saa.Text("正在重建缓存,请稍等。").send(reply=True)
|
||||
await build_cache()
|
||||
await saa.Text("重建缓存完成。").send(reply=True)
|
||||
|
||||
|
||||
rank_cmd = on_alconna(
|
||||
Alconna(
|
||||
"B话榜",
|
||||
|
@ -11,6 +11,7 @@ class ScopedConfig(BaseModel):
|
||||
visualization: bool = True # 是否可视化
|
||||
counting_cache: bool = False # 计数缓存(能够提高回复速度)
|
||||
excluded_people: List[str] = [] # 排除的人的QQ号
|
||||
use_user_info_cache: bool = False # 是否使用用户信息缓存
|
||||
timezone: Optional[str] = "Asia/Shanghai" # 时区,影响统计时间
|
||||
string_suffix: str = "统计花费时间:{timecost}秒" # 消息格式后缀
|
||||
template_path: str = "./template/rank_template.j2" # 模板路径
|
||||
|
@ -6,7 +6,7 @@ from sqlalchemy import delete, or_, select
|
||||
from nonebot import get_driver
|
||||
from nonebot.log import logger
|
||||
from nonebot.params import Depends
|
||||
from nonebot.adapters import Event,Bot
|
||||
from nonebot.adapters import Event, Bot
|
||||
from nonebot.message import event_postprocessor
|
||||
|
||||
from .model import MessageCountCache
|
||||
@ -56,7 +56,9 @@ async def build_cache():
|
||||
where.append(
|
||||
or_(
|
||||
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)
|
||||
@ -68,7 +70,9 @@ async def build_cache():
|
||||
else:
|
||||
user_cache = MessageCountCache(
|
||||
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,
|
||||
)
|
||||
db_session.add(user_cache)
|
||||
@ -100,7 +104,7 @@ async def _():
|
||||
|
||||
|
||||
@event_postprocessor
|
||||
async def _(bot: Bot, event: Event,session: Session = Depends(extract_session)):
|
||||
async def _(bot: Bot, event: Event, session: Session = Depends(extract_session)):
|
||||
if not plugin_config.counting_cache:
|
||||
return
|
||||
if not session.id2:
|
||||
@ -112,7 +116,7 @@ async def _(bot: Bot, event: Event,session: Session = Depends(extract_session)):
|
||||
|
||||
async with get_session() as db_session:
|
||||
session_id = await get_session_persist_id(session)
|
||||
logger.debug("session_id:"+str(session_id))
|
||||
logger.debug("session_id:" + str(session_id))
|
||||
where = [or_(MessageCountCache.session_id == session_id)]
|
||||
where.append(or_(MessageCountCache.time == remove_timezone(now)))
|
||||
statement = select(MessageCountCache).where(*where)
|
||||
|
@ -194,6 +194,7 @@ async def _get_user_default_avatar() -> bytes:
|
||||
).read()
|
||||
return img
|
||||
|
||||
|
||||
async def _get_user_avatar(user: UserInfo, client: httpx.AsyncClient) -> bytes:
|
||||
if not user.user_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)
|
||||
raise NetworkError(f"{url} 下载失败!")
|
||||
|
||||
|
||||
def get_default_user_info() -> UserInfo:
|
||||
user_info = UserInfo(
|
||||
user_id="114514",
|
||||
@ -215,8 +217,12 @@ def get_default_user_info() -> UserInfo:
|
||||
)
|
||||
return user_info
|
||||
|
||||
|
||||
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]:
|
||||
|
||||
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_avatar_bytes=user_avatars[i],
|
||||
)
|
||||
user.user_gender = (
|
||||
"♂"
|
||||
if user.user_gender == "male"
|
||||
else "♀" if user.user_gender == "female" else ""
|
||||
)
|
||||
print(user.user_gender)
|
||||
if user.user_gender == "male":
|
||||
user.user_gender = "♂"
|
||||
elif user.user_gender == "female":
|
||||
user.user_gender = "♀"
|
||||
else:
|
||||
user.user_gender = "🤔"
|
||||
rank2.append(user)
|
||||
|
||||
return rank2
|
||||
|
@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "nonebot-plugin-dialectlist"
|
||||
version = "2.4.1"
|
||||
version = "2.4.2"
|
||||
description = "看看你群群友有多能说"
|
||||
authors = [
|
||||
{name = "Chen_Xu233", email = "woyerpa@outlook.com"},
|
||||
|
Loading…
Reference in New Issue
Block a user