Ejemplo n.º 1
0
def command_delete(id):
    if Command.get(id=id).delete_instance():
        CommandAction.delete().where(CommandAction.command == id).execute()
        success(_("Command deleted."))
    else:
        danger(_("Error while deleting command."))
    return redirect(app.get_url('commands:list'))
Ejemplo n.º 2
0
def command_edit_post(id):
    command = Command.get(id=id)
    data = request.forms
    if ' ' in data['command']:
        danger(_("Spaces are not allowed in commands."))
        # TODO Redirect to the edit page
        return {
            'apis': get_apis(),
            'data': data,
        }
    with db.atomic():
        command.command = data['command']
        command.save()
        command.clear_actions()
        for i in range(int(data['actions_number'])):
            # Each action has actionX prepended to its inputs
            namespace = 'action{0}'.format(i)
            module, method = data['{0}_action_type'.format(namespace)].split('|')
            parameters = {
                key[len(namespace):]: value
                for key, value in data.items()
                if key.startswith(namespace) and not key.endswith('_action_type')
            }
            action = Action.create(module=module, method=method, parameters=json.dumps(parameters))
            CommandAction.create(command=command, action=action, order=i)
        success(_("Command edited."))
    return redirect(app.get_url('commands:list'))
Ejemplo n.º 3
0
def commands_add_post():
    data = request.forms
    with db.atomic():
        command = Command.create(command=data['command'])
        for i in range(int(data['actions_number'])):
            # Each action has actionX prepended to its inputs
            namespace = 'action{0}'.format(i)
            module, method = data['{0}_action_type'.format(namespace)].split('|')
            parameters = {
                key[len(namespace):]: value
                for key, value in data.items()
                if key.startswith(namespace) and not key.endswith('_action_type')
            }
            action = Action.create(module=module, method=method, parameters=json.dumps(parameters))
            CommandAction.create(command=command, action=action, order=i)
        success(_("Command created."))
    return redirect(app.get_url('commands:list'))
Ejemplo n.º 4
0
def handle_commands(response, client):
    """ handle custom commands """
    if response.command != 'PRIVMSG':
        return
    if response.data['command'] is None:
        return
    try:
        command = Command.get(command=response.data['command'])
    except Command.DoesNotExist:
        return
    for action in command.get_actions():
        info = get_action_info(action)
        parameters = json.loads(action.parameters)
        for parameter in info['parameters']:
            if parameter.name in [parameters.keys()]:
                value = parameters[parameter.name]
                parameters[parameter.name] = parameter.normalize(value)
        info['method'](client=client, **parameters)
Ejemplo n.º 5
0
def command_edit(id):
    command = Command.get(id=id)
    return {
        'apis': get_apis(),
        'command': command
    }
Ejemplo n.º 6
0
def commands_list():
    commands = Command.select()
    return {
        'commands': commands,
        'get_action_info': get_action_info,
    }
Ejemplo n.º 7
0
def command_delete(id):
    command = Command.get(id=id)
    return {'command': command}
Ejemplo n.º 8
0
def command_edit(id):
    command = Command.get(id=id)
    return {'command': command}