Skip to content

Commit

Permalink
Fix validation for emoji_id and emoji_name in ForumTag model
Browse files Browse the repository at this point in the history
  • Loading branch information
vadim-su committed Dec 26, 2023
1 parent 6dfa7f5 commit 14b738d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions asyncord/client/models/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import enum
from datetime import datetime
from typing import Annotated, Any

from pydantic import BaseModel, Field, ValidationInfo, field_validator
from pydantic import BaseModel, Field, ValidationInfo, field_validator, model_validator

from asyncord.client.models.permissions import PermissionFlag
from asyncord.client.models.users import User
Expand Down Expand Up @@ -239,7 +240,7 @@ class Channel(BaseModel):
user_limit: int | None = None
"""User limit of the voice channel."""

rate_limit_per_user: int | None = Field(None, min=0, max=21600)
rate_limit_per_user: Annotated[int, Field(ge=0, le=21600)] | None = None
"""Amount of seconds a user has to wait before sending another message.
Should be between 0 and 21600.
Expand Down Expand Up @@ -381,8 +382,10 @@ class ForumTag(BaseModel):
emoji_name: str | None
"""Unicode character of the emoji."""

@field_validator('emoji_name')
def validate_emoji(cls, emoji_name: str | None, field_info: ValidationInfo) -> Snowflake | None:
"""Validate emoji_name and emoji_id fields."""
if emoji_name is not None and field_info.data['emoji_id'] is not None:
raise ValueError('emoji_name and emoji_id cannot be set at the same time')
@model_validator(mode='before')
def validate_emoji_id_or_name(cls, values: dict[str, Any]) -> dict[str, Any]:
"""Validate that only one of emoji_id and emoji_name is set."""
if 'emoji_id' in values and 'emoji_name' in values:
raise ValueError('At most one of emoji_id and emoji_name may be set.')

return values

0 comments on commit 14b738d

Please sign in to comment.