From 54c30d4775b0eba815b0fc4f94128b2e0394b677 Mon Sep 17 00:00:00 2001 From: qwewqa <198e559dbd446d973355f415bdfa34@gmail.com> Date: Fri, 15 Jan 2021 13:11:57 -0500 Subject: [PATCH] add basic card command --- miyu_bot/commands/cogs/card.py | 36 ++++++++++++++++++++ miyu_bot/commands/cogs/music.py | 9 ++--- miyu_bot/commands/common/emoji.py | 5 +++ miyu_bot/commands/common/reaction_message.py | 6 +++- 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/miyu_bot/commands/cogs/card.py b/miyu_bot/commands/cogs/card.py index ffe5702..931df90 100644 --- a/miyu_bot/commands/cogs/card.py +++ b/miyu_bot/commands/cogs/card.py @@ -1,13 +1,49 @@ +import asyncio import logging +import discord +from d4dj_utils.master.card_master import CardMaster from discord.ext import commands +from main import masters +from miyu_bot.commands.common.emoji import rarity_emoji_ids +from miyu_bot.commands.common.master_asset_manager import hash_master +from miyu_bot.commands.common.reaction_message import run_tabbed_message + class Card(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot self.logger = logging.getLogger(__name__) + @property + def rarity_emoji(self): + return [self.bot.get_emoji(eid) for eid in rarity_emoji_ids.values()] + + @commands.command(name='card', + aliases=[], + description='Finds the card with the given name.', + help='!card secretcage') + async def card(self, ctx: commands.Context, *, arg: commands.clean_content): + self.logger.info(f'Searching for card "{arg}".') + card = masters.cards.get(arg, ctx) + + embeds = [self.get_card_embed(card, 0), self.get_card_embed(card, 1)] + asyncio.ensure_future(run_tabbed_message(ctx, self.rarity_emoji, embeds, starting_index=1)) + + def get_card_embed(self, card: CardMaster, limit_break): + embed = discord.Embed(title=f'{card.rarity_id}★ {card.name} {card.character.full_name_english}') + + card_hash = hash_master(card) + icon_path = card.icon_path(limit_break) + thumb_url = f'https://qwewqa.github.io/d4dj-dumps/cards/icons/{icon_path.stem}_{card_hash}{icon_path.suffix}' + art_path = card.art_path(limit_break) + art_url = f'https://qwewqa.github.io/d4dj-dumps/cards/art/{art_path.stem}_{card_hash}{art_path.suffix}' + + embed.set_thumbnail(url=thumb_url) + embed.set_image(url=art_url) + + return embed def setup(bot): diff --git a/miyu_bot/commands/cogs/music.py b/miyu_bot/commands/cogs/music.py index 7553ba4..49b16a6 100644 --- a/miyu_bot/commands/cogs/music.py +++ b/miyu_bot/commands/cogs/music.py @@ -116,9 +116,8 @@ class Music(commands.Cog): embeds, files = self.get_chart_embed_info(song) - message = await ctx.send(files=files, embed=embeds[difficulty - 1]) - - asyncio.ensure_future(run_tabbed_message(ctx, message, self.reaction_emojis, embeds)) + # Difficulty enum easy-expert are 1-4, one more than the embed index + asyncio.ensure_future(run_tabbed_message(ctx, self.reaction_emojis, embeds, files, difficulty - 1)) @commands.command(name='sections', aliases=['mixes'], @@ -144,9 +143,7 @@ class Music(commands.Cog): embeds, files = self.get_mix_embed_info(song) - message = await ctx.send(files=files, embed=embeds[difficulty - 1]) - - asyncio.ensure_future(run_tabbed_message(ctx, message, self.reaction_emojis, embeds)) + asyncio.ensure_future(run_tabbed_message(ctx, self.reaction_emojis, embeds, files, difficulty - 1)) @commands.command(name='songs', aliases=['songsearch', 'song_search'], diff --git a/miyu_bot/commands/common/emoji.py b/miyu_bot/commands/common/emoji.py index c78e34b..c47937c 100644 --- a/miyu_bot/commands/common/emoji.py +++ b/miyu_bot/commands/common/emoji.py @@ -39,3 +39,8 @@ attribute_emoji_ids = { attribute_emoji_ids_by_attribute_id = {i + 1: v for i, v in enumerate(attribute_emoji_ids.values())} event_point_emoji_id = 792097816931598336 + +rarity_emoji_ids = { + 'base': 799650003659915294, + 'limit_break': 799650003303268393 +} diff --git a/miyu_bot/commands/common/reaction_message.py b/miyu_bot/commands/common/reaction_message.py index f76da9b..37cb4d1 100644 --- a/miyu_bot/commands/common/reaction_message.py +++ b/miyu_bot/commands/common/reaction_message.py @@ -8,10 +8,14 @@ from discord.ext.commands import Context AnyEmoji = Union[str, Emoji] -async def run_tabbed_message(ctx: Context, message: Message, emojis: List[AnyEmoji], embeds: List[Embed], timeout=300): +async def run_tabbed_message(ctx: Context, emojis: List[AnyEmoji], embeds: List[Embed], files=None, starting_index=0, timeout=300): + if not files: + files = [] if len(emojis) != len(embeds): raise ValueError('Emojis and embeds must have the same number of elements.') + message = await ctx.send(files=files, embed=embeds[starting_index]) + async def callback(emoji, _ctx, _message): await message.edit(embed=embeds[emojis.index(emoji)])