weidengeist / Willowbot

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

poll module error #13

Closed LeoAlt8 closed 7 hours ago

LeoAlt8 commented 4 days ago

Hello. When using the command:

  "!poll" : {
    'matchType' : 'startsWith',
    'debug'     : 'Poll has been started.',
    'function'  : ['poll_start(commands, irc, "$arg0+")'],
    "minLevel"  : 3
    },

I get errors:

Traceback (most recent call last):
  File "D:\Willowbot\main_cli.py", line 78, in <module>
    chatMsg.processCommands(commands, r, irc)
  File "D:\Willowbot\modules\message.py", line 394, in processCommands
    self.reactToMessage(commands, 'general', c, irc)
  File "D:\Willowbot\modules\message.py", line 292, in reactToMessage
    eval(func)
  File "<string>", line 1, in <module>
NameError: name 'p' is not defined

and

Traceback (most recent call last):
  File "D:\Willowbot\main_cli.py", line 74, in <module>
    checkTimedCommands(commands['timed'], irc)
  File "D:\Willowbot\modules\basics.py", line 310, in checkTimedCommands
    eval(reaction['function'])
  File "<string>", line 1, in <module>
NameError: name 'commands' is not defined. Did you mean: 'getCommands'?

Each error stops the bot from working. The poll starts up, but as soon as viewers start chatting, there's a bot error.

Commands are run from an account with the moderator role.

OS: Win11x64 Python: Python 3.11.3

weidengeist commented 4 days ago

The most recent change of the function key from a string to a list of strings has not been committed to the poll module. This has been fixed now and I have successfully tested the poll module functionality. Please provide feedback if it solves your problems.

Kind regards, Weidengeist

LeoAlt8 commented 4 days ago

When the voting time expires, it gives an error:

Traceback (most recent call last):
  File "D:\Willowbot\main_cli.py", line 74, in <module>
    checkTimedCommands(commands['timed'], irc)
  File "D:\Willowbot\modules\basics.py", line 310, in checkTimedCommands
    eval(reaction['function'])
TypeError: eval() arg 1 must be a string, bytes or code object
weidengeist commented 4 days ago

The fix needed here was a little more extensive than I thought. The polls should be fixed now.

Sorry for any inconvenience.

LeoAlt8 commented 4 days ago

I'm sorry, but I found another problem. The survey doesn't take into account the Cyrillic answer choices. And when the survey time expires, it shows 0% of all options.

It works in Latin now. 👍

LeoAlt8 commented 3 days ago

Found another bug. It looks like the bot stores the result of the previous poll and somehow inserts the variant into the new poll. Example: First poll - !poll 30 v1_1 v1_2 v1_3. The bot outputs the poll results. I run the second poll - !poll 30 v2_1 v2_2 v2_3. The bot gives an error:

Evaluating poll_stop(commands, poll_results, irc)
Traceback (most recent call last):
  File "D:\Willowbot\main_cli.py", line 74, in <module>
    checkTimedCommands(commands, irc)
  File "D:\Willowbot\modules\basics.py", line 312, in checkTimedCommands
    eval(f)
  File "<string>", line 1, in <module>
  File "D:\Willowbot\modules_opt\poll.py", line 71, in poll_stop
    del commands['general'][c]
        ~~~~~~~~~~~~~~~~~~~^^^
KeyError: 'v1_1'
weidengeist commented 3 days ago

The first problem – poll not registering Cyrillic input – is the result of Willowbot converting Cyrillic letters that look like Latin ones into their Latin counterparts, which has been implemented because scam bots tried to avoid automatic bans by pattern matching. This conversion, however, leads to issues when Willowbot is used in mainly Cyrillic context, so I made it optional. The documentation has been updated accordingly. In short, you have to add 'cyrillicToLatinConversion : False to your config file. It should then look like this:

config = {
  'botname'                   : '**********',
  'clientID'                  : e5kdpgd2bbnbj1u5gbjpzeq7vsgwup',
  'connectionRetries'         : 10,
  'disconnectCheckInterval'   : 10,
  'port'                      : 6697,
  'server'                    : 'irc.chat.twitch.tv',
  'cyrillicToLatinConversion' : False
}

This key will also be added automatically when configuring Willowbot (python main_cli.py --configure), but you certainly won’t want to run through this process for just adding one new key.

I have used your bug report as an opportunity to redesign the poll module. The bug you have encountered is fixed now; subsequentially initiated polls will no longer affect each other. Additionally, you may now provide custom output phrases for the !poll command without having to modify the module itself. Please see the updated README for details. Those changes are designed with backwards compatibility, i.e. your current commands won’t cause an error if you don’t use the module’s new capabilities.

LeoAlt8 commented 3 days ago

Yeah, it's working fine now. Special thanks for 'cyrillicToLatinConversion' : False. I just need to figure out how to format the description of the voting messages.

Thank you so much for the work you've done!

LeoAlt8 commented 3 days ago

One more suggestion. You can make it so that the bot does not turn off if a moderator enters a command incorrectly. For example, the moderator will write in the chat !poll v1_1 v1_2 v1_3 , and the bot will reply that the command is not correct.

Now it terminates with an error if you forget to specify the time:

Traceback (most recent call last):
  File "D:\Willowbot\main_cli.py", line 78, in <module>
    chatMsg.processCommands(commands, r, irc)
  File "D:\Willowbot\modules\message.py", line 395, in processCommands
    self.reactToMessage(commands, 'general', c, irc)
  File "D:\Willowbot\modules\message.py", line 292, in reactToMessage
    eval(func)
  File "<string>", line 1, in <module>
  File "D:\Willowbot\modules_opt\poll.py", line 18, in poll_start
    duration = int(poll_options[0])
               ^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'v1_1'
LeoAlt8 commented 3 days ago

I suggest making a default value so that if you don't specify a polling time, the default value is used.

weidengeist commented 2 days ago

I have committed a fix for that scenario, which will set the poll duration to 60 seconds if the first argument of !poll can’t be successfully converted to an integer.

Additionally, I have implemented the ability to cancel a poll. The usage of this feature is, of course, documented in the updated README.

LeoAlt8 commented 2 days ago
Traceback (most recent call last):
  File "D:\Willowbot-main\main_cli.py", line 78, in <module>
    chatMsg.processCommands(commands, r, irc)
  File "D:\Willowbot-main\modules\message.py", line 395, in processCommands
    self.reactToMessage(commands, 'general', c, irc)
  File "D:\Willowbot-main\modules\message.py", line 292, in reactToMessage
    eval(func)
  File "<string>", line 1
    poll_cancel(commands, irc, cancelMessage = "Votes no longer accepted. Poll has been cancelled."
               ^
SyntaxError: '(' was never closed

Please add to the command description closing brackets in README.md 'function' : ['poll_cancel(commands, irc, cancelMessage = "Votes no longer accepted. Poll has been cancelled.")'],

LeoAlt8 commented 2 days ago

The poll is working now. Thank you very much for your work!

LeoAlt8 commented 1 day ago

P.S. Here's an idea for an improvement. To make the answer variant consist of several words, separate the variants with a comma. For example, !poll 60 green apple, red apple, pineapple What do you think? Is it possible to realize it?

weidengeist commented 1 day ago

This command format would be counter-intuitive, because it does not match the way chat commands are usually designed, namely without comma, unless the comma is part of the argument, for example a quote that is added to a stream quote database. Furthermore, poll answers should be as short and as simple as possible to prevent typos and make it easy for the chat to participate. Adapted to the example you posted above, it would be !poll 60 green red pine instead.

So it’s a no, I‘m afraid. I’m not going to change the poll argument format, because it would break with the conventions.