From 7f4099d7cfa25a05f292c912d403f1ac26e240b0 Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Thu, 18 Jan 2024 09:59:22 +0330 Subject: [PATCH] fix: ChatInputInteraction alignment with real data given from discord! --- setup.py | 2 +- .../discord_bot/chat_input_interaction.py | 25 +++++++------------ ..._payload_discord_chat_input_interaction.py | 12 ++++----- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/setup.py b/setup.py index c327052..72f57a4 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="tc-messageBroker", - version="1.6.4", + version="1.6.5", author="Mohammad Amin Dadgar, RnDAO", maintainer="Mohammad Amin Dadgar", maintainer_email="dadgaramin96@gmail.com", diff --git a/tc_messageBroker/rabbit_mq/payload/discord_bot/chat_input_interaction.py b/tc_messageBroker/rabbit_mq/payload/discord_bot/chat_input_interaction.py index 3634981..99d475b 100644 --- a/tc_messageBroker/rabbit_mq/payload/discord_bot/chat_input_interaction.py +++ b/tc_messageBroker/rabbit_mq/payload/discord_bot/chat_input_interaction.py @@ -1,4 +1,3 @@ -from datetime import datetime from typing import Any from .base_types.guild import Guild @@ -11,29 +10,29 @@ def __init__( id: str, application_id: int | None = None, type: int | None = None, + guild_id: str | None = None, + guild: Guild | None = None, channel: dict | None = None, channel_id: str | None = None, token: str | None = None, - guild_id: str | None = None, user: User | None = None, - created_at: datetime | None = None, + created_at: Any | None = None, deffered: bool | None = None, replied: bool | None = None, webhook: dict | None = None, member: dict | None = None, ephemeral: bool | None = None, - guild: Guild | None = None, created_time_stamp: int | None = None, - app_permissions: str | None = None, + app_permissions: dict | None = None, + member_permissions: dict | None = None, locale: str | None = None, guild_locale: str | None = None, client: dict | None = None, command: dict | None = None, command_id: str | None = None, command_name: str | None = None, - command_type: dict | None = None, + command_type: int | None = None, command_guild_id: str | None = None, - member_permissions: str | None = None, options: dict | None = None, version: int | None = None, ) -> None: @@ -72,12 +71,6 @@ def __init__( @classmethod def from_dict(self, data: dict) -> "ChatInputCommandInteraction": - member_permissions = data.get("memberPermissions") - - created_at = data.get("createdAt") - if created_at is not None: - created_at = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%S.%fZ") - guild = data.get("guild") if guild is not None: guild = Guild.from_dict(guild) @@ -95,7 +88,7 @@ def from_dict(self, data: dict) -> "ChatInputCommandInteraction": token=data.get("token"), guild_id=data.get("guildId"), user=user, - created_at=created_at, + created_at=data.get("createdAt"), deffered=data.get("deferred"), replied=data.get("replied"), webhook=data.get("webhook"), @@ -112,7 +105,7 @@ def from_dict(self, data: dict) -> "ChatInputCommandInteraction": command_name=data.get("commandName"), command_type=data.get("commandType"), command_guild_id=data.get("commandGuildId"), - member_permissions=member_permissions, + member_permissions=data.get("memberPermissions"), options=data.get("options"), version=data.get("version"), ) @@ -142,7 +135,7 @@ def to_dict(self) -> dict[str, Any]: if self.user is not None: data["user"] = self.user.to_dict() if self.created_at is not None: - data["createdAt"] = self.created_at.isoformat() + data["createdAt"] = self.created_at if self.member is not None: data["member"] = self.member if self.ephemeral is not None: diff --git a/tests/unit/test_payload_discord_chat_input_interaction.py b/tests/unit/test_payload_discord_chat_input_interaction.py index 888f596..35ee1e6 100644 --- a/tests/unit/test_payload_discord_chat_input_interaction.py +++ b/tests/unit/test_payload_discord_chat_input_interaction.py @@ -165,14 +165,14 @@ def test_team_member_all_inputs_filled(): member={"sample": "membersample"}, ephemeral=True, created_time_stamp=time.timestamp(), - app_permissions="permission #1", + app_permissions={"bitfield": "permission #1"}, locale="En", guild_locale="en", client={"sampleClient": "erfa"}, command={"ping": "pong"}, command_name={"ping_name": "pong_name"}, - command_type={"command_type": "type"}, - command_guild_id={"AI guys": "1232"}, + command_type=626262626, + command_guild_id="1234", member_permissions={"permission": "101"}, options={"sample": {"one": "1"}}, version=1, @@ -194,14 +194,14 @@ def test_team_member_all_inputs_filled(): assert ch_interaction.member == {"sample": "membersample"} assert ch_interaction.ephemeral is True assert ch_interaction.created_time_stamp == time.timestamp() - assert ch_interaction.app_permissions == "permission #1" + assert ch_interaction.app_permissions == {"bitfield": "permission #1"} assert ch_interaction.locale == "En" assert ch_interaction.guild_locale == "en" assert ch_interaction.client == {"sampleClient": "erfa"} assert ch_interaction.command == {"ping": "pong"} assert ch_interaction.command_name == {"ping_name": "pong_name"} - assert ch_interaction.command_type == {"command_type": "type"} - assert ch_interaction.command_guild_id == {"AI guys": "1232"} + assert ch_interaction.command_type == 626262626 + assert ch_interaction.command_guild_id == "1234" assert ch_interaction.member_permissions == {"permission": "101"} assert ch_interaction.options == {"sample": {"one": "1"}} assert ch_interaction.version == 1