Ejemplo n.º 1
0
def add_moves(char_info, lang, move_name, s3_client, json_lang='en'):
    moves_array = get_moves_json_array(json_lang)[MOVES]
    move_list = filter_moves_by_name(move_name, moves_array)

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

    move = move_list[0]

    if move[PLAYBOOK] == char_info[PLAYBOOK]:
        return False, get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.your_playbook')

    id = move_list[0][ID]

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

    if len(move):
        return False, 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})

    return True, get_translation(
        lang, f'{PLAYBOOK_INTERACTIONS}.successfully_added_move')(move_name)
Ejemplo 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)
Ejemplo n.º 3
0
def get_moves(message, lang):
    content = message.content
    moves_array = get_moves_json_array(lang)
    type_of_command, show_detail = parse_command(content)

    playbook_field = get_playbook_field(type_of_command, lang)

    if playbook_field:
        moves_by_playbook = list(
            filter(
                lambda move_dict: compare_move_to_playbook(
                    move_dict, playbook_field), moves_array['moves']))

        if not len(moves_by_playbook):
            return get_unknown_playbook_response(lang)

        if show_detail:
            return join_with_detail(moves_by_playbook, lang)

        return join_with_commas(moves_by_playbook, 'shortName')

    return None
Ejemplo n.º 4
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)