Implemented /event add

This commit is contained in:
2025-04-18 23:34:11 +02:00
parent fd44276021
commit ec733097ea
6 changed files with 298 additions and 24 deletions

View File

@@ -17,7 +17,7 @@ logger: Logger = get_logger(__name__)
class PycordGuild:
"""Dataclass of DB entry of a guild"""
__slots__ = ("_id", "id", "channel_id", "category_id")
__slots__ = ("_id", "id", "channel_id", "category_id", "timezone")
__short_name__ = "guild"
__collection__ = col_guilds
@@ -25,6 +25,7 @@ class PycordGuild:
id: int
channel_id: Optional[int]
category_id: Optional[int]
timezone: str
@classmethod
async def from_id(
@@ -83,7 +84,7 @@ class PycordGuild:
self._update_cache(cache)
logger.info("Set attribute '%s' of user %s to '%s'", key, self.id, value)
logger.info("Set attribute '%s' of guild %s to '%s'", key, self.id, value)
async def _remove(self, key: str, cache: Optional[Cache] = None) -> None:
"""Remove attribute data and save it into the database.
@@ -139,11 +140,12 @@ class PycordGuild:
"id": self.id,
"channel_id": self.channel_id,
"category_id": self.category_id,
"timezone": self.timezone,
}
@staticmethod
def get_defaults(guild_id: Optional[int] = None) -> Dict[str, Any]:
return {"id": guild_id, "channel_id": None, "category_id": None}
return {"id": guild_id, "channel_id": None, "category_id": None, "timezone": "UTC"}
@staticmethod
def get_default_value(key: str) -> Any:
@@ -162,17 +164,34 @@ class PycordGuild:
self._delete_cache(cache)
# TODO Add documentation
async def set_channel(self, channel_id: Optional[int] = None, cache: Optional[Cache] = None) -> None:
await self._set("channel_id", channel_id, cache)
def is_configured(self) -> bool:
return (
(self.id is not None)
and (self.channel_id is not None)
and (self.category_id is not None)
and (self.timezone is not None)
)
# TODO Add documentation
async def set_category(self, category_id: Optional[int] = None, cache: Optional[Cache] = None) -> None:
await self._set("category_id", category_id, cache)
async def set_channel(self, channel_id: Optional[int] = None, cache: Optional[Cache] = None) -> None:
await self._set("channel_id", channel_id, cache)
# TODO Add documentation
async def reset_channel(self, cache: Optional[Cache] = None) -> None:
await self._remove("channel_id", cache)
# TODO Add documentation
async def set_category(self, category_id: Optional[int] = None, cache: Optional[Cache] = None) -> None:
await self._set("category_id", category_id, cache)
# TODO Add documentation
async def reset_category(self, cache: Optional[Cache] = None) -> None:
await self._remove("category_id", cache)
# TODO Add documentation
async def set_timezone(self, timezone: str, cache: Optional[Cache] = None) -> None:
await self._set("timezone", timezone, cache)
# TODO Add documentation
async def reset_timezone(self, cache: Optional[Cache] = None) -> None:
await self._remove("timezone", cache)