add basic card command

pull/1/head
qwewqa 4 years ago
parent 758cb4ca1c
commit 54c30d4775
  1. 36
      miyu_bot/commands/cogs/card.py
  2. 9
      miyu_bot/commands/cogs/music.py
  3. 5
      miyu_bot/commands/common/emoji.py
  4. 6
      miyu_bot/commands/common/reaction_message.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):

@ -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'],

@ -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
}

@ -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)])

Loading…
Cancel
Save