Open eivl opened 1 year ago
Thanks for reporting the error and contributing to the project, much appreciated. I'll release a fix as soon as possible.
My pleasure.
badges = {badge.rstrip("/1") for badge in message.split("badges=")[1].split(";")[0].split(",")}
~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
another split issue.
i dont have the message that broke this. Adding it here.
I could try to rewrite the parser based on the RFC 1459 spec.
I'll be adjusting this as soon as possible. Apologies for the issues you're encountering.
no worries, im just glad i did not have to write my own socket and data parser from scratch :D
here is a message that failed in the parser.
m-id=56649026;subscriber=0;tmi-sent-ts=1696789151006;turbo=0;user-id=400074398;user-type= :faintsmlle!faintsmlle@faintsmlle.tmi.twitch.tv PRIVMSG #quin69 :guys stop saying shit about this being quins audio, this is much better
Im doing a full test to see if it breaks more places.
@classmethod
def parse(cls, message: str) -> "TwitchPrivateMessage":
"""
Parse a Twitch private message.
:param message: The message to parse.
"""
try:
badges = {badge.rstrip("/1") for badge in message.split("badges=")[1].split(";")[0].split(",")}
color = message.split("color=")[1].split(";")[0]
display_name = message.split("display-name=")[1].split(";")[0]
first_message = message.split("emotes=")[1].split(";")[0] == "-1"
message_id = message.split("id=")[1].split(";")[0]
mod = message.split("mod=")[1].split(";")[0] == "1"
broadcaster = "broadcaster" in badges
returning_chatter = message.split("room-id=")[1].split(";")[0] == "1"
room_id = int(message.split("room-id=")[1].split(";")[0])
subscriber = message.split("subscriber=")[1].split(";")[0] == "1"
turbo = message.split("turbo=")[1].split(";")[0] == "1"
user_id = int(message.split("user-id=")[1].split(";")[0])
name = message.split("PRIVMSG")[0].split("!")[-2].split(":")[1]
channel = message.split("PRIVMSG")[1].split(":")[0].strip().lstrip("#")
message = ":".join(message.split("PRIVMSG")[1].split(":")[1:]).strip()
except IndexError:
print()
print(message)
print()
return cls(
set(),
"",
"",
False,
"",
False,
False,
False,
0,
False,
False,
0,
"",
"",
"",
)
return cls(
badges,
color,
display_name,
first_message,
message_id,
mod,
broadcaster,
returning_chatter,
room_id,
subscriber,
turbo,
user_id,
name,
channel,
message,
)
I just wrap it in a try except and return an empty object back.
And here is another one that failed.
82a1-4d44-afc7-7acd1cbe1baa;mod=0;returning-chatter=0;room-id=56649026;subscriber=0;tmi-sent-ts=1696789889991;turbo=0;user-id=30278702;user-type= :anduinl!anduinl@anduinl.tmi.twitch.tv PRIVMSG #quin69 :Aware 2015
I ran this messages through a RFC 1459 tokenizer, and these lines still fails as it does not have the source. makes me think that twitch does not follow the IRC spec like I expect it to.
a97eba093e39423f9c4c2;color=#B22222;display-name=Khazerox;emotes=;first-msg=0;flags=0-3:P.3;id=9e48a829-3f4a-4bae-b9e2-7b30e9fc5acb;mod=0;returning-chatter=0;room-id=56649026;subscriber=1;tmi-sent-ts=1696790043418;turbo=0;user-id=58797167;user-type= :khazerox!khazerox@khazerox.tmi.twitch.tv PRIVMSG #quin69 :C***
and another one.
Should give you a few ideas how to troubleshoot I hope.
During testing, I found this error.
Here are a few details.
I was able to get the message string from a previous error from the same type as message as the one in the screenshot above.
testable example:
I don't know enough to talk about a solution, maybe indexing and splitting is not the right tool when the data is not predictable. and many selecting negative indexes would work.
name = message.split("PRIVMSG")[0].split("!")[-2].split(":")[1]
as an example for discussion.Since the results are unclear, regex may be the right tool for this.
eivl