Esempio n. 1
0
def clear_doomsign(message, lang):
    key, content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)

    if char_info[PLAYBOOK] != DOOMED:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_playbook')(
            get_translation(lang, f'playbooks.inverted_names.{DOOMED}'))

    doomsign_og = get_args_from_content(content)

    doomsign = get_translation(
        lang, f'playbooks.doomed.doomsigns.accessors.{doomsign_og}')
    if not doomsign:
        return get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.invalid_doomsign')(doomsign_og)

    char_doomsign = char_info[DOOMSIGNS][doomsign]
    if not char_doomsign:
        return get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.doomsign_not_marked')(doomsign_og)

    char_doomsign = True
    upload_to_s3(char_info, key, s3_client)
    return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.successfull_update')
Esempio n. 2
0
def add_move_from_your_playbook(message, lang):
    key, content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)

    if not char_info:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_character')

    move_name = get_args_from_content(content)

    moves_array = get_moves_json_array(lang)[MOVES]
    move_list = filter_moves_by_name(move_name, moves_array)

    if not len(move_list):
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_moves_pb')

    id = move_list[0][ID]

    move = list(filter(lambda dic: dic[ID] == id, char_info[MOVES]))[0]

    if move[PICKED]:
        return get_translation(lang,
                               f'{PLAYBOOK_INTERACTIONS}.move_already_taken')

    char_info[PENDING_ADVANCEMENTS] = char_info[PENDING_ADVANCEMENTS] - 1
    move[PICKED] = True
    upload_to_s3(char_info, key, s3_client)

    return get_translation(
        lang, f'{PLAYBOOK_INTERACTIONS}.successfully_added_move')(move_name)
Esempio n. 3
0
def invert_condition(message, compare_to, lang):
    key, content = get_key_and_content_from_message(message)
    condition_name_og = get_args_from_content(content)
    condition_name = get_translation(lang, f'inverted_conditions.{condition_name_og}')

    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)
    if not char_info:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_character')

    conditions = char_info[CONDITIONS]

    if condition_name not in conditions:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.invalid_condition')

    condition_to_mark = conditions[condition_name]

    if condition_to_mark == compare_to:
        return get_condition_is_unchangable(compare_to, lang)

    char_info[CONDITIONS][condition_name] = compare_to

    upload_to_s3(char_info, key, s3_client)

    return format_conditions(char_info[CONDITIONS], lang)
Esempio n. 4
0
def change_mask_label(message, lang):
    key, content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)
    new_mask_label_og = get_args_from_content(content)

    if char_info[PLAYBOOK] != JANUS:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_playbook')(
            get_translation(lang, f'playbooks.inverted_names.{JANUS}'))

    label_does_not_exist = validate_labels(lang, [new_mask_label_og])
    if label_does_not_exist:
        return label_does_not_exist

    new_mask_label = get_translation(lang,
                                     f'inverted_labels.{new_mask_label_og}')

    if new_mask_label == char_info[MASK_LABEL]:
        return get_translation(
            lang,
            f'{PLAYBOOK_INTERACTIONS}.already_mask_label')(new_mask_label_og)

    new_label_value = char_info[LABELS][new_mask_label][VALUE]

    if new_label_value == MAX_LABEL_VALUE:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.already_max')(
            new_label_value, new_mask_label_og)

    char_info[LABELS][new_mask_label][VALUE] = new_label_value + 1
    char_info[MASK_LABEL] = new_mask_label
    upload_to_s3(char_info, key, s3_client)

    return format_labels(char_info[LABELS], lang)
Esempio n. 5
0
def invert_condition_slash(ctx, lang, condition, what):
    key = get_key_from_ctx(ctx)
    condition_name_og = condition
    condition_name = get_translation(lang, f'inverted_conditions.{condition_name_og}')

    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)
    if not char_info:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_character')

    conditions = char_info[CONDITIONS]

    if condition_name not in conditions:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.invalid_condition')

    condition_to_mark = conditions[condition_name]

    if conditions[condition] == False:
        conditions[condition] = True
    elif conditions[condition] == True:
        conditions[condition] = False

    #if condition_to_mark == compare_to:
        #return get_condition_is_unchangable(compare_to, lang)

    #char_info[CONDITIONS][condition_name] = compare_to

    upload_to_s3(char_info, key, s3_client)

    return format_conditions_slash(char_info[CONDITIONS], lang, condition, what)
