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)
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)
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)
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')
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)
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)
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)
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')
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)
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)
def get_sheet(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 char #format_advancements(char_info[C], lang)
def get_moves(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_moves(char_info[MOVES])
def get_pending_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') pending_advancements = char_info[PENDING_ADVANCEMENTS] return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.pending_advancements')(pending_advancements)
def get_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] return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.potential')(potential)
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)
def delete_character_ctx(ctx, lang): 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: character_name = char_info['characterName'] formated_playbook_name = char_info['playbook'].capitalize() s3_delete(key, s3_client) return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.character_deletion')(character_name, formated_playbook_name) if not char_info: return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_character')
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')
def print_party(ctx,lang): key = get_channel_from_ctx(ctx) s3_client = get_s3_client() party = get_char_files_from_dir(key,s3_client) response = "The Party is made up of:\n" for player in party: if 'settings' not in player: #here we need to ignore settings.json files :D player_key = player.split('.')[0] char_info = info_from_s3(player_key, s3_client) response = response + f' - {char_info["characterName"]} the {char_info["playbook"].capitalize()} played by {char_info["playerName"]}\n' return response
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]}'
def get_raw_lang(message, _lang=None): try: settings_key = get_settings_path(message) s3_client = get_s3_client() settings = info_from_s3(settings_key, s3_client) if not settings: return 'en' return settings[LANGUAGE] except Exception as exception: return 'en'
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
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)
def get_dicedisplay(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() ##need to fix this so it displays the message properly return True try: dicedisplay = settings[DICEDISPLAY] except: dicedisplay = True return dicedisplay
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
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
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')
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
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')
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')
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