PythonistaGuild / TwitchIO

An Async Bot/API wrapper for Twitch made in Python.
https://twitchio.dev
MIT License
791 stars 163 forks source link

:) Parser eats all initial ":" characters in message text #310

Closed kamalmostafa closed 2 years ago

kamalmostafa commented 2 years ago

Inappropriate use of lstrip(":") in parse.py parser() munges any messages which actually do begin with ":" character(s) -- they're stripped off too.

Example input message text

:)

Yields output message text

)

Note also that every lstrip() call in parse.py is likewise inappropriate. They're all trying to remove "exactly one of a character", which is not what lstrip() does. Those other instances of lstrip() maybe won't manifest given normal protocol traffic. Maybe.

github-actions[bot] commented 2 years ago

Hello! Thanks for the issue. If this is a general help question, for a faster response consider joining the official Discord Server

Else if you have an issue with the library please wait for someone to help you here.

chillymosh commented 2 years ago

@kamalmostafa This PR has broken whisper parsing which will need to be addressed.

I believe I have a fix for this which I will probably push later today

kamalmostafa commented 2 years ago

Thank you for the follow-up fix @chillymosh (oops, sorry for the breakage)!

This looks like its probably okay... But the lstrip() is overzealous and would mis-parse channel names that actually do start with a '#', same as the original problem with stripping too many ':' characters. (That might not currently occur for Twitch IRC, but it's not unusual in "regular" IRC.)

-        channel = result.group("channel")
+        channel = result.group("channel").lstrip("#")

The goal is really to chop off exactly one '#' character, so how about this instead?:

+        channel = result.group("channel")[1:]

Thanks again, and also for TwitchIO :smiley:

chillymosh commented 2 years ago

channel = result.group("channel")[1:] would most likely work, whispers it would cut off the first letter but would not matter as it gets set to None now after, but channel names are usernames which are not allowed to contain any symbols other than an underscore (not start with), so starting with a # is not possible. Twitch uses a customised version of IRC v3 so bringing up "regular" IRC is not relevant as we will never connect to anything outside of Twitch.