From 9c8665e312f2b7e684bbc5571107188582ec03e5 Mon Sep 17 00:00:00 2001 From: qwewqa <198e559dbd446d973355f415bdfa34@gmail.com> Date: Tue, 22 Dec 2020 04:07:00 -0500 Subject: [PATCH] add music section command --- miyu_bot/commands/cogs/music.py | 97 +++++++++++++++++++++- miyu_bot/commands/common/fuzzy_matching.py | 1 + update_assets.py | 2 +- 3 files changed, 98 insertions(+), 2 deletions(-) diff --git a/miyu_bot/commands/cogs/music.py b/miyu_bot/commands/cogs/music.py index 06d8524..f2a4673 100644 --- a/miyu_bot/commands/cogs/music.py +++ b/miyu_bot/commands/cogs/music.py @@ -19,7 +19,7 @@ class Music(commands.Cog): self.music = self.get_music() def get_music(self): - music = FuzzyMap(lambda m: m.is_released and not m.is_tutorial) + music = FuzzyMap(lambda m: m.is_released) for m in asset_manager.music_master.values(): music[f'{m.name} {m.special_unit_name}'] = m return music @@ -126,6 +126,48 @@ class Music(commands.Cog): asyncio.ensure_future(make_tabbed_message(ctx, message, reaction_emote_ids, embeds)) + @commands.command(name='sections', + aliases=['mixes'], + description='Finds the sections of the chart with the given name.', + help='!sections grgr') + async def sections(self, ctx: commands.Context, *, arg: str): + self.logger.info(f'Searching for chart sections "{arg}".') + + split_args = arg.split() + + difficulty = ChartDifficulty.Expert + if len(split_args) >= 2: + final_word = split_args[-1] + if final_word in self.difficulty_names: + difficulty = self.difficulty_names[final_word] + arg = ''.join(split_args[:-1]) + + song: MusicMaster = self.music[arg] + if not song: + msg = f'Failed to find chart "{arg}".' + await ctx.send(msg) + self.logger.info(msg) + return + if not song.enable_long_mix: + msg = f'Song "{song.name}" does not have mix enabled.' + await ctx.send(msg) + self.logger.info(msg) + return + self.logger.info(f'Found "{song}" ({romanize(song.name)[1]}).') + + embeds, files = self.get_mix_embed_info(song) + + message = await ctx.send(files=files, embed=embeds[difficulty - 1]) + + reaction_emote_ids = [ + 790050636568723466, + 790050636489555998, + 790050636548276252, + 790050636225052694, + ] + + asyncio.ensure_future(make_tabbed_message(ctx, message, reaction_emote_ids, embeds)) + def get_chart_embed_info(self, song): embeds = [] files = [discord.File(song.jacket_path, filename=f'jacket.png')] @@ -167,6 +209,59 @@ class Music(commands.Cog): return embeds, files + def get_mix_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: ChartMaster = song.charts[difficulty] + embed = discord.Embed(title=f'Mix: {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.mix_path.relative_to(asset_manager.path).as_posix()}' + ) + + note_counts = chart.note_counts + mix_info = chart.mix_info + + info = { + 'Level': chart.display_level, + 'Unit': song.unit.name, + 'BPM': song.bpm, + 'Section Trend': song.section_trend.name, + } + + begin = { + 'Time': f'{round(mix_info[ChartSectionType.Begin].duration, 2)}s', + 'Combo': note_counts[ChartSectionType.Begin].count, + } + middle = { + 'Time': f'{round(mix_info[ChartSectionType.Middle].duration, 2)}s', + 'Combo': note_counts[ChartSectionType.Middle].count, + } + end = { + 'Time': f'{round(mix_info[ChartSectionType.End].duration, 2)}s', + 'Combo': note_counts[ChartSectionType.End].count, + } + + embed.add_field(name='Info', + value=self.format_info(info), + inline=False) + embed.add_field(name='Begin', + value=self.format_info(begin), + inline=True) + embed.add_field(name='Middle', + value=self.format_info(middle), + inline=True) + embed.add_field(name='End', + value=self.format_info(end), + inline=True) + embed.set_footer(text='1 column = 10 seconds') + + embeds.append(embed) + + return embeds, files + def setup(bot): bot.add_cog(Music(bot)) diff --git a/miyu_bot/commands/common/fuzzy_matching.py b/miyu_bot/commands/common/fuzzy_matching.py index a9eac6e..b3ea293 100644 --- a/miyu_bot/commands/common/fuzzy_matching.py +++ b/miyu_bot/commands/common/fuzzy_matching.py @@ -52,6 +52,7 @@ class FuzzyMatchConfig: special_substitution_weights: Dict[Tuple[str, str], float] = field(default_factory=lambda: { ('v', 'b'): 0.0, ('l', 'r'): 0.0, + ('c', 'k'): 0.0, }) word_match_weight: float = -0.2 acronym_match_weight: float = -0.3 diff --git a/update_assets.py b/update_assets.py index 3495024..740dfb6 100644 --- a/update_assets.py +++ b/update_assets.py @@ -12,7 +12,7 @@ async def main(): await revision_manager.repair_downloads() await revision_manager.update_assets() manager = AssetManager('assets') - manager.render_charts() + manager.render_charts_by_master() if __name__ == '__main__':