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'))
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'))
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)
def command_edit(id): command = Command.get(id=id) return { 'apis': get_apis(), 'command': command }
def command_delete(id): command = Command.get(id=id) return {'command': command}
def command_edit(id): command = Command.get(id=id) return {'command': command}