Esempio n. 6
0
def lock_label(message, lang):
    key, content = get_key_and_content_from_message(message)
    label_to_lock_name_og = get_args_from_content(content)
    label_to_lock_name = get_translation(lang, f'inverted_labels.{label_to_lock_name_og}')

    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)
    if not char_info:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_character')

    labels = char_info[LABELS]

    label_does_not_exist = validate_labels(lang, [label_to_lock_name_og])
    if label_does_not_exist:
        return label_does_not_exist

    label_to_lock = labels[label_to_lock_name]

    if label_to_lock[LOCKED]:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.already_locked')(get_translation(lang, f'labels.{label_to_lock_name}'))

    labels[label_to_lock_name][LOCKED] = True

    upload_to_s3(char_info, key, s3_client)

    return format_labels(labels, lang)
Esempio n. 7
0
def create_character_slash(ctx, lang, playbook_name, character_name, player_name, label_to_increase_og):
    key = get_key_from_ctx(ctx)
    s3_client = get_s3_client()

    char_info = info_from_s3(key, s3_client)
    if char_info:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.existing_character')

    label_does_not_exist = validate_labels(lang, [label_to_increase_og])
    if label_does_not_exist:
        return label_does_not_exist

    label_to_increase = get_translation(lang, f'inverted_labels.{label_to_increase_og}')
    translated_name = get_translation(lang, f'playbooks.names.{playbook_name}')
    file_list = get_files_from_dir('playbooks', s3_client)
    template_key = f'playbooks/{translated_name}'

    matching_files = list(filter(lambda file_info: file_info["Key"] == f'{template_key}.json', file_list["Contents"]))

    if not matching_files:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_template')(playbook_name)

    template = info_from_s3(template_key, s3_client)

    template[LABELS][label_to_increase][VALUE] = template[LABELS][label_to_increase][VALUE] + 1
    template['characterName'] = character_name
    template['playerName'] = player_name

    upload_to_s3(template, key, s3_client)

    formated_playbook_name = playbook_name.capitalize()
    return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.congrats_on_creation')(character_name, formated_playbook_name)
Esempio n. 8
0
def add_one_to_two_labels(message, lang):
    key, content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)

    if char_info[PLAYBOOK] != DELINQUENT:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_playbook')(
            get_translation(lang, f'playbooks.inverted_names.{DELINQUENT}'))

    labels_to_upgrade = get_args_from_content(content)
    labels = char_info[LABELS]

    labels_do_not_exist = validate_labels(lang, labels_to_upgrade)
    if labels_do_not_exist:
        return labels_do_not_exist

    for label_name in labels_to_upgrade:
        label_to_increase = get_translation(lang,
                                            f'inverted_labels.{label_name}')
        value = int(labels[label_to_increase][VALUE])

        if value == MAX_LABEL_VALUE:
            return get_translation(
                lang, f'{PLAYBOOK_INTERACTIONS}.already_max')(value,
                                                              label_name)

        labels[label_to_increase][VALUE] = 1 + value

    upload_to_s3(char_info, key, s3_client)
    return format_labels(labels, lang)
Esempio n. 9
0
def add_two_to_mentor_label(message, lang):
    key, content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)

    if char_info[PLAYBOOK] != PROTEGE:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_playbook')(
            get_translation(lang, f'playbooks.inverted_names.{PROTEGE}'))

    label_type_og = get_args_from_content(content)
    label_type = get_translation(lang, f'playbooks.protege.{label_type_og}')

    if not label_type:
        return get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.invalid_label_type')(label_type_og)

    label_name = char_info['mentor'][label_type]
    label_to_increase = char_info[LABELS][label_name]
    if label_to_increase[VALUE] > MAX_LABEL_VALUE - 1:
        return get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.max_mentor_label_value')(
                label_name, label_to_increase[VALUE])

    label_to_increase[VALUE] += 2

    upload_to_s3(char_info, key, s3_client)
    return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.successfull_update')
