Beispiel #1
0
def command_addfunc(interface, hook, args):
    """~addfunc name:code - Adds or updates a dynamic function"""
    func = args.partition(" ")
    name = func[0].strip().lower()
    line = func[2].strip()
    try:
        dynamic_core.parse_markup(line)
    except dynamic_core.ParseError as e:
        interface.reply(str(e))
        return

    version = add_command(name, line, interface.user_address)
    if version == 0:
        interface.reply("Failed to add command %s" % name)
    elif version == 1:
        interface.reply("Command %s added successfully." % name)
    else:
        interface.reply("Command %s updated to version %u" % (name, version))
Beispiel #2
0
def do_event(interfacename,eventname,dt):
    d = data.query('SELECT text, recurrence, datetime FROM schedule WHERE interface = ? AND name = ?',(interfacename,eventname))[0]
    dt = datetime.strptime(d[2],'%Y-%m-%d %H:%M:%S')
    rec = d[1]
    if rec=='':
        data.query('DELETE FROM schedule WHERE interface = ? and name = ?',(interfacename,eventname))
    else:
        dt = increment_datetime(dt,rec)
        data.query('UPDATE schedule SET datetime = ? WHERE interface = ? and name = ?',(dt.isoformat(' '),interfacename,eventname))
    
    try:
        i = modules.Interface.interfaces[interfacename]
    except:
        print "Alarm triggered for non-existing interface %s."%interfacename
        return

    context = dynamic_core.TagContext(i=i,args=d[2])
    message = dynamic_core.parse_markup(d[0]).process(context)
    i.reply("AlarmBot: "+message)
Beispiel #3
0
def command_runfunc(interface, hook, args):
    # logging.info("Running dynamic function %s"%hook.hook)
    context = dynamic_core.TagContext(i=interface, args=args, command=hook.hook)
    interface.reply(dynamic_core.parse_markup(hook.data).process(context))