Exemple #1
0
def modules_view_post():
    if 'uninstall' in request.forms.keys():
        module = ModuleConfiguration.get(ModuleConfiguration.identifier == request.forms['uninstall'])
        if module.activated:
            danger(_('Module is activated.'))
        else:
            module.get_module().uninstall()
            success(_('Module uninstalled successfully.'))
    else:
        activated_modules = set([module.identifier for module in get_activated_modules()])
        deactivated_modules = set([module.identifier for module in get_deactivated_modules()])

        new_activated_modules = set(request.forms.keys())
        to_activate = new_activated_modules & deactivated_modules
        to_deactivate = activated_modules - new_activated_modules

        for identifier in to_activate:
            modules[identifier].activate()
        for identifier in to_deactivate:
            modules[identifier].deactivate()

        if to_activate or to_deactivate:
            success(_('Module changed successfully.'))
    return {
        'modules': modules,
    }
Exemple #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'))
Exemple #3
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'))
Exemple #4
0
def shop_add_item():
    name = request.forms['name']
    price = int(request.forms['price'])
    active = bool(request.forms.get('active', False))
    try:
        ShopItem.create(name=name, price=price, active=active)
        success(_("Item created successfully"))
    except:
        danger(_("Error while creating item."))
    return redirect(app.get_url('shop:items'))
Exemple #5
0
def bet_add_bet():
    question = request.forms['question']
    options = request.forms['options']
    initial_pot = int(request.forms['initial-pot'])
    try:
        min_amount = int(request.forms['min-amount'])
    except ValueError:
        min_amount = None
    try:
        max_amount = int(request.forms['max-amount'])
    except ValueError:
        max_amount = None
    try:
        bet = Bet.create(question=question, options=options, initial_pot=initial_pot,
                         min_amount=min_amount, max_amount=max_amount)
        app.irc_send(action="message", parameters="New bet! {0}".format(bet.question))
        for index, option in enumerate(bet.get_options(), start=1):
            app.irc_send(action="message", parameters="{0}. {1}".format(index, option))
        success(_("Bet created successfully"))
    except Exception as e:
        danger(_("Error while creating bet: {0}.").format(e))
    return redirect(app.get_url('bet:list'))
Exemple #6
0
def strawpoll_create():
    """ View to create a new post """
    if 'chart' in request.forms.keys():
        url = app.get_url('strawpoll:stream_detail', id=request.forms['poll_id'])
        return redirect("{0}?chart={1}".format(url, request.forms['chart']))
    url = API_URL
    data = {
        'title': request.forms['title'],
        'options': request.forms['options'].replace('\r', '').split('\n'),
        'multi': bool(request.forms.get('multi', False)),
        # 'dupcheck': 'disabled',
    }
    r = requests.post(url, data=json.dumps(data))
    if r.ok:
        data = r.json()
        poll = Strawpoll.create(id=data['id'], title=data['title'])
        if 'send_on_irc' in request.forms.keys():
            message = "{0} {1}".format(poll.title, poll.get_url())
            app.irc_send(action="message", parameters=message)
        success(_('Poll created successfully.'))
    else:
        danger(_('Error while creating poll: {0}'.format(r.json().get('errorMessage', 'Unknown'))))
    return redirect(app.get_url('strawpoll:list'))
Exemple #7
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'))
Exemple #8
0
import math

from utils.translations import fake_translation as _

LEVELS = [
    {
        "level": -3,
        "expMin": -999999,
        "name": _("Negative cheater ?"),
        "accuracy": 95,
        "reliability": 85,
        "bullets": 6,
        "magazines": 1
    },  # Beginner's luck
    {
        "level": -2,
        "expMin": -99999,
        "name": _("Duck Hugger ?"),
        "accuracy": 95,
        "reliability": 85,
        "bullets": 6,
        "magazines": 1
    },  # Beginner's luck
    {
        "level": -1,
        "expMin": -9999,
        "name": _("What are you doing ?"),
        "accuracy": 95,
        "reliability": 85,
        "bullets": 6,
        "magazines": 1
Exemple #9
0
""" Default methods accessible in the modules api. """
from utils.modules.parameters import CharParameter
from utils.translations import _


def send_message(client, message):
    client.send(message)


api = {
    'send_message': {
        'title': _('Send a message'),
        'method': send_message,
        'parameters': [
            CharParameter('message', title="Message"),
        ]
    },
}
Exemple #10
0
""" Default methods accessible in the modules api. """
from utils.modules.parameters import CharParameter
from utils.translations import _


def send_message(response, client, message):
    client.send(message)


api = {
    "send_message": {
        "title": _("Send a message"),
        "method": send_message,
        "parameters": [CharParameter("message", title="Message")],
    }
}