diff --git a/nonebot/adapters/discord/adapter.py b/nonebot/adapters/discord/adapter.py index b4012c9..74fae08 100644 --- a/nonebot/adapters/discord/adapter.py +++ b/nonebot/adapters/discord/adapter.py @@ -429,7 +429,7 @@ def get_authorization(bot_info: BotInfo) -> str: async def receive_payload(self, ws: WebSocket) -> Payload: data = await ws.receive() data = decompress_data(data, self.discord_config.discord_compress) - return type_validate_python(PayloadType, json.loads(data)) + return type_validate_python(PayloadType, json.loads(data)) # type: ignore @classmethod def payload_to_event(cls, payload: Dispatch) -> Event: diff --git a/nonebot/adapters/discord/api/handle.py b/nonebot/adapters/discord/api/handle.py index fbcdfc5..78cb305 100644 --- a/nonebot/adapters/discord/api/handle.py +++ b/nonebot/adapters/discord/api/handle.py @@ -2508,7 +2508,8 @@ async def _get_stage_instance( url=adapter.base_url / f"stage-instances/{channel_id}", ) return type_validate_python( - Optional[StageInstance], await _request(adapter, bot, request) + Optional[StageInstance], + await _request(adapter, bot, request), # type: ignore ) @@ -3300,4 +3301,4 @@ async def _get_current_authorization_information( "get_gateway_bot": _get_gateway_bot, "get_current_bot_application_information": _get_current_bot_application_information, "get_current_authorization_information": _get_current_authorization_information, -} +} # type: ignore diff --git a/nonebot/adapters/discord/api/model.py b/nonebot/adapters/discord/api/model.py index 9780d5e..2af8ba0 100644 --- a/nonebot/adapters/discord/api/model.py +++ b/nonebot/adapters/discord/api/model.py @@ -103,10 +103,10 @@ class Snowflake(int): @classmethod def __get_pydantic_core_schema__(cls, source, handler) -> CoreSchema: - return core_schema.with_info_plain_validator_function(cls.validate) + return core_schema.with_info_plain_validator_function(cls.validate) # type: ignore @classmethod - def validate(cls, value: Any, _): + def validate(cls, value: Any, _): # type: ignore if isinstance(value, str) and value.isdigit(): value = int(value) if not isinstance(value, int): diff --git a/nonebot/adapters/discord/commands/params.py b/nonebot/adapters/discord/commands/params.py index c3182fe..22b136d 100644 --- a/nonebot/adapters/discord/commands/params.py +++ b/nonebot/adapters/discord/commands/params.py @@ -38,7 +38,7 @@ def __init__(self, *args, key: str, **kwargs: Any) -> None: self.key = key def __repr__(self) -> str: - return f"OptionParam(key={self.extra['key']!r})" + return f"OptionParam(key={self.key!r})" @classmethod @override diff --git a/nonebot/adapters/discord/event.py b/nonebot/adapters/discord/event.py index 30f47ae..35c0014 100644 --- a/nonebot/adapters/discord/event.py +++ b/nonebot/adapters/discord/event.py @@ -1005,7 +1005,7 @@ class WebhooksUpdateEvent(NoticeEvent, WebhooksUpdate): EventType.VOICE_STATE_UPDATE.value: VoiceStateUpdateEvent, EventType.VOICE_SERVER_UPDATE.value: VoiceServerUpdateEvent, EventType.WEBHOOKS_UPDATE.value: WebhooksUpdateEvent, -} +} # type: ignore __all__ = [ "EventType", diff --git a/nonebot/adapters/discord/message.py b/nonebot/adapters/discord/message.py index 62ae179..816dc34 100644 --- a/nonebot/adapters/discord/message.py +++ b/nonebot/adapters/discord/message.py @@ -438,7 +438,7 @@ def from_guild_message(cls, message: MessageGet) -> "Message": if message.mention_everyone: msg.append(MessageSegment.mention_everyone()) if message.content: - msg.extend(Message(message.content)) + msg.append(MessageSegment.text(message.content)) if message.attachments: msg.extend( MessageSegment.attachment( diff --git a/nonebot/adapters/discord/payload.py b/nonebot/adapters/discord/payload.py index 6619f0e..bf6e452 100644 --- a/nonebot/adapters/discord/payload.py +++ b/nonebot/adapters/discord/payload.py @@ -1,5 +1,5 @@ from enum import IntEnum -from typing import TYPE_CHECKING, Any, Dict, Optional, Union +from typing import Optional, Union from typing_extensions import Annotated, Literal from nonebot.compat import PYDANTIC_V2, ConfigDict @@ -12,12 +12,6 @@ Resume as ResumeData, ) -if TYPE_CHECKING: - if PYDANTIC_V2: - from pydantic.main import IncEx - else: - from pydantic.typing import AbstractSetIntStr, DictStrAny, MappingIntStrAny - class Opcode(IntEnum): DISPATCH = 0 @@ -32,25 +26,7 @@ class Opcode(IntEnum): class Payload(BaseModel): if PYDANTIC_V2: - model_config = ConfigDict(extra="allow", populate_by_name=True) - - def model_dump( - self, - *, - include: "IncEx" = None, - exclude: "IncEx" = None, - exclude_unset: bool = False, - exclude_defaults: bool = False, - exclude_none: bool = False, - ) -> Dict[str, Any]: - return super().model_dump( - include=include, - exclude=exclude, - by_alias=True, - exclude_unset=exclude_unset, - exclude_defaults=exclude_defaults, - exclude_none=exclude_none, - ) + model_config = ConfigDict(extra="allow", populate_by_name=True) # type: ignore else: @@ -58,25 +34,6 @@ class Config(ConfigDict): extra = "allow" allow_population_by_field_name = True - def dict( - self, - *, - include: Union["AbstractSetIntStr", "MappingIntStrAny", None] = None, - exclude: Union["AbstractSetIntStr", "MappingIntStrAny", None] = None, - exclude_unset: bool = False, - exclude_defaults: bool = False, - exclude_none: bool = False, - **kwargs: Any, - ) -> "DictStrAny": - return super().dict( - include=include, - exclude=exclude, - by_alias=True, - exclude_unset=exclude_unset, - exclude_defaults=exclude_defaults, - exclude_none=exclude_none, - ) - class Dispatch(Payload): opcode: Literal[Opcode.DISPATCH] = Field(Opcode.DISPATCH, alias="op")