Skip to content

Moved ChatInterface to mainWindow.py for better organization #106

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
44 changes: 41 additions & 3 deletions src/discord_objects.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from datetime import datetime
from typing import Self

import re

@dataclass
class DiscordUser:
Expand Down Expand Up @@ -108,6 +108,7 @@ class DiscordMessage:
author: DiscordUser
content: str
timestamp: datetime
message_type: str = 'text' #default

@classmethod
def from_dict(cls, message: dict) -> Self:
Expand All @@ -125,9 +126,45 @@ def from_dict(cls, message: dict) -> Self:
# content = message["content"]
# if content: ...

# TODO: WORK ON THIS. Make a difference between images and other stuff.
if not (content := message["content"]):
# # TODO: WORK ON THIS. Make a difference between images and other stuff.
# if not (content := message["content"]):
# content = "[(call/image/other)]"

content = message.get("content", "")
message_type = "text"

attachments = message.get("attachments", [])
embeds = message.get("embeds", [])
stickers = message.get("sticker_items", [])

# Check for image attachments
if attachments:
if any(att.get("content_type", "").startswith("image/") for att in attachments):
message_type = "image"
if not content:
content = "[Image Attachment]"
else:
message_type = "file"
if not content:
content = "[File Attachment]"
elif embeds:
message_type = "embed"
if not content:
content = "[Link Preview / Embed]"
elif stickers:
message_type = "sticker"
if not content:
content = "[Sticker]"
elif not content:
message_type = "other"
content = "[(call/image/other)]"
else:
url_pattern = re.compile(r'https?://\S+')
emoji_pattern = re.compile(r'^[\U00010000-\U0010ffff]+$', flags=re.UNICODE)
if emoji_pattern.match(content):
message_type = "emote"
elif url_pattern.search(content):
message_type = "link"

# For some reason, messages can use two, slightly different, timestamp formats.
time_str = message["timestamp"]
Expand All @@ -141,6 +178,7 @@ def from_dict(cls, message: dict) -> Self:
author=DiscordUser.from_dict(message["author"]),
content=content,
timestamp=timestamp.astimezone(),
message_type=message_type,
)


Expand Down
Loading