Example #1
0
def exec_commands_ircbot_parsemsg_hook(config, log, irc, poll_result):
    """
    Parse the result of irc.poll() and execute commands if the msg was
    a command.
    
    """

    (from_nick, from_chan, msg, dest) = poll_result

    # its a command,
    if not re.match('^\.[A-z]', msg):
        log.debug('msg did not start with a .command... skipping')
        return

    args = msg.split()
    cmd = args.pop(0)  # first part of msg is command, rest args
    if cmd in irc_commands.keys():
        # need to keep arg order
        args.insert(0, irc_commands[cmd]['func'])
        if irc_commands[cmd]['namespace'] != 'root':
            args.insert(0, irc_commands[cmd]['namespace'])
        args.insert(0, 'ius-tools')

        try:
            # FIX ME: this is a bit of a hack
            nam = namespaces[irc_commands[cmd]['namespace']]
            nam.controller.cli_opts = None
            nam.controller.cli_args = None
            namespaces[irc_commands[cmd]['namespace']] = nam
            (out_dict, out_txt) = simulate(args)
            reply = out_dict['irc_data']
        except IUSToolsArgumentError, e:
            reply = e.msg
            out_dict = {}

        # FIX ME: Need to consolidate all this .startswith('#') stuff

        # only send to user directly?
        if out_dict.has_key('irc_pm') and out_dict['irc_pm']:
            if dest.startswith('#'):
                irc.send(from_chan, "%s: check your PM." % from_nick)
                irc.send(from_nick, "%s" % reply)
            else:
                irc.send(from_nick, "%s" % reply)
        else:
            if dest.startswith('#'):
                irc.send(dest, "%s: %s" % (from_nick, reply))
            else:
                irc.send(dest, "%s" % reply)
Example #2
0
def exec_commands_ircbot_parsemsg_hook(config, log, irc, poll_result):
    """
    Parse the result of irc.poll() and execute commands if the msg was
    a command.
    
    """
    
    (from_nick, from_chan, msg, dest) = poll_result
    
    # its a command, 
    if not re.match('^\.[A-z]', msg):
        log.debug('msg did not start with a .command... skipping')
        return
    
    args = msg.split() 
    cmd = args.pop(0) # first part of msg is command, rest args
    if cmd in irc_commands.keys():            
        # need to keep arg order
        args.insert(0, irc_commands[cmd]['func'])
        if irc_commands[cmd]['namespace'] != 'root':
            args.insert(0, irc_commands[cmd]['namespace'])    
        args.insert(0, 'ius-tools')
    
        try:
            # FIX ME: this is a bit of a hack
            nam = namespaces[irc_commands[cmd]['namespace']]
            nam.controller.cli_opts = None
            nam.controller.cli_args = None
            namespaces[irc_commands[cmd]['namespace']] = nam
            (out_dict, out_txt) = simulate(args)
            reply = out_dict['irc_data']
        except IUSToolsArgumentError, e:
            reply = e.msg
            out_dict = {}
            
        # FIX ME: Need to consolidate all this .startswith('#') stuff
        
        # only send to user directly?
        if out_dict.has_key('irc_pm') and out_dict['irc_pm']:    
            if dest.startswith('#'):
                irc.send(from_chan, "%s: check your PM." % from_nick)
                irc.send(from_nick, "%s" % reply)
            else:
                irc.send(from_nick, "%s" % reply)
        else:
            if dest.startswith('#'):
                irc.send(dest, "%s: %s" % (from_nick, reply))
            else:
                irc.send(dest, "%s" % reply)
Example #3
0
 def available_commands(self):
     for c in irc_commands.keys():
         print c
     irc_data = "Available Commands: %s" % ' '.join(irc_commands.keys())
     return dict(irc_pm=True, irc_data=irc_data)