예제 #1
0
파일: moves.py 프로젝트: Shpaackle/maddie
def get_playbook_field(command, lang):
    playbook_list = get_playbook_list(lang)

    if command in playbook_list:
        return command

    moves = get_translation(lang, 'moves.moves')
    if command.startswith(moves):
        return 'basic'

    adult = get_translation(lang, 'moves.adult')
    if command.startswith(adult):
        return 'adult'

    return ''
예제 #2
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')
예제 #3
0
def get_settings(message, _lang):
    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()

    response = get_translation(settings[LANGUAGE], 'configuration.settings')
    for field in settings:
        name = get_translation(settings[LANGUAGE], f'configuration.{field}')
        value = settings[field]
        response = response + f'{name}: {value}\n'

    return response
예제 #4
0
def plain_command_handler(message, lang):
    command = message.content.split(" ")[0][1:]
    handler = plain_commands_dict.get(
        get_translation(lang, f'plain_commands.{command}'),
        lambda _msg, _lang: '')

    return handler(message, lang)
예제 #5
0
def update_lang(message, lang):
    new_lang = message.content.split(" ")[1]

    if is_invalid_lang(new_lang):
        return get_translation(lang, 'configuration.invalid_lang')

    return generic_updater(message, LANGUAGE)
예제 #6
0
파일: utils.py 프로젝트: GonzaH/maddie
def format_labels(labels, lang):
    response = get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.labels_base')

    for label in labels:
        name = get_translation(lang, f'labels.{label}').capitalize()
        value = labels[label][VALUE]

        if labels[label][LOCKED]:
            is_locked = get_translation(lang,
                                        f'{PLAYBOOK_INTERACTIONS}.locked')
        else:
            is_locked = ''

        response = response + f'{name}: {value} {is_locked}\n'

    return response
예제 #7
0
def format_advance_list(advance_list, list_name, lang):
    response = get_translation(lang,
                               f'{PLAYBOOK_INTERACTIONS}.{list_name}') + '\n'

    for advance_key in advance_list:
        advance = advance_list[advance_key]
        description = advance[DESCRIPTION]
        response = response + '• '
        if advance[TAKEN]:
            response = response + get_translation(
                lang, f'{PLAYBOOK_INTERACTIONS}.taken')

        response = response + get_translation(
            lang, f'playbooks.advances.{description}') + '\n'

    return response
예제 #8
0
파일: playbooks.py 프로젝트: GonzaH/maddie
def get_playbooks(lang):
    json_array = get_moves(lang)
    playbooks = get_translation(lang, 'playbooks.playbooks')
    embed = discord.Embed(title=playbooks)
    available = get_translation(lang, 'playbooks.available')
    embed.set_author(name=available)
    for s in json_array['sources']:
        line = ""
        for p in json_array['playbooks']:
            if s['source'] == p['source']:
                line = line + p['name'].capitalize() + ", "
        line = line.rstrip(', ')
        embed.add_field(name=f"{s['name']}", value=f"{line}", inline=False)
        embed.set_footer(text=" ")
        response = embed
    return response
예제 #9
0
def create_settings(message):
    settings_key = get_settings_path(message)
    s3_client = get_s3_client()
    settings = info_from_s3(settings_key, s3_client)

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

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

    settings = {"language": lang, "gm": "", "teamname": "", "customNames": []}

    upload_to_s3(settings, f'adventures/{message.channel.id}/settings',
                 s3_client)

    return get_translation(lang, 'configuration.successfull_creation')
예제 #10
0
def get_advancements(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')

    return format_advancements(char_info[ADVANCEMENT], lang)
예제 #11
0
def get_conditions_slash(ctx, lang):
    key = get_key_from_ctx(ctx)
    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')

    return format_conditions(char_info[CONDITIONS], lang)
예제 #12
0
def add_result (embed, num_calc, mod, lang):
    #do dice rolling
    result1 = random.randrange(1,7) ##first d6
    result2 = random.randrange(1,7) ##second d6
    result_tot = result1 + result2 + num_calc

    if mod == '-':
        modifier_to_show = ''
    else:
        modifier_to_show = f' {mod}'

    calculation_title = get_translation(lang, 'dice_rolling.calculation_title')
    calculation = get_translation(lang, 'dice_rolling.calculation')(result1, result2, modifier_to_show, num_calc)
    result = get_translation(lang, 'dice_rolling.result')

    embed.add_field(name=calculation_title, value=calculation, inline=False)
    embed.add_field(name=result, value=f"**{result_tot}**")
예제 #13
0
def join_with_detail(array_to_join, lang):
    response = get_translation(lang, 'moves.moves_plus.response_header')

    for p in array_to_join:
        response = response + p['capital'].capitalize() + " - " + p['description'] + \
            COMMA_SEPARATOR + p['shortName'] + \
            COMMA_SEPARATOR + p['label'] + "\n "

    return response
예제 #14
0
def lock_soldier(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] != SOLDIER:
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_playbook')(
            get_translation(lang, f'playbooks.inverted_names.{SOLDIER}'))

    soldier = char_info[LABELS][SOLDIER]
    if soldier[LOCKED]:
        return get_translation(
            lang, f'{PLAYBOOK_INTERACTIONS}.already_locked')(get_translation(
                lang, f'playbooks.inverted_names.{SOLDIER}'))

    soldier[LOCKED] = True

    return format_labels(labels, lang)