Esempio n. 10
0
def rearrange_labels(message, lang):
    key, content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)
    new_label_values = get_args_from_content(content)
    labels = char_info[LABELS]

    total_sum = 0
    new_sum = 0

    labels_do_not_exist = validate_labels(lang, labels)
    if labels_do_not_exist:
        return labels_do_not_exist

    for value in new_label_values:
        int_value = int(value)

        if int_value < MIN_LABEL_VALUE:
            return get_translation(lang,
                                   f'{PLAYBOOK_INTERACTIONS}.less_than_min')(
                                       MIN_LABEL_VALUE, int_value)

        if int_value > MAX_LABEL_VALUE:
            return get_translation(
                lang,
                f'{PLAYBOOK_INTERACTIONS}.greater_than_max')(MAX_LABEL_VALUE,
                                                             int_value)

        new_sum = new_sum + int_value

    for label in labels:
        total_sum = total_sum + int(labels[label][VALUE])

    if total_sum + 1 != new_sum:
        difference = abs(new_sum - total_sum)
        if new_sum - total_sum > 0:
            direction = get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.more')
        elif total_sum == new_sum:
            difference = ''
            direction = get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.equal')
        else:
            direction = get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.less')

        return get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.add_one_to_label')(difference,
                                                               direction)

    index = 0
    for label in labels:
        labels[label][VALUE] = int(new_label_values[index])
        index += 1

    upload_to_s3(char_info, key, s3_client)
    return format_labels(labels, lang)
Esempio n. 11
0
def replicate_character(ctx, lang, channel_id):
    key, content = get_key_and_content_from_ctx(ctx)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)
    if char_info:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.existing_character')
    link_server = channel_id
    file_list = get_files_from_dir('playbooks', s3_client)
    template_key = f'playbooks/blank'
    matching_files = list(filter(lambda file_info: file_info["Key"] == f'{template_key}.json', file_list["Contents"]))
    template = info_from_s3(template_key, s3_client)
    upload_to_s3(template, key, s3_client)
    return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.character_replication')(character_name, formated_playbook_name)
Esempio n. 12
0
def add_move_from_other_playbook(message, lang):
    key, content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)

    if not char_info:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_character')
    move_name = get_args_from_content(content)
    success, response = add_moves(char_info, lang, move_name, s3_client, lang)

    if success:
        upload_to_s3(char_info, key, s3_client)

    return response
Esempio n. 13
0
def execute_backup(): 
    # Change the value in brackets to keep more/fewer files. time.time() returns seconds since 1970...
    # currently set to 2 days ago from when this script starts to run.
     
    x_days_ago = time.time() - ( 60 * 60 * 24 * 2 )     
    os.putenv('PGPASSWORD', PASS)
     
    con = psycopg2.connect(database='postgres', user=USER, host=HOST, password=PASS)
    cur = con.cursor()
    cur.execute("""SELECT datname from pg_database where datistemplate = false;""")
     
    database_list = cur.fetchall()    
    
    # Delete old backup files first.
    for database_name in database_list :
        database_name = database_name[0]
        if database_name == '':
            continue
     
        glob_list = glob.glob(BACKUP_DIR + database_name + '*' + '.pgdump')
        for file in glob_list:
            file_info = os.stat(file)
            if file_info.st_ctime < x_days_ago:
                log("Unlink: %s" % file)
                os.unlink(file)
            else:
                log("Keeping : %s" % file)
     
    log("Backup files older than %s deleted." % time.strftime('%c', time.gmtime(x_days_ago)))
     
    # Now perform the backup.
    for database_name in database_list:
        database_name = database_name[0]
        if database_name == 'postgres':
            continue
     
        log("dump started for %s" % database_name)
        thetime = str(strftime("%Y-%m-%d-%H-%M")) 
        file_name = database_name + '_' + thetime + ".sql.pgdump"
        #Run the pg_dump command to the right directory
        command = dumper % (USER,  BACKUP_DIR + file_name, database_name)
        log(command)
        subprocess.call(command,shell = True)
        log("%s dump finished" % database_name)
        
        storage.upload_to_s3('secret', 'key', 'danimaribeiro_aws_backup', BACKUP_DIR + file_name)
        mail.send_email('@gmail.com', 'para', 'Backup completo', 'Alguns backups não puderam ser completados')
        
    log("Backup job complete.")
