use emoji directly in reaction messages

pull/1/head
qwewqa 4 years ago
parent 16c8b4ebec
commit a1123a0582
  1. 20
      miyu_bot/commands/cogs/event.py
  2. 30
      miyu_bot/commands/cogs/music.py
  3. 16
      miyu_bot/commands/common/emoji.py
  4. 11
      miyu_bot/commands/common/fuzzy_matching.py
  5. 27
      miyu_bot/commands/common/reaction_message.py

@ -6,8 +6,8 @@ from d4dj_utils.master.event_master import EventMaster, EventState
from discord.ext import commands
from main import asset_manager
from miyu_bot.commands.common.emoji import attribute_emoji_by_id, unit_emoji_by_id, parameter_bonus_emoji_by_id, \
event_point_emoji
from miyu_bot.commands.common.emoji import attribute_emoji_ids_by_attribute_id, unit_emoji_ids_by_unit_id, parameter_bonus_emoji_ids_by_parameter_id, \
event_point_emoji_id
from miyu_bot.commands.common.formatting import format_info
from miyu_bot.commands.common.fuzzy_matching import FuzzyMap, romanize
@ -69,26 +69,26 @@ class Event(commands.Cog):
inline=True)
embed.add_field(name='Bonus Characters',
value='\n'.join(
f'{self.bot.get_emoji(unit_emoji_by_id[char.unit_id])} {char.full_name_english}'
f'{self.bot.get_emoji(unit_emoji_ids_by_unit_id[char.unit_id])} {char.full_name_english}'
for char in event.bonus.characters
),
inline=True)
embed.add_field(name='Bonus Attribute',
value=f'{self.bot.get_emoji(attribute_emoji_by_id[event.bonus.attribute_id])} '
value=f'{self.bot.get_emoji(attribute_emoji_ids_by_attribute_id[event.bonus.attribute_id])} '
f'{event.bonus.attribute.en_name.capitalize()}' if event.bonus.attribute else 'None',
inline=True)
embed.add_field(name='Point Bonus',
value=format_info({
'Attribute': f'{self.bot.get_emoji(event_point_emoji)} +{event.bonus.attribute_match_point_bonus_value}%' if event.bonus.attribute_match_point_bonus_value else 'None',
'Character': f'{self.bot.get_emoji(event_point_emoji)} +{event.bonus.character_match_point_bonus_value}%' if event.bonus.character_match_point_bonus_value else 'None',
'Both': f'{self.bot.get_emoji(event_point_emoji)} +{event.bonus.all_match_point_bonus_value}%' if event.bonus.all_match_point_bonus_value else 'None',
'Attribute': f'{self.bot.get_emoji(event_point_emoji_id)} +{event.bonus.attribute_match_point_bonus_value}%' if event.bonus.attribute_match_point_bonus_value else 'None',
'Character': f'{self.bot.get_emoji(event_point_emoji_id)} +{event.bonus.character_match_point_bonus_value}%' if event.bonus.character_match_point_bonus_value else 'None',
'Both': f'{self.bot.get_emoji(event_point_emoji_id)} +{event.bonus.all_match_point_bonus_value}%' if event.bonus.all_match_point_bonus_value else 'None',
}),
inline=True)
embed.add_field(name='Parameter Bonus',
value=format_info({
'Attribute': f'{self.bot.get_emoji(parameter_bonus_emoji_by_id[event.bonus.attribute_match_parameter_bonus_id])} +{event.bonus.attribute_match_parameter_bonus_value}%' if event.bonus.attribute_match_parameter_bonus_value else 'None',
'Character': f'{self.bot.get_emoji(parameter_bonus_emoji_by_id[event.bonus.character_match_parameter_bonus_id])} +{event.bonus.attribute_match_parameter_bonus_value}%' if event.bonus.attribute_match_parameter_bonus_value else 'None',
'Both': f'{self.bot.get_emoji(parameter_bonus_emoji_by_id[event.bonus.all_match_parameter_bonus_id])} +{event.bonus.all_match_parameter_bonus_value}%' if event.bonus.all_match_parameter_bonus_value else 'None',
'Attribute': f'{self.bot.get_emoji(parameter_bonus_emoji_ids_by_parameter_id[event.bonus.attribute_match_parameter_bonus_id])} +{event.bonus.attribute_match_parameter_bonus_value}%' if event.bonus.attribute_match_parameter_bonus_value else 'None',
'Character': f'{self.bot.get_emoji(parameter_bonus_emoji_ids_by_parameter_id[event.bonus.character_match_parameter_bonus_id])} +{event.bonus.attribute_match_parameter_bonus_value}%' if event.bonus.attribute_match_parameter_bonus_value else 'None',
'Both': f'{self.bot.get_emoji(parameter_bonus_emoji_ids_by_parameter_id[event.bonus.all_match_parameter_bonus_id])} +{event.bonus.all_match_parameter_bonus_value}%' if event.bonus.all_match_parameter_bonus_value else 'None',
}),
inline=True)
embed.set_footer(text=f'Event Id: {event.id}')

