Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ChatInputInteraction alignment with real data given from discord! #52

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.4",
version="1.6.5",
author="Mohammad Amin Dadgar, RnDAO",
maintainer="Mohammad Amin Dadgar",
maintainer_email="[email protected]",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from datetime import datetime
from typing import Any

from .base_types.guild import Guild
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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"),
Expand All @@ -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"),
)
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_payload_discord_chat_input_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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