Skip to content

Commit

Permalink
update dependencies (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
MeetWq authored Aug 3, 2024
1 parent 813c5aa commit 17d37a7
Show file tree
Hide file tree
Showing 10 changed files with 409 additions and 373 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false
env:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ _✨ [Nonebot2](https://github.com/nonebot/nonebot2) 用户信息获取插件

<p align="center">
<img src="https://img.shields.io/github/license/noneplugin/nonebot-plugin-userinfo" alt="license">
<img src="https://img.shields.io/badge/python-3.8+-blue.svg" alt="Python">
<img src="https://img.shields.io/badge/nonebot-2.0.0+-red.svg" alt="NoneBot">
<img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="Python">
<img src="https://img.shields.io/badge/nonebot-2.3.0+-red.svg" alt="NoneBot">
<a href="https://pypi.org/project/nonebot-plugin-userinfo">
<img src="https://badgen.net/pypi/v/nonebot-plugin-userinfo" alt="pypi">
</a>
Expand Down
15 changes: 11 additions & 4 deletions nonebot_plugin_userinfo/adapters/satori.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@ async def _get_info(self, user_id: str) -> Optional[UserInfo]:
user = member.user

if user:
member_name = member.name if member else None
member_nick = member.nick if member else None
user_name = user.name or user.nick or member_name or member_nick or ""
user_name = user.name or user.nick or member_nick or ""

avatar = None
if user.avatar:
avatar = ImageUrl(url=user.avatar)
elif member and member.avatar:
avatar = ImageUrl(url=member.avatar)
else:
if self.event.platform == "chronocat" and check_qq_number(user_id):
if self.event.platform in (
"onebot",
"red",
"chronocat",
) and check_qq_number(user_id):
avatar = QQAvatar(qq=int(user_id))

return UserInfo(
Expand All @@ -68,7 +71,11 @@ async def _get_info(self, user_id: str) -> Optional[UserInfo]:
user_avatar=avatar,
)

if self.event.platform == "chronocat" and check_qq_number(user_id):
if self.event.platform in (
"onebot",
"red",
"chronocat",
) and check_qq_number(user_id):
return UserInfo(
user_id=user_id,
user_name="",
Expand Down
14 changes: 7 additions & 7 deletions nonebot_plugin_userinfo/getter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Generic, List, NamedTuple, Optional, Type, TypeVar
from typing import Generic, NamedTuple, Optional, TypeVar

from cachetools import TTLCache
from nonebot.adapters import Bot, Event
Expand Down Expand Up @@ -40,16 +40,16 @@ async def get_info(


class UserInfoGetterTuple(NamedTuple):
bot: Type[Bot]
event: Type[Event]
getter: Type[UserInfoGetter]
bot: type[Bot]
event: type[Event]
getter: type[UserInfoGetter]


_user_info_getters: List[UserInfoGetterTuple] = []
_user_info_getters: list[UserInfoGetterTuple] = []


def register_user_info_getter(bot: Type[Bot], event: Type[Event]):
def wrapper(getter: Type[UserInfoGetter]):
def register_user_info_getter(bot: type[Bot], event: type[Event]):
def wrapper(getter: type[UserInfoGetter]):
_user_info_getters.append(UserInfoGetterTuple(bot, event, getter))
return getter

Expand Down
24 changes: 18 additions & 6 deletions nonebot_plugin_userinfo/image_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import anyio
import emoji
from pydantic import BaseModel, validator
from nonebot.compat import PYDANTIC_V2
from pydantic import BaseModel
from strenum import StrEnum

from .utils import download_url
Expand Down Expand Up @@ -41,11 +42,22 @@ class EmojiStyle(StrEnum):
class Emoji(ImageSource):
data: str

@validator("data")
def check_emoji(cls, value: str) -> str:
if not emoji.is_emoji(value):
raise ValueError("Not a emoji")
return value
if PYDANTIC_V2:
from pydantic import field_validator

@field_validator("data")
def check_emoji(cls, value: str) -> str:
if not emoji.is_emoji(value):
raise ValueError("Not a emoji")
return value
else:
from pydantic import validator

@validator("data")
def check_emoji(cls, value: str) -> str:
if not emoji.is_emoji(value):
raise ValueError("Not a emoji")
return value

async def get_image(self, style: EmojiStyle = EmojiStyle.Apple) -> bytes:
url = f"https://emojicdn.elk.sh/{self.data}?style={style}"
Expand Down
Loading

0 comments on commit 17d37a7

Please sign in to comment.