@ -1,5 +1,7 @@
import asyncio
import contextlib
import logging
import wave
from typing import Optional, Tuple
import discord
@ -9,10 +11,10 @@ from d4dj_utils.master.music_master import MusicMaster
from discord.ext import commands
from main import asset_manager
from miyu_bot.commands.common.emoji import difficulty_emoji_id
from miyu_bot.commands.common.emoji import difficulty_emoji_ids
from miyu_bot.commands.common.formatting import format_info
from miyu_bot.commands.common.fuzzy_matching import romanize, FuzzyMap
from miyu_bot.commands.common.reaction_message import make_tabbed_message
from miyu_bot.commands.common.reaction_message import run_tabbed_message
class Music(commands.Cog):
@ -24,6 +26,10 @@ class Music(commands.Cog):
if not self.music.has_exact(f'{m.name} {m.special_unit_name}'):
self.music[f'{m.name} {m.special_unit_name}'] = m
@property
def reaction_emojis(self):
return [self.bot.get_emoji(eid) for eid in difficulty_emoji_ids.values()]
difficulty_names = {
'expert': ChartDifficulty.Expert,
'hard': ChartDifficulty.Hard,
@ -108,14 +114,7 @@ class Music(commands.Cog):
message = await ctx.send(files=files, embed=embeds[difficulty - 1])
reaction_emoji_ids = [
790050636568723466,
790050636489555998,
790050636548276252,
790050636225052694,
]
asyncio.ensure_future(make_tabbed_message(ctx, message, reaction_emoji_ids, embeds))
asyncio.ensure_future(run_tabbed_message(ctx, message, self.reaction_emojis, embeds))
@commands.command(name='sections',
aliases=['mixes'],
@ -143,9 +142,16 @@ class Music(commands.Cog):
message = await ctx.send(files=files, embed=embeds[difficulty - 1])
reaction_emoji_ids = difficulty_emoji_id.values()
asyncio.ensure_future(run_tabbed_message(ctx, message, self.reaction_emojis, embeds))
asyncio.ensure_future(make_tabbed_message(ctx, message, reaction_emoji_ids, embeds))
@commands.command(name='songs',
aliases=['search_songs'],
description='Finds songs matching the given name.',
help='!songs grgr')
async def songs(self, ctx: commands.Context, *, arg: str):
self.logger.info(f'Searching for songs sections "{arg}".')
songs = self.music.get_sorted(arg)
return
def get_chart_embed_info(self, song):
embeds = []

@ -1,6 +1,6 @@
from d4dj_utils.master.chart_master import ChartDifficulty
difficulty_emoji_id = {
difficulty_emoji_ids = {
ChartDifficulty.Easy: 790050636568723466,
ChartDifficulty.Normal: 790050636489555998,
ChartDifficulty.Hard: 790050636548276252,
@ -8,16 +8,16 @@ difficulty_emoji_id = {
}
# \:buff_power: \:buff_heart: \:buff_technique: \:buff_physical:
parameter_bonus_emoji = {
parameter_bonus_emoji_Ids = {
'all': 792095555634331668,
'heart': 792096971040620564,
'technique': 792096971090558986,
'physical': 792096971002216488,
}
parameter_bonus_emoji_by_id = {i: v for i, v in enumerate(parameter_bonus_emoji.values())}
parameter_bonus_emoji_ids_by_parameter_id = {i: v for i, v in enumerate(parameter_bonus_emoji_Ids.values())}
unit_emoji = {
unit_emoji_ids = {
'happy_around': 792069679442821121,
'peaky_pkey': 792076165916524544,
'photon_maiden': 792069679455535136,
@ -26,9 +26,9 @@ unit_emoji = {
'lyrical_lily': 792069679673114644,
}
unit_emoji_by_id = {i + 1: v for i, v in enumerate(unit_emoji.values())}
unit_emoji_ids_by_unit_id = {i + 1: v for i, v in enumerate(unit_emoji_ids.values())}
attribute_emoji = {
attribute_emoji_ids = {
'street': 791903477986361345,
'party': 791903477999599677,
'cute': 791903477743616003,
@ -36,6 +36,6 @@ attribute_emoji = {
'elegant': 791903477969321985,
}
attribute_emoji_by_id = {i + 1: v for i, v in enumerate(attribute_emoji.values())}
attribute_emoji_ids_by_attribute_id = {i + 1: v for i, v in enumerate(attribute_emoji_ids.values())}
event_point_emoji = 792097816931598336
event_point_emoji_id = 792097816931598336

@ -44,6 +44,17 @@ class FuzzyMap:
self.logger.info(f'Found key "{key}" in time {timeit.default_timer() - start_time}.')
return self._values[result]
def get_sorted(self, key: str):
start_time = timeit.default_timer()
if len(key) > self.max_length:
self.logger.debug(f'Rejected key "{key}" due to length.')
return []
key = romanize(key)
values = [item[1] for score, item in
sorted((self.matcher.score(key, item[0]), item) for item in self._values.items()) if score <= 0]
self.logger.info(f'Searched key "{key}" in time {timeit.default_timer() - start_time}.')
return values
class FuzzyDictValuesView:
def __init__(self, map: FuzzyMap):

@ -1,33 +1,32 @@
import asyncio
from typing import List, Callable, Awaitable
import discord
from discord import Message, Embed, Emoji
from discord.ext.commands import Context
async def make_tabbed_message(ctx: Context, message: Message, emoji_ids: List[int], embeds: List[Embed], timeout=300):
emoji_ids = list(emoji_ids)
async def run_tabbed_message(ctx: Context, message: Message, emojis: List[Emoji], embeds: List[Embed], timeout=300):
async def callback(emoji, _ctx, _message):
await message.edit(embed=embeds[emojis.index(emoji)])
async def callback(emoji_id, _ctx, _message):
await message.edit(embed=embeds[emoji_ids.index(emoji_id)])
await run_reaction_message(ctx, message, emojis, callback, timeout)
await make_reaction_message(ctx, message, emoji_ids, callback, timeout)
async def make_reaction_message(ctx: Context, message: Message, emoji_ids: List[int],
callback: Callable[[int, Context, Message], Awaitable[None]], timeout=300):
for emoji_id in emoji_ids:
await message.add_reaction(ctx.bot.get_emoji(emoji_id))
async def run_reaction_message(ctx: Context, message: Message, emojis: List[Emoji],
callback: Callable[[Emoji, Context, Message], Awaitable[None]], timeout=300):
for emoji in emojis:
await message.add_reaction(emoji)
def check(rxn, usr):
return usr == ctx.author and rxn.emoji.id in emoji_ids and rxn.message.id == message.id
return usr == ctx.author and rxn.emoji in emojis and rxn.message.id == message.id
while True:
try:
reaction, user = await ctx.bot.wait_for('reaction_add', timeout=timeout, check=check)
await callback(reaction.emoji.id, ctx, message)
await callback(reaction.emoji, ctx, message)
await message.remove_reaction(reaction, user)
except asyncio.TimeoutError:
for emoji_id in emoji_ids:
await message.remove_reaction(ctx.bot.get_emoji(emoji_id), ctx.bot.user)
for emoji in emojis:
await message.remove_reaction(ctx.bot.get_emoji(emoji), ctx.bot.user)
break

Loading…
Cancel
Save