Esempio n. 14
0
def remove_potential(message, lang):
    key, _content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)
    if not char_info:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_character')

    potential = char_info[POTENTIAL]
    if potential > 0:
        potential = potential - 1
        char_info[POTENTIAL] = potential
        upload_to_s3(char_info, key, s3_client)
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.congrats_potential')(potential)
    elif potential == 0:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.nopotential')
Esempio n. 15
0
def add_resources(message, lang):
    key, content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)

    if char_info[PLAYBOOK] != PROTEGE:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_playbook')(
            get_translation(lang, f'playbooks.inverted_names.{PROTEGE}'))

    resources_og = get_args_from_content(content)

    resources_count = len(resources_og)
    if resources_count > MAX_RESOURCES_TO_ADD:
        return get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.more_than_four_resources')(
                MAX_RESOURCES_TO_ADD, resources_count)

    current_resources = char_info[MENTOR][RESOURCES]
    resource_count = 0
    resources = []
    already_acquired = []

    for resource_og in resources_og:
        resource = get_translation(
            lang, f'playbooks.protege.resources_accessors.{resource_og}')
        if not resource:
            return get_invaild_resource_response(lang, resource_og,
                                                 current_resources)

        if current_resources[resource]:
            already_acquired.append(resource_og)
        else:
            resources.append(resource)

    if already_acquired:
        response = get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.resource_already_acquired')

        for resource in already_acquired:
            response += f'\n• {resource}'

        return response

    for resource in resources:
        current_resources[resource] = True

    upload_to_s3(char_info, key, s3_client)
    return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.successfull_update')
Esempio n. 16
0
def toggle_dice(message, _lang):
    settings_key = get_settings_path(message)
    s3_client = get_s3_client()
    settings = info_from_s3(settings_key, s3_client)
    lang = settings[LANGUAGE]
    if not settings:
        return no_config_file()
    dice = settings[DICEDISPLAY]
    if dice == True:
        dice = False
    elif dice == False:
        dice = True
    settings[DICEDISPLAY] = dice
    upload_to_s3(settings, settings_key, s3_client)
    response = get_translation(lang,
                               f'{CONFIGURATION}.dicedisplayswitched')(dice)
    return response
Esempio n. 17
0
def generic_updater(message, field):
    settings_key = get_settings_path(message)
    s3_client = get_s3_client()
    settings = info_from_s3(settings_key, s3_client)

    if not settings:
        return no_config_file()

    from tssplit import tssplit
    new_value = tssplit(message.content, quote='"', delimiter=' ')[1]
    #new_value = message.content.split(" ")[1]
    settings[field] = new_value

    upload_to_s3(settings, settings_key, s3_client)

    return get_translation(settings[LANGUAGE],
                           'configuration.successfull_update')
Esempio n. 18
0
def get_more_flares(message, lang):
    key, content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)

    if char_info[PLAYBOOK] != NOVA:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_playbook')(
            get_translation(lang, f'playbooks.inverted_names.{NOVA}'))

    new_flares = get_args_from_content(content)

    new_flares_count = len(new_flares)
    if new_flares_count != 3:
        return get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.not_exactly_three_flares')(
                new_flares_count)

    already_picked = ''
    acum = ''
    flares = char_info[FLARES]
    translated_flares = []

    for flare in new_flares:
        translated_flare = get_translation(
            lang, f'playbooks.nova.accessors.{flare}')
        translated_flares.append(translated_flare)

        if translated_flare not in flares:
            acum += f'\n• {flare}'
        elif flares[translated_flare]:
            already_picked = get_translation(
                lang, f'{PLAYBOOK_INTERACTIONS}.flare_is_picked')(flare)

    if acum:
        return already_picked + '\n' + get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.invalid_flares') + acum
    if already_picked:
        return already_picked

    for translated_flare in translated_flares:
        flares[translated_flare] = True

    upload_to_s3(char_info, key, s3_client)
    return format_flares(lang, flares)
