0

First of all sorry for my bad english, I am from Germany and currently learning english so please don't be harsh to me.

Now my question is, is there a way to execute a response by a bot on an equation, that turns out correct /equal. So in like an if-else statement

Kami
  • 19,134
  • 4
  • 51
  • 63
memeToasty
  • 21
  • 2
  • 4

1 Answers1

0

UPDATE - After writing the original answer below, I realized that regular commands would be able to handle many cases if there were a suitable parameter, like $if('expr', 'true-response', 'false-response'). So I wrote one. You can find it at https://github.com/madelsberger/if_StreamlabsParameter

The parameter is itself implemented in a Python script, so you'd still have to set your bot up to use Python scripts. But then if you install this parameter script, you can use it in regular commands instead of implementing each command with yet more custom scripting.

Note that this script is not approved by the Streamlabs Chatbot support (nor am I familiar with a procedure for submitting it to be approved); and I provide it under the MIT license (i.e. "AS IS"). It should work fine, and you're free to review the code to verify I haven't done anything malicious. I'll try to make a reasonable effort to answer reasonable questions as time permits.


So what you want is for the user to issue a command, and then the bot does a calculation; if a particular equation is satisfied, it sends a particular response, and if the equation is not satisfied it sends a different response (or just doesn't send); is that right?

I don't think basic commands (i.e. the Commands tab) can do this. You can do it with custom scripting. The script you need may not be very complicated, but you would need to install Python 2.7.13 and write a little Python code that satisfies the requirements for a Streamlabs Chatbot script.

As a very basic example, say we want to create a "guess my number" game, and when someone guesses it says "Correct" if the guess is correct.

In your chatbot's .../Services/Scripts directory you would create a subdirectory for your script (lets call it guess, and in that folder you would create guess_StreamlabsSystem.py as follows

# chatbot won't load a script that doesn't define these variables
ScriptName = "guess"
Website = None
Description = "number guessing game"
Creator = "madelsberger" # or for a script you write, your name here
Version = "1.0.0"

# global data used by the script
correctNumber = None

# called when your script starts up
def Init():
    global correctNumber
    correctNumber = Parent.GetRandom(1, 11)

# called whenever the chatbot has data - chat messages, whispers, etc. - that
# your script might care about
def Execute(data):
    global correctNumber
    if data.IsChatMessage() and data.GetParam(0).lower() == '!guess':
        try: # avoid problems if a non-numeric guess is given
            if int(data.GetParam(1)) == correctNumber:
                Parent.SendTwitchMessage("@" + data.User
                                             + " guessed correctly!")
                correctNumber = Parent.GetRandom(1, 11)
            else:
                Parent.SendTwitchMessage(data.GetParam(1) + " is not correct")
        except:
            pass

# called frequently to mark the passage of time; if there's some condition
# your bot wants to act on *other* than data from the bot, and if you can
# write code that watches for that condition, it can go here; but beware this
# gets run frequently, so if the check is resource-intensive then you don't
# want to run it on *every* tick
def Tick():
    pass

Note that in practice you might want to add cooldown controls, or permission controls. Your code can see an object called Parent which provides methods to handle these things. You also might want things like the trigger command to be configurable; you can set that up using a UI_Config.json file. See the chatbot docs for more details on scripting. https://cdn.streamlabs.com/chatbot/Documentation.pdf

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52