weidengeist / Willowbot

A chat bot intended to be used on Twitch
GNU General Public License v3.0
4 stars 0 forks source link

Prime Sub Notification is broken #2

Closed Clasko closed 1 year ago

Clasko commented 1 year ago

Traceback:

Traceback (most recent call last):
File "/home/bot/Willowbot/main_cli.py", line 60, in <module>
    chatMsg.processCommands(commands, r, irc)
  File "/home/bot/Willowbot/modules/message.py", line 332, in processCommands
    self.reactToMessage(commands, 'sub', m, irc)
  File "/home/bot/Willowbot/modules/message.py", line 247, in reactToMessage
    answer = splitIntoGroupsOf(answer[0], 500)
  File "/home/bot/Willowbot/modules/basics.py", line 219, in splitIntoGroupsOf
    if re.match(".* $", first) or re.match("^ +", re.sub(first, "", s)) or first == s:
  File "/usr/local/lib/python3.10/re.py", line 209, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/usr/local/lib/python3.10/re.py", line 303, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/local/lib/python3.10/sre_compile.py", line 788, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/local/lib/python3.10/sre_parse.py", line 955, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/local/lib/python3.10/sre_parse.py", line 444, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/local/lib/python3.10/sre_parse.py", line 669, in _parse
    raise source.error("nothing to repeat",
re.error: nothing to repeat at position 0
weidengeist commented 1 year ago

Do you have any special characters in the answer string for your Prime Sub command definition which could be interpreted as special characters of a regex? If so, the source of error seems to be this part:

re.match("^ +", re.sub(first, "", s))

The second argument within the match would better be s.replace(first, "") to prevent misinterpretation of characters in the first variable.

I have changed that line in my local copy of the repository, will keep an eye on this issue, and update the repository after having confirmed the potential fix is working.

Clasko commented 1 year ago

I don't think so. The answer string is "The one and only @$subName kommt mit einem Prime Sub um die Ecke! DANKE <3"

weidengeist commented 1 year ago

I have now updated the repository with the fix mentioned above and can no longer reproduce the issue. Please get the most recent Willowbot version and check out if it works for you.

Clasko commented 1 year ago

Will do. Thank you. :)

weidengeist commented 1 year ago

I have added a debug mode for the bot (manual section 5 for further instructions) so you can test your command and see if the bot works for you without having to wait for a real Prime sub.

Clasko commented 1 year ago

Looks good to me:

image
weidengeist commented 1 year ago

Great. :-) I’ll leave the issue open anyway and wait for your confirmation that the command also works with the real chat messages, which I assume they do, as at least my tests under those circumstances worked well.