Add fastapi dependency and remove nonebot-plugin-userinfo

This commit is contained in:
HibiKier 2025-01-09 08:46:30 +08:00 committed by BalconyJH
parent e2111278d2
commit 73d2ed444e
7 changed files with 672 additions and 823 deletions

1244
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -23,12 +23,11 @@ strenum = "^0.4.15"
nonebot-plugin-session = "^0.2.3" nonebot-plugin-session = "^0.2.3"
ujson = "^5.9.0" ujson = "^5.9.0"
nb-cli = "^1.3.0" nb-cli = "^1.3.0"
nonebot2 = "^2.1.3" nonebot2 = {extras = ["fastapi"], version = "^2.3.3"}
pillow = "^10.0.0" pillow = "^10.0.0"
retrying = "^1.3.4" retrying = "^1.3.4"
aiofiles = "^23.2.1" aiofiles = "^23.2.1"
nonebot-plugin-htmlrender = "^0.3.0" nonebot-plugin-htmlrender = "^0.3.0"
nonebot-plugin-userinfo = "^0.1.3"
pypinyin = "^0.51.0" pypinyin = "^0.51.0"
beautifulsoup4 = "^4.12.3" beautifulsoup4 = "^4.12.3"
lxml = "^5.1.0" lxml = "^5.1.0"
@ -61,7 +60,6 @@ plugins = [
"nonebot_plugin_apscheduler", "nonebot_plugin_apscheduler",
"nonebot_plugin_session", "nonebot_plugin_session",
"nonebot_plugin_htmlrender", "nonebot_plugin_htmlrender",
"nonebot_plugin_userinfo",
"nonebot_plugin_alconna", "nonebot_plugin_alconna",
] ]
plugin_dirs = ["zhenxun/services", "zhenxun/builtin_plugins", "zhenxun/plugins"] plugin_dirs = ["zhenxun/services", "zhenxun/builtin_plugins", "zhenxun/plugins"]

View File

