add reaction chart difficulty selectors

pull/1/head
qwewqa 4 years ago
parent 31f64a2799
commit b9403a85a3
  1. 3
      main.py
  2. 14
      miyu_bot/commands/cogs/card.py
  3. 50
      miyu_bot/commands/cogs/music.py

@ -11,7 +11,10 @@ with open('config.json') as f:
bot_token = json.load(f)['token'] bot_token = json.load(f)['token']
bot = commands.Bot(command_prefix='!', case_insensitive=True) bot = commands.Bot(command_prefix='!', case_insensitive=True)
asset_manager = AssetManager('assets') asset_manager = AssetManager('assets')
bot.load_extension('miyu_bot.commands.cogs.card')
bot.load_extension('miyu_bot.commands.cogs.music') bot.load_extension('miyu_bot.commands.cogs.music')
bot.load_extension('miyu_bot.commands.cogs.utility') bot.load_extension('miyu_bot.commands.cogs.utility')

@ -0,0 +1,14 @@
import logging
from discord.ext import commands
class Card(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.logger = logging.getLogger(__name__)
def setup(bot):
bot.add_cog(Card(bot))

@ -1,3 +1,4 @@
import asyncio
import logging import logging
import discord import discord
@ -111,18 +112,47 @@ class Music(commands.Cog):
return return
self.logger.info(f'Found "{song}" ({romanize(song.name)[1]}).') self.logger.info(f'Found "{song}" ({romanize(song.name)[1]}).')
chart: ChartMaster = song.charts[difficulty] embeds, files = self.get_chart_embed_info(song)
message = await ctx.send(files=files, embed=embeds[difficulty - 1])
reaction_emote_ids = [
790050636568723466,
790050636489555998,
790050636548276252,
790050636225052694,
]
for emote_id in reaction_emote_ids:
await message.add_reaction(self.bot.get_emoji(emote_id))
def check(rxn, usr):
return usr == ctx.author and rxn.emoji.id in reaction_emote_ids
while True:
try:
reaction, user = await self.bot.wait_for('reaction_add', timeout=60, check=check)
self.logger.debug(f'Reaction {reaction} from user {user}.')
emote_index = reaction_emote_ids.index(reaction.emoji.id)
await message.edit(embed=embeds[emote_index])
await message.remove_reaction(reaction, user)
except asyncio.TimeoutError:
break
def get_chart_embed_info(self, song):
embeds = []
files = [discord.File(song.jacket_path, filename=f'jacket.png')]
for difficulty in [ChartDifficulty.Easy, ChartDifficulty.Normal, ChartDifficulty.Hard, ChartDifficulty.Expert]:
chart = song.charts[difficulty]
embed = discord.Embed(title=f'{song.name} [{chart.difficulty.name}]')
embed.set_thumbnail(url=f'attachment://jacket.png')
embed.set_image(
url=f'https://qwewqa.github.io/d4dj-dumps/{chart.image_path.relative_to(asset_manager.path).as_posix()}'
)
chart_data = chart.load_chart_data() chart_data = chart.load_chart_data()
note_counts = chart_data.get_note_counts() note_counts = chart_data.get_note_counts()
thumb = discord.File(song.jacket_path, filename='jacket.png')
render = discord.File(chart.image_path, filename='render.png')
embed = discord.Embed(title=f'{song.name} [{difficulty.name}]')
embed.set_thumbnail(url=f'attachment://jacket.png')
embed.set_image(url=f'attachment://render.png')
embed.add_field(name='Info', embed.add_field(name='Info',
value=f'Level: {chart.display_level}\n' value=f'Level: {chart.display_level}\n'
f'Unit: {song.special_unit_name or song.unit.name}\n' f'Unit: {song.special_unit_name or song.unit.name}\n'
@ -146,7 +176,9 @@ class Music(commands.Cog):
inline=True) inline=True)
embed.set_footer(text='1 column = 10 seconds') embed.set_footer(text='1 column = 10 seconds')
await ctx.send(files=[thumb, render], embed=embed) embeds.append(embed)
return embeds, files
def setup(bot): def setup(bot):

Loading…
Cancel
Save