Skip to content

Commit

Permalink
Merge pull request #47 from TogetherCrew/fix-payload-schemas
Browse files Browse the repository at this point in the history
fix: field names updated with the real data!
  • Loading branch information
cyri113 authored Oct 24, 2023
2 parents 77e1f74 + 4cd8a81 commit 33609ea
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="tc-messageBroker",
version="1.6.1",
version="1.6.2",
author="Mohammad Amin Dadgar, RnDAO",
maintainer="Mohammad Amin Dadgar",
maintainer_email="[email protected]",
Expand Down
28 changes: 28 additions & 0 deletions tc_messageBroker/rabbit_mq/payload/discord_bot/base_types/guild.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Any


class Guild:
def __init__(
self,
Expand All @@ -9,6 +12,11 @@ def __init__(
shard_id: int | None = None,
splash: str | None = None,
banner: str | None = None,
channels: list[str] | None = None,
members: list[str] | None = None,
roles: list[str] | None = None,
commands: Any | None = None,
bans: Any | None = None,
description: str | None = None,
verification_level: int | None = None,
vanity_url_code: str | None = None,
Expand Down Expand Up @@ -46,6 +54,11 @@ def __init__(
self.icon = icon
self.features = features
self.available = available
self.members = members
self.channels = channels
self.roles = roles
self.commands = commands
self.bans = bans
self.shard_id = shard_id
self.splash = splash
self.banner = banner
Expand Down Expand Up @@ -92,6 +105,11 @@ def from_dict(cls, guild_dict: dict) -> "Guild":
name=guild_dict.get("name"),
icon=guild_dict.get("icon"),
features=guild_dict.get("features", []),
channels=guild_dict.get("channels"),
members=guild_dict.get("members"),
roles=guild_dict.get("roles"),
commands=guild_dict.get("commands"),
bans=guild_dict.get("bans"),
available=guild_dict.get("available"),
shard_id=guild_dict.get("shardId"),
splash=guild_dict.get("splash"),
Expand Down Expand Up @@ -232,5 +250,15 @@ def to_dict(self) -> dict:
data["safetyAlertsChannelId"] = self.safety_alerts_channel_id
if self.owner_id is not None:
data["ownerId"] = self.owner_id
if self.channels is not None:
data["channels"] = self.channels # type: ignore
if self.members is not None:
data["members"] = self.members # type: ignore
if self.roles is not None:
data["roles"] = self.roles # type: ignore
if self.commands is not None:
data["commands"] = self.commands
if self.bans is not None:
data["bans"] = self.bans

return data
32 changes: 16 additions & 16 deletions tc_messageBroker/rabbit_mq/payload/discord_bot/base_types/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ def from_dict(cls, data: dict) -> "User":
id=data["id"],
created_at=created_at,
client=data.get("client"),
default_avatar_url=data.get("default_avatar_url"),
default_avatar_url=data.get("defaultAvatarURL"),
partial=data.get("partial"),
created_timestamp=data.get("created_timestamp"),
created_timestamp=data.get("createdTimestamp"),
discriminator=data.get("discriminator"),
bot=data.get("bot"),
avatar=data.get("avatar"),
avatar_decoration=data.get("avatar_decoration"),
avatar_decoration=data.get("avatarDecoration"),
banner=data.get("banner"),
accent_color=data.get("accent_color"),
display_name=data.get("display_name"),
dm_channel=data.get("dm_channel"),
accent_color=data.get("accentColor"),
display_name=data.get("displayName"),
dm_channel=data.get("dmChannel"),
flags=data.get("flags"),
global_name=data.get("global_name"),
hex_accent_color=data.get("hex_accent_color"),
global_name=data.get("globalName"),
hex_accent_color=data.get("hexAccentColor"),
system=data.get("system"),
tag=data.get("tag"),
username=data.get("username"),
Expand All @@ -84,20 +84,20 @@ def to_dict(self) -> dict:
"id": self.id,
"created_at": created_at,
"client": self.client,
"default_avatar_url": self.default_avatar_url,
"defaultAvatarURL": self.default_avatar_url,
"partial": self.partial,
"created_timestamp": self.created_timestamp,
"createdTimestamp": self.created_timestamp,
"discriminator": self.discriminator,
"bot": self.bot,
"avatar": self.avatar,
"avatar_decoration": self.avatar_decoration,
"avatarDecoration": self.avatar_decoration,
"banner": self.banner,
"accent_color": self.accent_color,
"display_name": self.display_name,
"dm_channel": self.dm_channel,
"accentColor": self.accent_color,
"displayName": self.display_name,
"dmChannel": self.dm_channel,
"flags": self.flags,
"global_name": self.global_name,
"hex_accent_color": self.hex_accent_color,
"globalName": self.global_name,
"hexAccentColor": self.hex_accent_color,
"system": self.system,
"tag": self.tag,
"username": self.username,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datetime import datetime
from typing import Any

from .base_types.flags import PermissionsBitField
from .base_types.guild import Guild
from .base_types.user import User

Expand Down Expand Up @@ -33,8 +32,8 @@ def __init__(
command_id: str | None = None,
command_name: str | None = None,
command_type: dict | None = None,
command_guild_id: dict | None = None,
member_permissions: PermissionsBitField | None = None,
command_guild_id: str | None = None,
member_permissions: str | None = None,
options: dict | None = None,
version: int | None = None,
) -> None:
Expand Down Expand Up @@ -74,12 +73,10 @@ def __init__(
@classmethod
def from_dict(self, data: dict) -> "ChatInputCommandInteraction":
member_permissions = data.get("memberPermissions")
if member_permissions is not None:
member_permissions = PermissionsBitField.from_dict(member_permissions)

created_at = data.get("createdAt")
if created_at is not None:
created_at = datetime.fromisoformat(created_at)
created_at = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%S.%fZ")

guild = data.get("guild")
if guild is not None:
Expand Down

0 comments on commit 33609ea

Please sign in to comment.