weidengeist / Willowbot

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

"sublevel" does not work #4

Closed LeoAlt8 closed 1 year ago

LeoAlt8 commented 2 years ago
commands = {
  "Hi" : {
    "answer" : "$senderDisplayName ***text0*** ",
    "cooldown"  : 30
  },

  "!sublvl" : {
    "answer" : "$senderDisplayName ***text1***",
    "sublevel" : 1
  },

  "!sublvl" : {
    "answer" : "$senderDisplayName ***text2***",
    "sublevel" : 2
  },

  "!sublvl" : {
    "answer" : "$senderDisplayName ***text3***",
    "sublevel" : 3
  },

  "!sublvl" : {
    "answer" : "$senderDisplayName ***text4***",
    "sublevel" : 4
  },

  "!sublvl" : {
    "answer" : "$senderDisplayName ***text5***",
    "sublevel" : 5
  }
}

A sub with 2 months writes the command !sublvl, but the bot writes $senderDisplayName text5 to the chat. But this is the answer for 5 months of sub. I left 1, 2 and 3 months, the bot began to answer $senderDisplayName text3. Tried various options. It turned out that the bot always sends text from the last command !sublvl, ignoring "sublevel" : xx

weidengeist commented 2 years ago

You are missing two important points here:

  1. Your spelling is incorrect. The key is not called sublevel, but subLevel, with capital L.
  2. Dictionaries in Python do not work like that. You are assigning the dictionary key !sublvl multiple times, i. e. you overwrite the former definition with each new instance of !sublvl. That’s why you only get the last reaction in your commands list called !sublvl. There is a link to a documentation about dictionaries in Python in the REAME file in section 3, second paragraph.

What you want to achieve isn’t a command the execution of which is restricted to a subscription level, but an answer that depends on the subscription level and differs accordingly. This can’t be done with Willowbot’s default design, but it can indeed be realized by writing a custom module as described in section 4 of the README. You write a module with the name, say, subLevelMsg and a function subLevelMsg_eval() within this module, where you do the actual differentiation, and link the !sublvl command to this function by setting the function key accordingly.

Regards, Weidengeist