aboutsummaryrefslogtreecommitdiffstats
path: root/backend/models/discord_role.py
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2022-01-22 01:54:15 +0300
committerGravatar Hassan Abouelela <[email protected]>2022-01-22 01:54:15 +0300
commit3e786da5537cc243097b4bedb8e6b78ad1525f95 (patch)
treeeb5fc12d7cec3e4623a03483a33370fcd28559d1 /backend/models/discord_role.py
parentMerge pull request #132 from python-discord/anon-webhooks (diff)
Add Helper Functions For Managing Roles
Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'backend/models/discord_role.py')
-rw-r--r--backend/models/discord_role.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/backend/models/discord_role.py b/backend/models/discord_role.py
new file mode 100644
index 0000000..9f0b7dd
--- /dev/null
+++ b/backend/models/discord_role.py
@@ -0,0 +1,40 @@
+import typing
+
+from pydantic import BaseModel
+
+
+class RoleTags(BaseModel):
+ """Meta information about a discord role."""
+
+ bot_id: typing.Optional[str]
+ integration_id: typing.Optional[str]
+ premium_subscriber: bool
+
+ def __init__(self, **data: typing.Any):
+ """
+ Handle the terrible discord API.
+
+ Discord only returns the premium_subscriber field if it's true,
+ meaning the typical validation process wouldn't work.
+
+ We manually parse the raw data to determine if the field exists, and give it a useful
+ bool value.
+ """
+ data["premium_subscriber"] = "premium_subscriber" in data.keys()
+ super().__init__(**data)
+
+
+class DiscordRole(BaseModel):
+ """Schema model of Discord guild roles."""
+
+ id: str
+ name: str
+ color: int
+ hoist: bool
+ icon: typing.Optional[str]
+ unicode_emoji: typing.Optional[str]
+ position: int
+ permissions: str
+ managed: bool
+ mentionable: bool
+ tags: typing.Optional[RoleTags]