Esempio n. 19
0
def edit_labels_slash(ctx, lang, labelup, labeldown):
    key = get_key_from_ctx(ctx)
    label_to_increase_name_og = labelup
    label_to_decrease_name_og = labeldown

    if label_to_increase_name_og == label_to_decrease_name_og:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.different_labels')

    label_to_increase_name = get_translation(lang, f'inverted_labels.{label_to_increase_name_og}')
    label_to_decrease_name = get_translation(lang, f'inverted_labels.{label_to_decrease_name_og}')

    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)
    if not char_info:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_character')

    labels = char_info[LABELS]

    labels_do_not_exist = validate_labels(lang, [label_to_increase_name_og, label_to_decrease_name_og])
    if labels_do_not_exist:
        return labels_do_not_exist

    label_to_increase = labels[label_to_increase_name]
    label_to_increase_value = label_to_increase[VALUE]
    label_to_decrease = labels[label_to_decrease_name]
    label_to_decrease_value = label_to_decrease[VALUE]

    if label_is_not_editable(label_to_increase, MAX_LABEL_VALUE):
        up = get_translation(lang,  f'{PLAYBOOK_INTERACTIONS}.up')
        return get_label_has_border_value_text(label_to_increase_name, label_to_increase, up, lang)

    if label_is_not_editable(label_to_decrease, MIN_LABEL_VALUE):
        down = get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.down')
        return get_label_has_border_value_text(label_to_decrease_name, label_to_decrease, down, lang)

    labels[label_to_increase_name][VALUE] = label_to_increase_value + 1
    labels[label_to_decrease_name][VALUE] = label_to_decrease_value - 1

    upload_to_s3(char_info, key, s3_client)

    return format_labels_changed(labels, lang, label_to_increase_name, label_to_decrease_name)
Esempio n. 20
0
def add_team(message, _lang, action):
    settings_key = get_settings_path(message)
    s3_client = get_s3_client()
    settings = info_from_s3(settings_key, s3_client)
    if not settings:
        return no_config_file()
    lang = settings[LANGUAGE]
    team = settings[TEAM]
    if action == 'increase':
        team = team + 1  #increment!
    elif action == 'decrease':
        if team > 0:
            team = team - 1  #spend!
        else:
            return get_translation(lang, 'configuration.insufficient_team')
    elif action == 'empty':
        team = 1
    settings[TEAM] = team  #update team
    upload_to_s3(settings, settings_key, s3_client)
    response = get_translation(lang, f'{CONFIGURATION}.team_pool')(team)
    return response
Esempio n. 21
0
def mark_potential(message, lang):
    key, _content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)
    if not char_info:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_character')

    potential = char_info[POTENTIAL]

    if potential == 4:
        char_info[POTENTIAL] = 0
        char_info[PENDING_ADVANCEMENTS] = char_info[PENDING_ADVANCEMENTS] + 1
        potential = 0
        upload_to_s3(char_info, key, s3_client)
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.congrats_pending_advancements')(char_info[PENDING_ADVANCEMENTS])

    potential = potential + 1
    char_info[POTENTIAL] = potential

    upload_to_s3(char_info, key, s3_client)
    return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.congrats_potential')(potential)
Esempio n. 22
0
def add_adult_move(message, lang):
    key, content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)

    if not char_info:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_character')

    move_name = get_args_from_content(content)

    moves_array = get_moves_json_array(lang)[MOVES]
    move_list = list(
        filter(lambda move_dict: move_dict[SHORT_NAME] == move_name,
               moves_array))

    if not len(move_list):
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_moves_pb')

    move = move_list[0]

    if move[PLAYBOOK] != ADULT:
        return get_translation(lang,
                               f'{PLAYBOOK_INTERACTIONS}.not_adult')(move_name)

    id = move_list[0][ID]

    move = list(filter(lambda dic: dic[ID] == id, char_info[MOVES]))

    if len(move):
        return get_translation(lang,
                               f'{PLAYBOOK_INTERACTIONS}.move_already_taken')

    char_info[PENDING_ADVANCEMENTS] = char_info[PENDING_ADVANCEMENTS] - 1
    char_info[MOVES].append({"id": id, "picked": True})
    upload_to_s3(char_info, key, s3_client)

    return get_translation(
        lang, f'{PLAYBOOK_INTERACTIONS}.successfully_added_move')(move_name)
