🎨 按ruff和black格式化代码

This commit is contained in:
Chenric 2024-09-21 20:18:40 +08:00
parent 65dc67c6ac
commit 8d905cb647
6 changed files with 31 additions and 31 deletions

View File

@ -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,

View File

@ -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

View File

@ -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)

View File

@ -1,4 +1,3 @@
# TODO 时间处理模块,用于处理时间相关操作。
from zoneinfo import ZoneInfo
from typing import Optional, Union
from datetime import datetime, time, tzinfo

View File

@ -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,26 +194,30 @@ 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()
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:
@ -223,7 +229,7 @@ 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 = []
@ -237,11 +243,10 @@ async def get_user_infos(bot:Bot,event:Event,rank:List,use_cache: bool = True)->
**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

View File

@ -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]