update unit aliases and make units tags in card and cards command

pull/1/head
qwewqa 4 years ago
parent c5b6fd024b
commit 11d09806d7
  1. 35
      miyu_bot/commands/cogs/card.py
  2. 38
      miyu_bot/commands/cogs/music.py
  3. 23
      miyu_bot/commands/common/name_aliases.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.event import get_latest_event
from miyu_bot.commands.common.formatting import format_info 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.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 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. # Not used, but here because it's a valid argument before running require_all_arguments_used.
display, _ = arguments.single(['display', 'disp'], sort, allowed_operators=['='], display, _ = arguments.single(['display', 'disp'], sort, allowed_operators=['='],
converter=card_attribute_aliases) converter=card_attribute_aliases)
character = {characters_by_name[c].id for c in arguments.words(characters_by_name.keys())} characters = {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())} units = {units_by_name[unit].id
rarity = {int(r[0]) for r in arguments.words(['4*', '3*', '2*', '1*', r'4\*', r'3\*', r'2\*', r'1\*'])} for unit in arguments.tags(names=units_by_name.keys(), aliases=unit_aliases)}
attribute = {attributes_by_name[a].id for a in arguments.words(attributes_by_name.keys())} 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'])) event_bonus = bool(arguments.tags(['event', 'eventbonus', 'event_bonus']))
@ -134,13 +135,13 @@ class Card(commands.Cog):
latest_event = get_latest_event(ctx) latest_event = get_latest_event(ctx)
bonus: EventSpecificBonusMaster = latest_event.bonus bonus: EventSpecificBonusMaster = latest_event.bonus
if not character: if not characters:
character.update(bonus.character_ids) characters.update(bonus.character_ids)
elif 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: if bonus.attribute_id:
attribute = {bonus.attribute_id} attributes = {bonus.attribute_id}
if not arguments.has_named('sort'): if not arguments.has_named('sort'):
sort = CardAttribute.Date sort = CardAttribute.Date
@ -155,14 +156,14 @@ class Card(commands.Cog):
cards = cards[::-1] cards = cards[::-1]
if reverse_sort: if reverse_sort:
cards = cards[::-1] cards = cards[::-1]
if character: if characters:
cards = [card for card in cards if card.character.id in character] cards = [card for card in cards if card.character.id in characters]
if unit: if units:
cards = [card for card in cards if card.character.unit.id in unit] cards = [card for card in cards if card.character.unit.id in units]
if rarity: if rarities:
cards = [card for card in cards if card.rarity_id in rarity] cards = [card for card in cards if card.rarity_id in rarities]
if attribute: if attributes:
cards = [card for card in cards if card.attribute.id in attribute] cards = [card for card in cards if card.attribute.id in attributes]
return cards return cards

@ -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.formatting import format_info
from miyu_bot.commands.common.fuzzy_matching import romanize 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.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 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') reverse_sort = sort_op == '<' or arguments.tag('reverse')
display, _ = arguments.single(['display', 'disp'], sort, allowed_operators=['='], display, _ = arguments.single(['display', 'disp'], sort, allowed_operators=['='],
converter=music_attribute_aliases) converter=music_attribute_aliases)
units = arguments.tags( units = {units_by_name[unit].id
names=['happy_around', 'peaky_p-key', 'photon_maiden', 'merm4id', 'rondo', 'lyrical_lily', 'other'], for unit in arguments.tags(names=units_by_name.keys(), aliases=unit_aliases)}
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',
})
def difficulty_converter(d): def difficulty_converter(d):
return int(d[:-1]) + 0.5 if d[-1] == '+' else int(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)] songs = [song for song in songs if operator(song.charts[4].level, value)]
if units: if units:
unit_ids = { songs = [song for song in songs if song.unit.id in units]
'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]
if not (arguments.text_argument and sort == MusicAttribute.DefaultOrder): if not (arguments.text_argument and sort == MusicAttribute.DefaultOrder):
songs = sorted(songs, key=lambda s: sort.get_sort_key_from_music(s)) songs = sorted(songs, key=lambda s: sort.get_sort_key_from_music(s))

@ -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()} 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['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',
}

Loading…
Cancel
Save