mirror of
https://github.com/ChenXu233/nonebot_plugin_dialectlist.git
synced 2025-01-31 15:32:13 +08:00
🎨 按ruff和black格式化代码
This commit is contained in:
parent
65dc67c6ac
commit
8d905cb647
@ -8,21 +8,18 @@ require("nonebot_plugin_alconna")
|
||||
require("nonebot_plugin_cesaa")
|
||||
|
||||
import re
|
||||
import os
|
||||
import time as t
|
||||
import nonebot_plugin_saa as saa
|
||||
|
||||
from typing import Union, Optional, List
|
||||
from typing import Union, Optional
|
||||
from datetime import datetime, timedelta
|
||||
from arclet.alconna import ArparmaBehavior
|
||||
from arclet.alconna.arparma import Arparma
|
||||
|
||||
from nonebot.log import logger
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.compat import model_dump
|
||||
from nonebot.params import Arg, Depends
|
||||
from nonebot.adapters import Bot, Event
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.plugin import PluginMetadata, inherit_supported_adapters
|
||||
from nonebot_plugin_alconna import (
|
||||
Args,
|
||||
@ -30,9 +27,6 @@ from nonebot_plugin_alconna import (
|
||||
Alconna,
|
||||
on_alconna,
|
||||
)
|
||||
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_userinfo import get_user_info
|
||||
from nonebot_plugin_chatrecorder import get_message_records
|
||||
from nonebot_plugin_session import Session, SessionIdType, extract_session
|
||||
|
||||
@ -45,7 +39,6 @@ from .time import (
|
||||
get_datetime_now_with_timezone,
|
||||
parse_datetime,
|
||||
)
|
||||
from .model import UserRankInfo
|
||||
from .utils import (
|
||||
got_rank,
|
||||
msg_counter,
|
||||
@ -216,7 +209,7 @@ async def handle_rank(
|
||||
start: datetime = Arg(),
|
||||
stop: datetime = Arg(),
|
||||
):
|
||||
|
||||
|
||||
if id := state["group_id"]:
|
||||
id = str(id)
|
||||
logger.debug(f"group_id: {id}")
|
||||
@ -228,7 +221,7 @@ async def handle_rank(
|
||||
await saa.Text("没有指定群哦").finish()
|
||||
|
||||
if plugin_config.counting_cache:
|
||||
raise Exception("我草缓存功能还没端上来呢,你怎么就先用上了")
|
||||
raise Exception("我草缓存功能还没端上来呢,你怎么就先用上了")
|
||||
else:
|
||||
messages = await get_message_records(
|
||||
id2s=[id],
|
||||
|
@ -1,5 +1,5 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional, List, Literal
|
||||
from typing import Optional, List
|
||||
from nonebot import get_driver, get_plugin_config
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ class ScopedConfig(BaseModel):
|
||||
suffix: bool = False # 是否显示后缀
|
||||
excluded_self: bool = True
|
||||
visualization: bool = True # 是否可视化
|
||||
counting_cache: bool = False # 计数缓存(没有完工)
|
||||
counting_cache: bool = False # 计数缓存(没有完工)
|
||||
excluded_people: List[str] = [] # 排除的人的QQ号
|
||||
timezone: Optional[str] = "Asia/Shanghai"
|
||||
string_suffix: str = "统计花费时间:{timecost}秒" # 消息格式后缀
|
||||
|
@ -1,7 +1,6 @@
|
||||
from datetime import datetime
|
||||
from typing import Union
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy import JSON, TEXT, String,Integer
|
||||
from sqlalchemy import Integer
|
||||
from nonebot_plugin_orm import Model
|
||||
from nonebot_plugin_userinfo import UserInfo
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
@ -19,6 +18,7 @@ class UserRankInfo(UserInfo):
|
||||
# session_id: str
|
||||
# session_bnum: int
|
||||
|
||||
|
||||
class MessageCountCache(Model):
|
||||
__table_args__ = {"extend_existing": True}
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
|
@ -1,4 +1,3 @@
|
||||
# TODO 时间处理模块,用于处理时间相关操作。
|
||||
from zoneinfo import ZoneInfo
|
||||
from typing import Optional, Union
|
||||
from datetime import datetime, time, tzinfo
|
||||
|
@ -2,7 +2,7 @@ import os
|
||||
import asyncio
|
||||
import unicodedata
|
||||
|
||||
from typing import Dict, List, Optional
|
||||
from typing import Dict, List
|
||||
from sqlalchemy import or_, select
|
||||
from sqlalchemy.sql import ColumnElement
|
||||
|
||||
@ -184,7 +184,9 @@ async def get_rank_image(rank: List[UserRankInfo]) -> bytes:
|
||||
},
|
||||
pages={"viewport": {"width": 1000, "height": 10}},
|
||||
)
|
||||
def _get_user_nickname(user_info:UserInfo)->str:
|
||||
|
||||
|
||||
def _get_user_nickname(user_info: UserInfo) -> str:
|
||||
user_nickname = (
|
||||
user_info.user_displayname
|
||||
if user_info.user_displayname
|
||||
@ -192,27 +194,31 @@ def _get_user_nickname(user_info:UserInfo)->str:
|
||||
)
|
||||
return user_nickname
|
||||
|
||||
async def _get_user_default_avatar()->bytes:
|
||||
|
||||
async def _get_user_default_avatar() -> bytes:
|
||||
img = open(
|
||||
os.path.dirname(os.path.abspath(__file__))
|
||||
+ "/template/avatar/default.jpg",
|
||||
os.path.dirname(os.path.abspath(__file__)) + "/template/avatar/default.jpg",
|
||||
"rb",
|
||||
).read()
|
||||
).read()
|
||||
return img
|
||||
|
||||
def get_default_user_info()->UserInfo:
|
||||
|
||||
def get_default_user_info() -> UserInfo:
|
||||
user_info = UserInfo(
|
||||
user_id="114514",
|
||||
user_name="鬼知道这谁,bot获取不了",
|
||||
)
|
||||
return user_info
|
||||
|
||||
async def get_user_infos(bot:Bot,event:Event,rank:List,use_cache: bool = True)-> List[UserRankInfo]:
|
||||
|
||||
|
||||
async def get_user_infos(
|
||||
bot: Bot, event: Event, rank: List, use_cache: bool = True
|
||||
) -> List[UserRankInfo]:
|
||||
|
||||
user_ids = [i[0] for i in rank]
|
||||
pool = [get_user_info(bot, event, id, use_cache) for id in user_ids]
|
||||
user_infos = (await asyncio.gather(*pool))
|
||||
|
||||
user_infos = await asyncio.gather(*pool)
|
||||
|
||||
pool = []
|
||||
for i in user_infos:
|
||||
if not i:
|
||||
@ -223,25 +229,24 @@ async def get_user_infos(bot:Bot,event:Event,rank:List,use_cache: bool = True)->
|
||||
user_avatars = await asyncio.gather(*pool)
|
||||
for i in user_avatars:
|
||||
if not i:
|
||||
user_avatars[user_avatars.index(i)] = await(_get_user_default_avatar())
|
||||
user_avatars[user_avatars.index(i)] = await _get_user_default_avatar()
|
||||
|
||||
total = sum([i[1] for i in rank])
|
||||
rank2 = []
|
||||
for i in range(len(rank)):
|
||||
|
||||
|
||||
user_info = user_infos[i]
|
||||
if not user_info:
|
||||
user_info = get_default_user_info()
|
||||
|
||||
|
||||
user = UserRankInfo(
|
||||
**model_dump(user_info),
|
||||
user_bnum=rank[i][1],
|
||||
user_proportion=round(rank[i][1] / total * 100, 2),
|
||||
user_index=i+1,
|
||||
user_index=i + 1,
|
||||
user_nickname=_get_user_nickname(user_info),
|
||||
user_avatar_bytes=user_avatars[i],
|
||||
)
|
||||
rank2.append(user)
|
||||
|
||||
return rank2
|
||||
|
||||
|
@ -49,6 +49,9 @@ indent-style = "tab"
|
||||
build = 'pdm run setup.py sdist'
|
||||
publish = 'pdm run python -m twine upload dist/*'
|
||||
|
||||
[tool.ruff.lint]
|
||||
ignore = ["E402"]
|
||||
|
||||
|
||||
# 以下为智普 AI 生成,还不知道这玩意有啥用。
|
||||
# [tool.pdm.dev-dependencies]
|
||||
|
Loading…
x
Reference in New Issue
Block a user