Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit 3d66fd4

Browse files
author
DirectiveAthena
committed
Fix: Correct command catching
1 parent a76a59a commit 3d66fd4

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

src/AthenaTwitchBot/functions/twitch_message_constructors.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import annotations
66
from typing import Callable
77
from datetime import datetime
8+
import time
89

910
# Custom Library
1011
from AthenaColor import StyleNest, ForeNest, HEX
@@ -41,14 +42,14 @@ def _find_bot_only(content:list[str],message:str, bot_name:str) -> TwitchMessage
4142
"emotes": lambda tm, tag_value: setattr(tm, "emotes", tag_value),
4243
"first-msg": lambda tm, tag_value: setattr(tm, "first_msg", bool(tag_value)),
4344
"flags": lambda tm, tag_value: setattr(tm, "flags", tag_value),
44-
"id": lambda tm, tag_value: setattr(tm, "message_id", int(tag_value)),
45+
"id": lambda tm, tag_value: setattr(tm, "message_id", tag_value),
4546
"mod": lambda tm, tag_value: setattr(tm, "mod", bool(tag_value)),
4647
"room-id": lambda tm, tag_value: setattr(tm, "room_id", tag_value),
4748
"subscriber": lambda tm, tag_value: setattr(tm, "subscriber", bool(tag_value)),
48-
"tmi-sent-ts": lambda tm, tag_value: setattr(tm, "tmi_sent_ts", datetime.fromtimestamp(int(tag_value))),
49+
"tmi-sent-ts": lambda tm, tag_value: setattr(tm, "tmi_sent_ts", int(tag_value)),
4950
"turbo": lambda tm, tag_value: setattr(tm, "turbo", bool(tag_value)),
5051
"user-id": lambda tm, tag_value: setattr(tm, "user_id", int(tag_value)),
51-
"user-type": lambda tm, tag_value: setattr(tm, "user-type", tag_value),
52+
"user-type": lambda tm, tag_value: setattr(tm, "user_type", tag_value),
5253
}
5354

5455
# ----------------------------------------------------------------------------------------------------------------------
@@ -83,7 +84,7 @@ def twitch_message_constructor_tags(message_bytes:bytearray, bot_name:str) -> Tw
8384
message=message,
8485
message_type=irc_message,
8586
channel=channel,
86-
text=" ".join(text)
87+
text=" ".join(text).replace(":", "", 1) #only remove the first ":"
8788
)
8889

8990

src/AthenaTwitchBot/models/twitch_bot_protocol.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,15 @@ def data_received(self, data: bytearray) -> None:
5454
print(pong_message)
5555

5656
# catch a message which starts with a command:
57-
case TwitchMessage(message=[_,_,_,str(user_message),*user_message_other]) if user_message.startswith(f":{self.bot.prefix}"):
57+
case TwitchMessage(text=user_message) if user_message.startswith(f"{self.bot.prefix}"):
5858
user_message:str
5959
print(ForeNest.ForestGreen("COMMAND CAUGHT"))
6060
try:
61-
user_cmd = user_message.replace(f":{self.bot.prefix}", "")
62-
result = self.bot.commands[user_cmd](self=self.bot,transport=self.transport)
63-
print(result)
61+
user_cmd = user_message.replace(f"{self.bot.prefix}", "")
62+
self.bot.commands[user_cmd](self=self.bot,message=twitch_message,transport=self.transport)
6463
except KeyError:
6564
pass
6665

67-
# catch a message which has a command within it:
68-
case TwitchMessage(message=[_,_,_,*messages_parts]):
69-
for message in messages_parts:
70-
if message.startswith(self.bot.prefix):
71-
print(ForeNest.ForestGreen("COMMAND CAUGHT"))
72-
7366
def connection_lost(self, exc: Exception | None) -> None:
7467
self.main_loop.stop()
7568

src/AthenaTwitchBot/models/twitch_message.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ class TwitchMessage:
2828
color:HEX=field(default_factory=HEX)
2929
display_name:str=""
3030
first_msg:bool=False
31-
message_id:int=0
31+
message_id:str=""
3232
mod:bool=False
3333
room_id:str=""
3434
subscriber:bool=False
35-
tmi_sent_ts:datetime=field(default_factory=datetime.now)
35+
tmi_sent_ts:int=0
3636
turbo:bool=False
3737
user_id:int=0
3838
emotes:str=""
3939
flags:str=""
40+
user_type:str=""
4041
# ----------------------------------------------------------------------------------------------------------------------
4142
# - Special message types -
4243
# ----------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)