@ -1,39 +1,38 @@
aiocache==0.12.3 ; python_version >= "3.10" and python_version < "4.0" aiocache==0.12.3 ; python_version >= "3.10" and python_version < "4.0"
aiofiles==23.2.1 ; python_version >= "3.10" and python_version < "4.0" aiofiles==23.2.1 ; python_version >= "3.10" and python_version < "4.0"
aiosqlite==0.17.0 ; python_version >= "3.10" and python_version < "4.0" aiosqlite==0.17.0 ; python_version >= "3.10" and python_version < "4.0"
anyio==4.7.0 ; python_version >= "3.10" and python_version < "4.0" annotated-types==0.7.0 ; python_version >= "3.10" and python_version < "4.0"
anyio==4.8.0 ; python_version >= "3.10" and python_version < "4.0"
apscheduler==3.11.0 ; python_version >= "3.10" and python_version < "4.0" apscheduler==3.11.0 ; python_version >= "3.10" and python_version < "4.0"
arclet-alconna-tools==0.7.10 ; python_version >= "3.10" and python_version < "4.0" arclet-alconna-tools==0.7.10 ; python_version >= "3.10" and python_version < "4.0"
arclet-alconna==1.8.35 ; python_version >= "3.10" and python_version < "4.0" arclet-alconna==1.8.35 ; python_version >= "3.10" and python_version < "4.0"
arrow==1.3.0 ; python_version >= "3.10" and python_version < "4.0" arrow==1.3.0 ; python_version >= "3.10" and python_version < "4.0"
async-timeout==5.0.1 ; python_version >= "3.10" and python_version < "3.11.0" async-timeout==5.0.1 ; python_version >= "3.10" and python_version < "3.11.0"
asyncpg==0.30.0 ; python_version >= "3.10" and python_version < "4.0" asyncpg==0.30.0 ; python_version >= "3.10" and python_version < "4.0"
attrs==24.2.0 ; python_version >= "3.10" and python_version < "4.0" attrs==24.3.0 ; python_version >= "3.10" and python_version < "4.0"
beautifulsoup4==4.12.3 ; python_version >= "3.10" and python_version < "4.0" beautifulsoup4==4.12.3 ; python_version >= "3.10" and python_version < "4.0"
bilireq==0.2.3.post0 ; python_version >= "3.10" and python_version < "4.0" bilireq==0.2.3.post0 ; python_version >= "3.10" and python_version < "4.0"
binaryornot==0.4.4 ; python_version >= "3.10" and python_version < "4.0" binaryornot==0.4.4 ; python_version >= "3.10" and python_version < "4.0"
cachetools==5.5.0 ; python_version >= "3.10" and python_version < "4.0"
cashews==7.4.0 ; python_version >= "3.10" and python_version < "4.0" cashews==7.4.0 ; python_version >= "3.10" and python_version < "4.0"
cattrs==23.2.3 ; python_version >= "3.10" and python_version < "4.0" cattrs==23.2.3 ; python_version >= "3.10" and python_version < "4.0"
certifi==2024.8.30 ; python_version >= "3.10" and python_version < "4.0" certifi==2024.12.14 ; python_version >= "3.10" and python_version < "4.0"
cffi==1.17.1 ; python_version >= "3.10" and python_version < "4.0" and platform_python_implementation != "PyPy" cffi==1.17.1 ; python_version >= "3.10" and python_version < "4.0" and platform_python_implementation != "PyPy"
chardet==5.2.0 ; python_version >= "3.10" and python_version < "4.0" chardet==5.2.0 ; python_version >= "3.10" and python_version < "4.0"
charset-normalizer==3.4.0 ; python_version >= "3.10" and python_version < "4.0" charset-normalizer==3.4.1 ; python_version >= "3.10" and python_version < "4.0"
click==8.1.7 ; python_version >= "3.10" and python_version < "4.0" click==8.1.8 ; python_version >= "3.10" and python_version < "4.0"
cn2an==0.5.22 ; python_version >= "3.10" and python_version < "4.0" cn2an==0.5.23 ; python_version >= "3.10" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and (platform_system == "Windows" or sys_platform == "win32") colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and (platform_system == "Windows" or sys_platform == "win32")
cookiecutter==2.6.0 ; python_version >= "3.10" and python_version < "4.0" cookiecutter==2.6.0 ; python_version >= "3.10" and python_version < "4.0"
cryptography==44.0.0 ; python_version >= "3.10" and python_version < "4.0" cryptography==44.0.0 ; python_version >= "3.10" and python_version < "4.0"
dateparser==1.2.0 ; python_version >= "3.10" and python_version < "4.0" dateparser==1.2.0 ; python_version >= "3.10" and python_version < "4.0"
distlib==0.3.9 ; python_version >= "3.10" and python_version < "4.0" distlib==0.3.9 ; python_version >= "3.10" and python_version < "4.0"
ecdsa==0.19.0 ; python_version >= "3.10" and python_version < "4.0" ecdsa==0.19.0 ; python_version >= "3.10" and python_version < "4.0"
emoji==2.14.0 ; python_version >= "3.10" and python_version < "4.0"
exceptiongroup==1.2.2 ; python_version >= "3.10" and python_version < "4.0" exceptiongroup==1.2.2 ; python_version >= "3.10" and python_version < "4.0"
fastapi==0.115.6 ; python_version >= "3.10" and python_version < "4.0" fastapi==0.115.6 ; python_version >= "3.10" and python_version < "4.0"
feedparser==6.0.11 ; python_version >= "3.10" and python_version < "4.0" feedparser==6.0.11 ; python_version >= "3.10" and python_version < "4.0"
filelock==3.16.1 ; python_version >= "3.10" and python_version < "4.0" filelock==3.16.1 ; python_version >= "3.10" and python_version < "4.0"
greenlet==3.1.1 ; python_version >= "3.10" and python_version < "4.0" greenlet==3.1.1 ; python_version >= "3.10" and python_version < "4.0"
grpcio==1.68.1 ; python_version >= "3.10" and python_version < "4.0" grpcio==1.69.0 ; python_version >= "3.10" and python_version < "4.0"
h11==0.14.0 ; python_version >= "3.10" and python_version < "4.0" h11==0.14.0 ; python_version >= "3.10" and python_version < "4.0"
httpcore==0.16.3 ; python_version >= "3.10" and python_version < "4.0" httpcore==0.16.3 ; python_version >= "3.10" and python_version < "4.0"
httptools==0.6.4 ; python_version >= "3.10" and python_version < "4.0" httptools==0.6.4 ; python_version >= "3.10" and python_version < "4.0"
@ -42,7 +41,7 @@ idna==3.10 ; python_version >= "3.10" and python_version < "4.0"
imagehash==4.3.1 ; python_version >= "3.10" and python_version < "4.0" imagehash==4.3.1 ; python_version >= "3.10" and python_version < "4.0"
importlib-metadata==8.5.0 ; python_version >= "3.10" and python_version < "4.0" importlib-metadata==8.5.0 ; python_version >= "3.10" and python_version < "4.0"
iso8601==1.1.0 ; python_version >= "3.10" and python_version < "4.0" iso8601==1.1.0 ; python_version >= "3.10" and python_version < "4.0"
jinja2==3.1.4 ; python_version >= "3.10" and python_version < "4.0" jinja2==3.1.5 ; python_version >= "3.10" and python_version < "4.0"
loguru==0.7.3 ; python_version >= "3.10" and python_version < "4.0" loguru==0.7.3 ; python_version >= "3.10" and python_version < "4.0"
lxml==5.3.0 ; python_version >= "3.10" and python_version < "4.0" lxml==5.3.0 ; python_version >= "3.10" and python_version < "4.0"
markdown-it-py==3.0.0 ; python_version >= "3.10" and python_version < "4.0" markdown-it-py==3.0.0 ; python_version >= "3.10" and python_version < "4.0"
@ -54,17 +53,16 @@ multidict==6.1.0 ; python_version >= "3.10" and python_version < "4.0"
nb-cli==1.4.2 ; python_version >= "3.10" and python_version < "4.0" nb-cli==1.4.2 ; python_version >= "3.10" and python_version < "4.0"
nepattern==0.7.7 ; python_version >= "3.10" and python_version < "4.0" nepattern==0.7.7 ; python_version >= "3.10" and python_version < "4.0"
nonebot-adapter-onebot==2.4.6 ; python_version >= "3.10" and python_version < "4.0" nonebot-adapter-onebot==2.4.6 ; python_version >= "3.10" and python_version < "4.0"
nonebot-plugin-alconna==0.54.1 ; python_version >= "3.10" and python_version < "4.0" nonebot-plugin-alconna==0.54.2 ; python_version >= "3.10" and python_version < "4.0"
nonebot-plugin-apscheduler==0.5.0 ; python_version >= "3.10" and python_version < "4.0" nonebot-plugin-apscheduler==0.5.0 ; python_version >= "3.10" and python_version < "4.0"
nonebot-plugin-htmlrender==0.3.5 ; python_version >= "3.10" and python_version < "4.0" nonebot-plugin-htmlrender==0.3.5 ; python_version >= "3.10" and python_version < "4.0"
nonebot-plugin-session==0.2.3 ; python_version >= "3.10" and python_version < "4.0" nonebot-plugin-session==0.2.3 ; python_version >= "3.10" and python_version < "4.0"
nonebot-plugin-uninfo==0.4.1 ; python_version >= "3.10" and python_version < "4.0" nonebot-plugin-uninfo==0.4.1 ; python_version >= "3.10" and python_version < "4.0"
nonebot-plugin-userinfo==0.1.3 ; python_version >= "3.10" and python_version < "4.0"
nonebot-plugin-waiter==0.8.0 ; python_version >= "3.10" and python_version < "4.0" nonebot-plugin-waiter==0.8.0 ; python_version >= "3.10" and python_version < "4.0"
nonebot2==2.4.0 ; python_version >= "3.10" and python_version < "4.0" nonebot2==2.4.1 ; python_version >= "3.10" and python_version < "4.0"
nonebot2[fastapi]==2.4.0 ; python_version >= "3.10" and python_version < "4.0" nonebot2[fastapi]==2.4.1 ; python_version >= "3.10" and python_version < "4.0"
noneprompt==0.1.9 ; python_version >= "3.10" and python_version < "4.0" noneprompt==0.1.9 ; python_version >= "3.10" and python_version < "4.0"
numpy==2.2.0 ; python_version >= "3.10" and python_version < "4.0" numpy==2.2.1 ; python_version >= "3.10" and python_version < "4.0"
pillow==10.4.0 ; python_version >= "3.10" and python_version < "4.0" pillow==10.4.0 ; python_version >= "3.10" and python_version < "4.0"
platformdirs==4.3.6 ; python_version >= "3.10" and python_version < "4.0" platformdirs==4.3.6 ; python_version >= "3.10" and python_version < "4.0"
playwright==1.49.1 ; python_version >= "3.10" and python_version < "4.0" playwright==1.49.1 ; python_version >= "3.10" and python_version < "4.0"
@ -76,12 +74,13 @@ psutil==5.9.8 ; python_version >= "3.10" and python_version < "4.0"
py-cpuinfo==9.0.0 ; python_version >= "3.10" and python_version < "4.0" py-cpuinfo==9.0.0 ; python_version >= "3.10" and python_version < "4.0"
pyasn1==0.6.1 ; python_version >= "3.10" and python_version < "4.0" pyasn1==0.6.1 ; python_version >= "3.10" and python_version < "4.0"
pycparser==2.22 ; python_version >= "3.10" and python_version < "4.0" and platform_python_implementation != "PyPy" pycparser==2.22 ; python_version >= "3.10" and python_version < "4.0" and platform_python_implementation != "PyPy"
pydantic==1.10.18 ; python_version >= "3.10" and python_version < "4.0" pydantic-core==2.27.2 ; python_version >= "3.10" and python_version < "4.0"
pydantic==2.10.4 ; python_version >= "3.10" and python_version < "4.0"
pyee==12.0.0 ; python_version >= "3.10" and python_version < "4.0" pyee==12.0.0 ; python_version >= "3.10" and python_version < "4.0"
pyfiglet==1.0.2 ; python_version >= "3.10" and python_version < "4.0" pyfiglet==1.0.2 ; python_version >= "3.10" and python_version < "4.0"
pygments==2.18.0 ; python_version >= "3.10" and python_version < "4.0" pygments==2.19.1 ; python_version >= "3.10" and python_version < "4.0"
pygtrie==2.5.0 ; python_version >= "3.10" and python_version < "4.0" pygtrie==2.5.0 ; python_version >= "3.10" and python_version < "4.0"
pymdown-extensions==10.12 ; python_version >= "3.10" and python_version < "4.0" pymdown-extensions==10.14 ; python_version >= "3.10" and python_version < "4.0"
pypika-tortoise==0.1.6 ; python_version >= "3.10" and python_version < "4.0" pypika-tortoise==0.1.6 ; python_version >= "3.10" and python_version < "4.0"
pypinyin==0.51.0 ; python_version >= "3.10" and python_version < "4" pypinyin==0.51.0 ; python_version >= "3.10" and python_version < "4"
python-dateutil==2.9.0.post0 ; python_version >= "3.10" and python_version < "4.0" python-dateutil==2.9.0.post0 ; python_version >= "3.10" and python_version < "4.0"
@ -100,9 +99,8 @@ rfc3986[idna2008]==1.5.0 ; python_version >= "3.10" and python_version < "4.0"
rich==13.9.4 ; python_version >= "3.10" and python_version < "4.0" rich==13.9.4 ; python_version >= "3.10" and python_version < "4.0"
rsa==4.9 ; python_version >= "3.10" and python_version < "4" rsa==4.9 ; python_version >= "3.10" and python_version < "4"
ruamel-yaml-clib==0.2.12 ; platform_python_implementation == "CPython" and python_version < "3.13" and python_version >= "3.10" ruamel-yaml-clib==0.2.12 ; platform_python_implementation == "CPython" and python_version < "3.13" and python_version >= "3.10"
ruamel-yaml==0.18.6 ; python_version >= "3.10" and python_version < "4.0" ruamel-yaml==0.18.10 ; python_version >= "3.10" and python_version < "4.0"
scipy==1.14.1 ; python_version >= "3.10" and python_version < "4.0" scipy==1.15.0 ; python_version >= "3.10" and python_version < "4.0"
setuptools==75.6.0 ; python_version >= "3.10" and python_version < "4.0"
sgmllib3k==1.0.0 ; python_version >= "3.10" and python_version < "4.0" sgmllib3k==1.0.0 ; python_version >= "3.10" and python_version < "4.0"
six==1.17.0 ; python_version >= "3.10" and python_version < "4.0" six==1.17.0 ; python_version >= "3.10" and python_version < "4.0"
sniffio==1.3.1 ; python_version >= "3.10" and python_version < "4.0" sniffio==1.3.1 ; python_version >= "3.10" and python_version < "4.0"
@ -113,16 +111,16 @@ tarina==0.6.8 ; python_version >= "3.10" and python_version < "4.0"
text-unidecode==1.3 ; python_version >= "3.10" and python_version < "4.0" text-unidecode==1.3 ; python_version >= "3.10" and python_version < "4.0"
tomli==2.2.1 ; python_version >= "3.10" and python_version < "3.11" tomli==2.2.1 ; python_version >= "3.10" and python_version < "3.11"
tomlkit==0.13.2 ; python_version >= "3.10" and python_version < "4.0" tomlkit==0.13.2 ; python_version >= "3.10" and python_version < "4.0"
tortoise-orm[asyncpg]==0.20.0 ; python_version >= "3.10" and python_version < "4.0" tortoise-orm[asyncpg]==0.20.1 ; python_version >= "3.10" and python_version < "4.0"
types-python-dateutil==2.9.0.20241206 ; python_version >= "3.10" and python_version < "4.0" types-python-dateutil==2.9.0.20241206 ; python_version >= "3.10" and python_version < "4.0"
typing-extensions==4.12.2 ; python_version >= "3.10" and python_version < "4.0" typing-extensions==4.12.2 ; python_version >= "3.10" and python_version < "4.0"
tzdata==2024.2 ; python_version >= "3.10" and python_version < "4.0" and platform_system == "Windows" tzdata==2024.2 ; python_version >= "3.10" and python_version < "4.0" and platform_system == "Windows"
tzlocal==5.2 ; python_version >= "3.10" and python_version < "4.0" tzlocal==5.2 ; python_version >= "3.10" and python_version < "4.0"
ujson==5.10.0 ; python_version >= "3.10" and python_version < "4.0" ujson==5.10.0 ; python_version >= "3.10" and python_version < "4.0"
urllib3==2.2.3 ; python_version >= "3.10" and python_version < "4.0" urllib3==2.3.0 ; python_version >= "3.10" and python_version < "4.0"
uvicorn[standard]==0.32.1 ; python_version >= "3.10" and python_version < "4.0" uvicorn[standard]==0.34.0 ; python_version >= "3.10" and python_version < "4.0"
uvloop==0.21.0 ; (sys_platform != "win32" and sys_platform != "cygwin") and platform_python_implementation != "PyPy" and python_version >= "3.10" and python_version < "4.0" uvloop==0.21.0 ; (sys_platform != "win32" and sys_platform != "cygwin") and platform_python_implementation != "PyPy" and python_version >= "3.10" and python_version < "4.0"
virtualenv==20.28.0 ; python_version >= "3.10" and python_version < "4.0" virtualenv==20.28.1 ; python_version >= "3.10" and python_version < "4.0"
watchfiles==0.24.0 ; python_version >= "3.10" and python_version < "4.0" watchfiles==0.24.0 ; python_version >= "3.10" and python_version < "4.0"
wcwidth==0.2.13 ; python_version >= "3.10" and python_version < "4.0" wcwidth==0.2.13 ; python_version >= "3.10" and python_version < "4.0"
websockets==14.1 ; python_version >= "3.10" and python_version < "4.0" websockets==14.1 ; python_version >= "3.10" and python_version < "4.0"

