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 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 get_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 not char_info: return get_translation(lang, f'{PLAYBOOK_INTERACTIONS}.no_character') return format_labels(char_info[LABELS], lang)
def get_labels_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_labels(char_info[LABELS], lang)
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 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)
def edit_labels(message, lang): key, content = get_key_and_content_from_message(message) label_to_increase_name_og, label_to_decrease_name_og = get_args_from_content( content) 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(labels, lang)