diff --git a/miyu_bot/commands/cogs/card.py b/miyu_bot/commands/cogs/card.py index e1101ef..aa436cd 100644 --- a/miyu_bot/commands/cogs/card.py +++ b/miyu_bot/commands/cogs/card.py @@ -16,7 +16,7 @@ from miyu_bot.commands.common.emoji import rarity_emoji_ids, attribute_emoji_ids from miyu_bot.commands.common.event import get_latest_event from miyu_bot.commands.common.formatting import format_info from miyu_bot.commands.common.master_asset_manager import hash_master -from miyu_bot.commands.common.name_aliases import characters_by_name, attributes_by_name, units_by_name +from miyu_bot.commands.common.name_aliases import characters_by_name, attributes_by_name, units_by_name, unit_aliases from miyu_bot.commands.common.reaction_message import run_tabbed_message, run_reaction_message, run_paged_message @@ -123,10 +123,11 @@ class Card(commands.Cog): # Not used, but here because it's a valid argument before running require_all_arguments_used. display, _ = arguments.single(['display', 'disp'], sort, allowed_operators=['='], converter=card_attribute_aliases) - character = {characters_by_name[c].id for c in arguments.words(characters_by_name.keys())} - unit = {units_by_name[a].id for a in arguments.words(units_by_name.keys())} - rarity = {int(r[0]) for r in arguments.words(['4*', '3*', '2*', '1*', r'4\*', r'3\*', r'2\*', r'1\*'])} - attribute = {attributes_by_name[a].id for a in arguments.words(attributes_by_name.keys())} + characters = {characters_by_name[c].id for c in arguments.words(characters_by_name.keys())} + units = {units_by_name[unit].id + for unit in arguments.tags(names=units_by_name.keys(), aliases=unit_aliases)} + rarities = {int(r[0]) for r in arguments.words(['4*', '3*', '2*', '1*', r'4\*', r'3\*', r'2\*', r'1\*'])} + attributes = {attributes_by_name[a].id for a in arguments.words(attributes_by_name.keys())} event_bonus = bool(arguments.tags(['event', 'eventbonus', 'event_bonus'])) @@ -134,13 +135,13 @@ class Card(commands.Cog): latest_event = get_latest_event(ctx) bonus: EventSpecificBonusMaster = latest_event.bonus - if not character: - character.update(bonus.character_ids) + if not characters: + characters.update(bonus.character_ids) elif bonus.character_ids: - character = {char for char in character if char in bonus.character_ids} + characters = {char for char in characters if char in bonus.character_ids} if bonus.attribute_id: - attribute = {bonus.attribute_id} + attributes = {bonus.attribute_id} if not arguments.has_named('sort'): sort = CardAttribute.Date @@ -155,14 +156,14 @@ class Card(commands.Cog): cards = cards[::-1] if reverse_sort: cards = cards[::-1] - if character: - cards = [card for card in cards if card.character.id in character] - if unit: - cards = [card for card in cards if card.character.unit.id in unit] - if rarity: - cards = [card for card in cards if card.rarity_id in rarity] - if attribute: - cards = [card for card in cards if card.attribute.id in attribute] + if characters: + cards = [card for card in cards if card.character.id in characters] + if units: + cards = [card for card in cards if card.character.unit.id in units] + if rarities: + cards = [card for card in cards if card.rarity_id in rarities] + if attributes: + cards = [card for card in cards if card.attribute.id in attributes] return cards diff --git a/miyu_bot/commands/cogs/music.py b/miyu_bot/commands/cogs/music.py index 3d92035..85ee94f 100644 --- a/miyu_bot/commands/cogs/music.py +++ b/miyu_bot/commands/cogs/music.py @@ -19,6 +19,7 @@ from miyu_bot.commands.common.emoji import difficulty_emoji_ids from miyu_bot.commands.common.formatting import format_info from miyu_bot.commands.common.fuzzy_matching import romanize from miyu_bot.commands.common.master_asset_manager import hash_master +from miyu_bot.commands.common.name_aliases import units_by_name, unit_aliases from miyu_bot.commands.common.reaction_message import run_tabbed_message, run_paged_message @@ -178,24 +179,8 @@ class Music(commands.Cog): reverse_sort = sort_op == '<' or arguments.tag('reverse') display, _ = arguments.single(['display', 'disp'], sort, allowed_operators=['='], converter=music_attribute_aliases) - units = arguments.tags( - names=['happy_around', 'peaky_p-key', 'photon_maiden', 'merm4id', 'rondo', 'lyrical_lily', 'other'], - aliases={ - 'hapiara': 'happy_around', - 'ha': 'happy_around', - 'peaky': 'peaky_p-key', - 'p-key': 'peaky_p-key', - 'pkey': 'peaky_p-key', - 'pkpk': 'peaky_p-key', - 'photome': 'photon_maiden', - 'photon': 'photon_maiden', - 'pm': 'photon_maiden', - 'mermaid': 'merm4id', - 'riririri': 'lyrical_lily', - 'lililili': 'lyrical_lily', - 'lily': 'lyrical_lily', - 'lili': 'lyrical_lily', - }) + units = {units_by_name[unit].id + for unit in arguments.tags(names=units_by_name.keys(), aliases=unit_aliases)} def difficulty_converter(d): return int(d[:-1]) + 0.5 if d[-1] == '+' else int(d) @@ -215,22 +200,7 @@ class Music(commands.Cog): songs = [song for song in songs if operator(song.charts[4].level, value)] if units: - unit_ids = { - 'happy_around': 1, - 'peaky_p-key': 2, - 'photon_maiden': 3, - 'merm4id': 4, - 'rondo': 5, - 'lyrical_lily': 6, - } - allowed_unit_ids = set() - for unit in units: - if unit == 'other': - allowed_unit_ids.add(30) - allowed_unit_ids.add(50) - else: - allowed_unit_ids.add(unit_ids[unit]) - songs = [song for song in songs if song.unit.id in allowed_unit_ids] + songs = [song for song in songs if song.unit.id in units] if not (arguments.text_argument and sort == MusicAttribute.DefaultOrder): songs = sorted(songs, key=lambda s: sort.get_sort_key_from_music(s)) diff --git a/miyu_bot/commands/common/name_aliases.py b/miyu_bot/commands/common/name_aliases.py index 3e75ac2..7a6d064 100644 --- a/miyu_bot/commands/common/name_aliases.py +++ b/miyu_bot/commands/common/name_aliases.py @@ -7,5 +7,26 @@ for character in asset_manager.character_master.values(): attributes_by_name = {attribute.en_name: attribute for attribute in asset_manager.attribute_master.values()} -units_by_name = {unit.name.lower(): unit for unit in asset_manager.unit_master.values()} +units_by_name = {unit.name.lower().replace(' ', '_'): unit for unit in asset_manager.unit_master.values()} units_by_name['rondo'] = units_by_name['燐舞曲'] +units_by_name['special'] = units_by_name['スペシャル'] +units_by_name['other'] = units_by_name['その他'] +unit_aliases = { + 'hapiara': 'happy_around', + 'ha': 'happy_around', + 'peaky': 'peaky_p-key', + 'p-key': 'peaky_p-key', + 'pkey': 'peaky_p-key', + 'pkpk': 'peaky_p-key', + 'pk': 'peaky_p-key', + 'photome': 'photon_maiden', + 'photon': 'photon_maiden', + 'pm': 'photon_maiden', + 'mermaid': 'merm4id', + 'mmd': 'merm4id', + 'riririri': 'lyrical_lily', + 'lililili': 'lyrical_lily', + 'lily': 'lyrical_lily', + 'lili': 'lyrical_lily', + 'll': 'lyrical_lily', +}