예제 #15
0
def create_character(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:
        return get_translation(lang,
                               f'{PLAYBOOK_INTERACTIONS}.existing_character')

    playbook_name, character_name, player_name, label_to_increase_og = get_args_from_content(
        content)

    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)
예제 #16
0
def get_field_from_config(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()

    name = get_translation(settings[LANGUAGE], f'configuration.{field}').capitalize()

    return f'{name}: {settings[field]}'
예제 #17
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

        upload_to_s3(char_info, key, s3_client)
        return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.congrats_pending_advancements')(char_info[PENDING_ADVANCEMENTS])

    char_info[POTENTIAL] = potential + 1

    upload_to_s3(char_info, key, s3_client)
    return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.congrats_potential')(potential)
예제 #18
0
def delete_settings(message):
    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()
    if settings:
        s3_delete(settings_key, s3_client)
        return get_translation(settings[LANGUAGE],
                               'configuration.successfull_deletion')
예제 #19
0
def get_playbook_component(component, message, lang):
    key, _content = get_key_and_content_from_message(message)
    msg = message.content
    usr = message.author.display_name
    s3_client = get_s3_client()
    char_info = info_from_s3(key, s3_client)
    json_array = get_moves(lang)
    playbook_re = get_translation(lang, 'playbooks.playbook_re')
    #this case deals with if we have a character created, but waits to make sure they haven't passed a playbook in anyway
    result1 = re.search(playbook_re, msg)
    found = 0
    if result1 is not None:
        for p in json_array['playbooks']:
            if p['name'] == result1.group(1):
                mot = p['mot']
                cel = p['celebrate']
                wek = p['weakness']
                img = p['img']
                found = 1
    if found != 1:
        if char_info:
            playbook = char_info['playbook']
            charactername = char_info['characterName']
            for p in json_array['playbooks']:
                if p['name'] == playbook:
                    mot = p['mot']
                    cel = p['celebrate']
                    wek = p['weakness']
                    img = p['img']
                    usr = charactername
                    found = 1
    if found == 1:
        description = get_translation(lang, 'description')
        if component == 'mot':
            embed = discord.Embed(title=get_translation(lang, 'playbooks.moment_of_truth'), colour=5450873)
            embed.set_author(name=get_translation(lang, 'playbooks.this_is_mot')(usr))
            embed.add_field(name=description, value=mot)
        elif component == 'celebrate':
            embed = discord.Embed(title=get_translation(lang, 'playbooks.celebrate'))
            embed.set_author(name=get_translation(lang, 'playbooks.this_is_celebrate')(usr))
            embed.add_field(name=description, value=cel)
        elif component == 'weakness':
            embed = discord.Embed(title=get_translation(lang, 'playbooks.weakness'))
            embed.set_author(name=get_translation(lang, 'playbooks.this_is_weakness')(usr))
            embed.add_field(name=description, value=wek)
        embed.set_thumbnail(url=img)
        embed.set_footer(text=" ")
        response = embed
        return response
    else:
        response = 0
예제 #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
예제 #21
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_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)
예제 #22
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')
예제 #23
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')
예제 #24
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')
예제 #25
0
def print_playbook_slash(ctx, lang):
    key = get_key_from_ctx(ctx)
    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')
    char_text = f'You are {char_info["characterName"]}, a {char_info["playbook"].capitalize()}.'
    #this case handles if the character is a replica
    if char_info.get('replicate_key'):
#        repl_id = char_info.get('replicate_key').split('/')[1]
#        this_id = message.channel.get("id")
        char_text = f'You are a copy of {char_info["characterName"]}, a {char_info["playbook"].capitalize()}.'
    return char_text
예제 #26
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)
예제 #27
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')
예제 #28
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
예제 #29
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')
예제 #30
0
파일: playbooks.py 프로젝트: GonzaH/maddie
def get_moment_of_truth(message, lang):
    msg = message.content
    usr = message.author.display_name
    json_array = get_moves(lang)
    found = 0
    msg = msg.lower()
    playbook_re = get_translation(lang, 'playbooks.playbook_re')
    result1 = re.search(playbook_re, msg)
    for p in json_array['playbooks']:
        if p['name'] == result1.group(1):
            mot = p['mot']
            img = p['img']
            found = 1
    if found == 1:
        embed = discord.Embed(title=get_translation(lang, 'playbooks.moment_of_truth'))
        embed.set_author(name=get_translation(lang, 'playbooks.this_is_mot')(usr))
        embed.set_thumbnail(url=img)
        description = get_translation(lang, 'description')
        embed.add_field(name=description, value=mot)
        embed.set_footer(text=" ")
        response = embed
    else: response = 0

    return response