Esempio n. 23
0
def create_settings_ctx(ctx):
    settings_key = get_settings_path_ctx(ctx)
    s3_client = get_s3_client()
    settings = info_from_s3(settings_key, s3_client)

    if settings:
        return get_translation(settings[LANGUAGE],
                               'configuration.existing_settings')

    lang = "en"  #message.content.split(" ")[1]

    settings = {
        "language": lang,
        "gm": "",
        "teamname": "",
        "customNames": [],
        "team": 1,
        "dicedisplay": True
    }

    upload_to_s3(settings, f'adventures/{ctx.channel_id}/settings', s3_client)

    return get_translation(lang, 'configuration.successfull_creation')
Esempio n. 24
0
def get_part_of_playbook(message, lang, playbook_to_take_from,
                         your_playbook_must_be, what_to_take, moves,
                         cant_take_message):
    key, content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)

    if char_info[PLAYBOOK] not in your_playbook_must_be:
        allowed_playbooks = ''
        for playbook in your_playbook_must_be:
            translated_playbook = get_translation(
                lang, f'playbooks.inverted_names.{playbook}')
            allowed_playbooks += f'\n• {translated_playbook}'

        return get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.no_playbook')(allowed_playbooks)

    playbook_template = info_from_s3(f'playbooks/{playbook_to_take_from}',
                                     s3_client)

    for take_this in what_to_take:
        if take_this in char_info:
            return get_translation(lang,
                                   f'{PLAYBOOK_INTERACTIONS}.already_have')(
                                       get_translation(lang,
                                                       cant_take_message))

        char_info[take_this] = playbook_template[take_this]

    for move in moves:
        success, response = add_moves(char_info, lang, move, s3_client)

        if not success:
            return response

    upload_to_s3(char_info, key, s3_client)
    return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.successfull_update')
Esempio n. 25
0
def get_more_bull_roles(message, lang):
    key, content = get_key_and_content_from_message(message)
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)

    if char_info[PLAYBOOK] != BULL:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_playbook')(
            get_translation(lang, f'playbooks.inverted_names.{BULL}'))

    new_roles = get_args_from_content(content)
    already_picked = ''
    acum = ''
    roles = char_info[HEART][ROLES]
    translated_roles = []

    for role in new_roles:
        translated_role = get_translation(
            lang, f'playbooks.bull.roles.titles_dict')[role]
        translated_roles.append(translated_role)

        if translated_role not in roles:
            acum += f'\n• {role}'
        elif roles[translated_role]:
            already_picked = get_translation(
                lang, f'{PLAYBOOK_INTERACTIONS}.role_is_picked')(role)

    if len(acum):
        return already_picked + '\n' + get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.invalid_roles') + acum
    if already_picked:
        return already_picked

    for translated_role in translated_roles:
        roles[translated_role] = True

    upload_to_s3(char_info, key, s3_client)
    return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.successfull_update')
Esempio n. 26
0
    def submit(self, user, error_callback_url=None):
        self.error_callback_url = error_callback_url

        try:
            form_data = self.match_fields(user)
            include_postage = user.get('include_postage', False)
            mail_letter = user.get('mail_letter', False)
            to_address = election_mail.get_mailto_address(user)
            pdf_file = self.generate_pdf(form_data, to_address,
                                         include_postage, mail_letter)

            if pdf_file:
                self.pdf_url = storage.upload_to_s3(
                    pdf_file,
                    'forms/%s/hellovote-registration-print-me.pdf' % self.uid)

                if mail_letter:
                    letter = postage.mail_letter(self.uid, user, self.pdf_url)
                    return {
                        'status': 'success',
                        'mail_letter': True,
                        'mail_carrier': letter.carrier,
                        'expected_delivery_date':
                        letter.expected_delivery_date,
                        'pdf_url': self.pdf_url
                    }
                else:
                    return {'status': 'success', 'pdf_url': self.pdf_url}
            else:
                return {
                    'status': 'error',
                    'message': 'unable to generate NVRA pdf'
                }

        except ValidationError, e:
            raise OVRError(self,
                           message=e.message,
                           payload=e.payload,
                           error_callback_url=self.error_callback_url)