Python irc bot input
Question: ive been working on an irc bot and have run into a halt, i cant figure out how
to accept input for arguments for a function, specifically my function add(),
heres the function,

    
    
    def add(x1,x2):
        xtot = x1 + x2
        ircsock.send("PRIVMSG "+ channel + " :Toatal =  %s.\n" % (xtot))
    

and heres how its called

    
    
    if ircmsg.find('add.' + botnick) != -1:
        add()
    

i want to know how to attach input along side just running the function, as in
add.mybot 1,2 instead of just add.mybot


Answer: I don't know which library you are using, but I will suppose that ircmsg
contains the input (otherwise, replace ircmsg by ircmsg.line/ircmsg.input/…

    
    
    import re
    if ircmsg.find('add.' + botnick) != -1:  #you find a line with add.mybot
        try:
            (x,y) = [int(i) for i in re.match(".*\((.*),(.*)\).*",a).groups()] #we try to retrieve what we want
            add(x, y)
        except:
            pass # or some logs
    

However, I think that the conversion should not be done here but in your `add`
function (+ if you want to be able to add float for instance).

For instance:

    
    
    import re
    if ircmsg.find('add.' + botnick) != -1:  #you find a line with add.mybot
        try:
            (x,y) = re.match(".*\((.*),(.*)\).*",a).groups() #we try to retrieve what we want
            add(x, y)
        except:
            pass # or some logs
    

and

    
    
    def add(x1,x2):
        if x1.isdigit() and x2.isdigit():
            xtot = int(x1) + int(x2)
            ircsock.send("PRIVMSG "+ channel + " :Toatal =  %s.\n" % (xtot))
        else:
            try:
                xtot = float(x1) + float(x2)
                ircsock.send("PRIVMSG "+ channel + " :Toatal =  %s.\n" % (xtot))
            except:
                pass #or send the concatenation x1+x2
    

Hope I am not mistaken.