View File

@ -95,6 +95,8 @@ async def test_check(
) )
ctx.receive_event(bot=bot, event=event) ctx.receive_event(bot=bot, event=event)
ctx.should_ignore_rule(_self_check_matcher) ctx.should_ignore_rule(_self_check_matcher)
print("Template to pic call args:", mock_template_to_pic.call_args_list)
mock_template_to_pic.assert_awaited_once_with( mock_template_to_pic.assert_awaited_once_with(
template_path=str((mock_template_path_new / "check").absolute()), template_path=str((mock_template_path_new / "check").absolute()),
template_name="main.html", template_name="main.html",

View File

@ -7,8 +7,7 @@ from nonebot.params import Depends, RegexGroup
from nonebot.plugin import PluginMetadata from nonebot.plugin import PluginMetadata
from nonebot.rule import to_me from nonebot.rule import to_me
from nonebot_plugin_alconna import Alconna, Option, on_alconna, store_true from nonebot_plugin_alconna import Alconna, Option, on_alconna, store_true
from nonebot_plugin_session import EventSession from nonebot_plugin_uninfo import Uninfo
from nonebot_plugin_userinfo import EventUserInfo, UserInfo
from zhenxun.configs.config import BotConfig, Config from zhenxun.configs.config import BotConfig, Config
from zhenxun.configs.utils import PluginExtraData, RegisterConfig from zhenxun.configs.utils import PluginExtraData, RegisterConfig
@ -19,6 +18,7 @@ from zhenxun.services.log import logger
from zhenxun.utils.depends import UserName from zhenxun.utils.depends import UserName
from zhenxun.utils.enum import PluginType from zhenxun.utils.enum import PluginType
from zhenxun.utils.message import MessageUtils from zhenxun.utils.message import MessageUtils
from zhenxun.utils.platform import PlatformUtils
__plugin_meta__ = PluginMetadata( __plugin_meta__ = PluginMetadata(
name="昵称系统", name="昵称系统",
@ -119,7 +119,7 @@ def CheckNickname():
async def dependency( async def dependency(
bot: Bot, bot: Bot,
session: EventSession, session: Uninfo,
reg_group: tuple[Any, ...] = RegexGroup(), reg_group: tuple[Any, ...] = RegexGroup(),
): ):
black_word = Config.get_config("nickname", "BLACK_WORD") black_word = Config.get_config("nickname", "BLACK_WORD")
@ -129,7 +129,7 @@ def CheckNickname():
await MessageUtils.build_message("叫你空白?叫你虚空?叫你无名??").finish( await MessageUtils.build_message("叫你空白?叫你虚空?叫你无名??").finish(
at_sender=True at_sender=True
) )
if session.id1 in bot.config.superusers: if session.user.id in bot.config.superusers:
logger.debug( logger.debug(
f"超级用户设置昵称, 跳过合法检测: {name}", "昵称设置", session=session f"超级用户设置昵称, 跳过合法检测: {name}", "昵称设置", session=session
) )
@ -163,110 +163,106 @@ def CheckNickname():
@_nickname_matcher.handle(parameterless=[CheckNickname()]) @_nickname_matcher.handle(parameterless=[CheckNickname()])
async def _( async def _(
session: EventSession, session: Uninfo,
user_info: UserInfo = EventUserInfo(), uname: str = UserName(),
reg_group: tuple[Any, ...] = RegexGroup(), reg_group: tuple[Any, ...] = RegexGroup(),
): ):
if session.id1: (name,) = reg_group
(name,) = reg_group if len(name) < 5 and random.random() < 0.3:
if len(name) < 5 and random.random() < 0.3: name = "~".join(name)
name = "~".join(name) group_id = None
if gid := session.id3 or session.id2: if session.group:
await GroupInfoUser.set_user_nickname( group_id = session.group.parent.id if session.group.parent else session.group.id
session.id1, if group_id:
gid, await GroupInfoUser.set_user_nickname(
name, session.user.id,
user_info.user_displayname group_id,
or user_info.user_remark name,
or user_info.user_name, uname,
session.platform, PlatformUtils.get_platform(session),
)
logger.info(f"设置群昵称成功: {name}", "昵称设置", session=session)
else:
await FriendUser.set_user_nickname(
session.id1,
name,
user_info.user_displayname
or user_info.user_remark
or user_info.user_name,
session.platform,
)
logger.info(f"设置私聊昵称成功: {name}", "昵称设置", session=session)
await MessageUtils.build_message(random.choice(CALL_NAME).format(name)).finish(
reply_to=True
) )
await MessageUtils.build_message("用户id为空...").send() logger.info(f"设置群昵称成功: {name}", "昵称设置", session=session)
else:
await FriendUser.set_user_nickname(
session.user.id,
name,
uname,
PlatformUtils.get_platform(session),
)
logger.info(f"设置私聊昵称成功: {name}", "昵称设置", session=session)
await MessageUtils.build_message(random.choice(CALL_NAME).format(name)).finish(
reply_to=True
)
@_global_nickname_matcher.handle(parameterless=[CheckNickname()]) @_global_nickname_matcher.handle(parameterless=[CheckNickname()])
async def _( async def _(
session: EventSession, session: Uninfo,
nickname: str = UserName(), nickname: str = UserName(),
reg_group: tuple[Any, ...] = RegexGroup(), reg_group: tuple[Any, ...] = RegexGroup(),
): ):
if session.id1: (name,) = reg_group
(name,) = reg_group await FriendUser.set_user_nickname(
await FriendUser.set_user_nickname( session.user.id,
session.id1, name,
name, nickname,
nickname, PlatformUtils.get_platform(session),
session.platform, )
) await GroupInfoUser.filter(user_id=session.user.id).update(nickname=name)
await GroupInfoUser.filter(user_id=session.id1).update(nickname=name) logger.info(f"设置全局昵称成功: {name}", "设置全局昵称", session=session)
logger.info(f"设置全局昵称成功: {name}", "设置全局昵称", session=session) await MessageUtils.build_message(random.choice(CALL_NAME).format(name)).finish(
await MessageUtils.build_message(random.choice(CALL_NAME).format(name)).finish( reply_to=True
reply_to=True )
)
await MessageUtils.build_message("用户id为空...").send()
@_matcher.assign("name") @_matcher.assign("name")
async def _(session: EventSession, user_info: UserInfo = EventUserInfo()): async def _(session: Uninfo, uname: str = UserName()):
if session.id1: group_id = None
if gid := session.id3 or session.id2: if session.group:
nickname = await GroupInfoUser.get_user_nickname(session.id1, gid) group_id = session.group.parent.id if session.group.parent else session.group.id
card = user_info.user_displayname or user_info.user_name if group_id:
else: nickname = await GroupInfoUser.get_user_nickname(session.user.id, group_id)
nickname = await FriendUser.get_user_nickname(session.id1) card = uname
card = user_info.user_name else:
if nickname: nickname = await FriendUser.get_user_nickname(session.user.id)
await MessageUtils.build_message( card = uname
random.choice(REMIND).format(nickname) if nickname:
).finish(reply_to=True) await MessageUtils.build_message(random.choice(REMIND).format(nickname)).finish(
else: reply_to=True
await MessageUtils.build_message( )
random.choice( else:
[ await MessageUtils.build_message(
"没..没有昵称嘛,{}", random.choice(
"啊,你是{}啊,我想叫你的昵称!", [
"{}啊,有什么事吗?", "没..没有昵称嘛,{}",
"你是{}", "啊,你是{}啊,我想叫你的昵称!",
] "{}啊,有什么事吗?",
).format(card) "你是{}",
).finish(reply_to=True) ]
await MessageUtils.build_message("用户id为空...").send() ).format(card)
).finish(reply_to=True)
@_matcher.assign("cancel") @_matcher.assign("cancel")
async def _(bot: Bot, session: EventSession, user_info: UserInfo = EventUserInfo()): async def _(bot: Bot, session: Uninfo):
if session.id1: group_id = None
gid = session.id3 or session.id2 if session.group:
if gid: group_id = session.group.parent.id if session.group.parent else session.group.id
nickname = await GroupInfoUser.get_user_nickname(session.id1, gid) if group_id:
nickname = await GroupInfoUser.get_user_nickname(session.user.id, group_id)
else:
nickname = await FriendUser.get_user_nickname(session.user.id)
if nickname:
await MessageUtils.build_message(random.choice(CANCEL).format(nickname)).send(
reply_to=True
)
if group_id:
await GroupInfoUser.set_user_nickname(session.user.id, group_id, "")
else: else:
nickname = await FriendUser.get_user_nickname(session.id1) await FriendUser.set_user_nickname(session.user.id, "")
if nickname: await BanConsole.ban(session.user.id, group_id, 9, 60, bot.self_id)
await MessageUtils.build_message( return
random.choice(CANCEL).format(nickname) else:
).send(reply_to=True) await MessageUtils.build_message("你在做梦吗?你没有昵称啊").finish(
if gid: reply_to=True
await GroupInfoUser.set_user_nickname(session.id1, gid, "") )
else:
await FriendUser.set_user_nickname(session.id1, "")
await BanConsole.ban(session.id1, gid, 9, 60, bot.self_id)
return
else:
await MessageUtils.build_message("你在做梦吗?你没有昵称啊").finish(
reply_to=True
)
await MessageUtils.build_message("用户id为空...").send()

View File

@ -1,12 +1,18 @@
from datetime import datetime from datetime import datetime
from typing import Any, Generic, TypeVar from typing import Any, Generic, TypeVar
from pydantic import BaseModel, validator from nonebot.compat import PYDANTIC_V2
from pydantic import BaseModel
T = TypeVar("T") T = TypeVar("T")
RT = TypeVar("RT") RT = TypeVar("RT")
if PYDANTIC_V2:
from pydantic import field_validator as validator_decorator
else:
from pydantic import validator as validator_decorator
class User(BaseModel): class User(BaseModel):
username: str username: str
@ -61,13 +67,13 @@ class QueryModel(BaseModel, Generic[T]):
data: T | None = None data: T | None = None
"""携带数据""" """携带数据"""
@validator("index") @validator_decorator("index")
def index_validator(cls, index): def index_validator(cls, index):
if index < 1: if index < 1:
raise ValueError("查询下标小于1...") raise ValueError("查询下标小于1...")
return index return index
@validator("size") @validator_decorator("size")
def size_validator(cls, size): def size_validator(cls, size):
if size < 1: if size < 1:
raise ValueError("每页数量小于1...") raise ValueError("每页数量小于1...")

View File

@ -3,6 +3,5 @@ from nonebot import require
require("nonebot_plugin_apscheduler") require("nonebot_plugin_apscheduler")
require("nonebot_plugin_alconna") require("nonebot_plugin_alconna")
require("nonebot_plugin_session") require("nonebot_plugin_session")
require("nonebot_plugin_userinfo")
require("nonebot_plugin_htmlrender") require("nonebot_plugin_htmlrender")
require("nonebot_plugin_uninfo") require("nonebot_plugin_uninfo")