Skip to content

Commit

Permalink
Render messages with /me(closes #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascdev committed Oct 12, 2023
1 parent e1c9a79 commit bb0d902
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Changes:
* Display error message when trying to send message without logging in(closes #16)
* Display error message when trying to send message without selecting a chat channel(closes #16)
* Show current selected channel on new message hint text

* Render messages with /me
5 changes: 4 additions & 1 deletion hasherino/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def add_control_elements(self, message):

for element in message.elements:
if type(element) == str:
result = ChatText(element, ft.colors.WHITE, self.font_size)
color = message.user.chat_color if message.me else ft.colors.WHITE
result = ChatText(element, color, self.font_size)
elif type(element) == Emote:
result = ChatEmote(
src=element.get_url(),
Expand Down Expand Up @@ -363,6 +364,7 @@ async def send_message_click(self, _):
for element in self.new_message.value.split(" ")
],
message_type="chat_message",
me=False,
)
)

Expand Down Expand Up @@ -522,6 +524,7 @@ async def message_received(self, message: ParsedMessage):
for element in message.get_message_text().split(" ")
],
message_type="chat_message",
me=True,
)
)
case _:
Expand Down
1 change: 1 addition & 0 deletions hasherino/hasherino_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ class Message:
user: User
elements: list[str | Emote]
message_type: str
me: bool
17 changes: 16 additions & 1 deletion hasherino/twitch_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,24 @@ def get_command(self) -> Command:

return result

def is_me(self) -> bool:
"""
Messages sent with /me, coloring the whole line with the user's chat color
"""
return (
self.get_command() is Command.PRIVMSG
and self.parameters[:7] == "\x01ACTION"
)

def get_message_text(self) -> str:
# Remove \r\n from end of text
return "" if len(self.parameters) <= 2 else self.parameters[:-2]
result = "" if len(self.parameters) <= 2 else self.parameters[:-2]

if self.is_me():
# parameters: '\x01ACTION asd\x01\r\n'
result = result[8:-1]

return result

def __str__(self) -> str:
return str(self.__dict__)
Expand Down

0 comments on commit bb0d902

Please sign in to comment.