Skip to content

Commit

Permalink
Merge branch 'master' into update-test-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
julien777z authored Feb 11, 2025
2 parents 4bc4b43 + e7f9366 commit b566cba
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
8 changes: 7 additions & 1 deletion bloxlink_lib/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,13 @@ async def update_item(domain: str, item_id: str, **aspects) -> None:

# update database
await mongo.bloxlink[domain].update_one(
{"_id": item_id}, {"$set": set_aspects, "$unset": unset_aspects}, upsert=True
{"_id": item_id},
{
"$set": set_aspects,
"$unset": unset_aspects,
"$currentDate": {"updatedAt": True},
},
upsert=True,
)


Expand Down
34 changes: 18 additions & 16 deletions bloxlink_lib/models/guilds.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Mapping, Self, Type, Literal, Annotated
from pydantic import Field, field_validator
import hikari
from datetime import datetime
from .base import PydanticList, BaseModel, PydanticDict, MemberSerializable
from ..validators import is_positive_number_as_str
from .migrators import migrate_restrictions
Expand Down Expand Up @@ -70,15 +70,8 @@ class GuildData(BaseModel):
"""Representation of the stored settings for a guild"""

id: Annotated[int, Field(alias="_id")]
binds: Annotated[list[binds_module.GuildBind], Field(default_factory=list)]

@field_validator("binds", mode="before")
@classmethod
def transform_binds(cls: Type[Self], binds: list) -> list[binds_module.GuildBind]:
if all(isinstance(b, binds_module.GuildBind) for b in binds):
return binds

return [binds_module.GuildBind(**b) for b in binds]
binds: Annotated[list[binds_module.GuildBind], Field(default_factory=list)]

verifiedRoleEnabled: bool = True
verifiedRoleName: str | None = "Verified" # deprecated
Expand Down Expand Up @@ -106,13 +99,6 @@ def transform_binds(cls: Type[Self], binds: list) -> list[binds_module.GuildBind

restrictions: PydanticList[GuildRestriction] = Field(default_factory=list)

@field_validator("restrictions", mode="before")
@classmethod
def transform_restrictions(
cls: Type[Self], restrictions: dict[str, dict[str, GuildRestriction]]
) -> list[GuildRestriction]:
return migrate_restrictions(restrictions)

webhooks: Webhooks = None

hasBot: bool = False
Expand All @@ -130,6 +116,22 @@ def transform_restrictions(
groupIDs: PydanticDict = None
migratedBindsToV4: bool = False

# field converters
@field_validator("binds", mode="before")
@classmethod
def transform_binds(cls: Type[Self], binds: list) -> list[binds_module.GuildBind]:
if all(isinstance(b, binds_module.GuildBind) for b in binds):
return binds

return [binds_module.GuildBind(**b) for b in binds]

@field_validator("restrictions", mode="before")
@classmethod
def transform_restrictions(
cls: Type[Self], restrictions: dict[str, dict[str, GuildRestriction]]
) -> list[GuildRestriction]:
return migrate_restrictions(restrictions)

def model_post_init(self, __context):
# merge verified roles into binds
if self.verifiedRole:
Expand Down
2 changes: 2 additions & 0 deletions bloxlink_lib/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class UserData(BaseModel):
"""

id: Annotated[int, Field(alias="_id")]
updatedAt: datetime

robloxID: str | None = None
robloxAccounts: dict = Field(
default_factory=lambda: {"accounts": [], "guilds": {}, "confirms": {}}
Expand Down

0 comments on commit b566cba

Please sign in to comment.