parent
9c8665e312
commit
550b63f60c
@ -0,0 +1,95 @@ |
||||
import datetime |
||||
import logging |
||||
|
||||
import discord |
||||
from d4dj_utils.master.event_master import EventMaster |
||||
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.formatting import format_info |
||||
from miyu_bot.commands.common.fuzzy_matching import FuzzyMap, romanize |
||||
|
||||
|
||||
class Event(commands.Cog): |
||||
def __init__(self, bot: commands.Bot): |
||||
self.bot = bot |
||||
self.logger = logging.getLogger(__name__) |
||||
self.events = FuzzyMap( |
||||
lambda e: e.start_datetime < datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=-8) |
||||
) |
||||
for e in asset_manager.event_master.values(): |
||||
self.events[e.name] = e |
||||
|
||||
@commands.command(name='event', |
||||
aliases=['ev'], |
||||
description='Finds the event with the given name.', |
||||
help='!event pkcooking') |
||||
async def event(self, ctx: commands.Context, *, arg: str): |
||||
self.logger.info(f'Searching for event "{arg}".') |
||||
|
||||
event: EventMaster |
||||
try: |
||||
event = asset_manager.event_master[int(arg)] |
||||
if event not in self.events.values(): |
||||
event = self.events[arg] |
||||
except (ValueError, KeyError): |
||||
event = self.events[arg] |
||||
|
||||
if not event: |
||||
msg = f'Failed to find event "{arg}".' |
||||
await ctx.send(msg) |
||||
self.logger.info(msg) |
||||
return |
||||
self.logger.info(f'Found event "{event}" ({romanize(event.name)}).') |
||||
|
||||
logo = discord.File(event.logo_path, filename='logo.png') |
||||
|
||||
embed = discord.Embed(title=event.name) |
||||
embed.set_thumbnail(url=f'attachment://logo.png') |
||||
|
||||
embed.add_field(name='Dates', |
||||
value=format_info({ |
||||
'Start': event.start_datetime, |
||||
'Close': event.reception_close_datetime, |
||||
'Rank Fix': event.rank_fix_start_datetime, |
||||
'Results': event.result_announcement_datetime, |
||||
'End': event.end_datetime, |
||||
'Story Unlock': event.story_unlock_datetime, |
||||
'Status': event.state().name, |
||||
}), |
||||
inline=False) |
||||
embed.add_field(name='Event Type', |
||||
value=event.event_type.name, |
||||
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}' |
||||
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])} ' |
||||
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', |
||||
}), |
||||
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', |
||||
}), |
||||
inline=True) |
||||
|
||||
await ctx.send(files=[logo], embed=embed) |
||||
|
||||
|
||||
def setup(bot): |
||||
bot.add_cog(Event(bot)) |
@ -0,0 +1,41 @@ |
||||
from d4dj_utils.master.chart_master import ChartDifficulty |
||||
|
||||
difficulty_emoji_id = { |
||||
ChartDifficulty.Easy: 790050636568723466, |
||||
ChartDifficulty.Normal: 790050636489555998, |
||||
ChartDifficulty.Hard: 790050636548276252, |
||||
ChartDifficulty.Expert: 790050636225052694, |
||||
} |
||||
|
||||
# \:buff_power: \:buff_heart: \:buff_technique: \:buff_physical: |
||||
parameter_bonus_emoji = { |
||||
'all': 792095555634331668, |
||||
'heart': 792096971040620564, |
||||
'technique': 792096971090558986, |
||||
'physical': 792096971002216488, |
||||
} |
||||
|
||||
parameter_bonus_emoji_by_id = {i: v for i, v in enumerate(parameter_bonus_emoji.values())} |
||||
|
||||
unit_emoji = { |
||||
'happy_around': 792069679442821121, |
||||
'peaky_pkey': 792076165916524544, |
||||
'photon_maiden': 792069679455535136, |
||||
'merm4id': 792069679874310184, |
||||
'rondo': 792069679770238976, |
||||
'lyrical_lily': 792069679673114644, |
||||
} |
||||
|
||||
unit_emoji_by_id = {i + 1: v for i, v in enumerate(unit_emoji.values())} |
||||
|
||||
attribute_emoji = { |
||||
'street': 791903477986361345, |
||||
'party': 791903477999599677, |
||||
'cute': 791903477743616003, |
||||
'cool': 791903477700755466, |
||||
'elegant': 791903477969321985, |
||||
} |
||||
|
||||
attribute_emoji_by_id = {i + 1: v for i, v in enumerate(attribute_emoji.values())} |
||||
|
||||
event_point_emoji = 792097816931598336 |
@ -0,0 +1,2 @@ |
||||
def format_info(info_entries: dict): |
||||
return '\n'.join(f'{k}: {v}' for k, v in info_entries.items() if v) |
@ -1,32 +1,33 @@ |
||||
import asyncio |
||||
from typing import List, Callable, Awaitable |
||||
|
||||
from discord import Message, Embed |
||||
from discord import Message, Embed, Emoji |
||||
from discord.ext.commands import Context |
||||
|
||||
|
||||
async def make_tabbed_message(ctx: Context, message: Message, emote_ids: List[int], embeds: List[Embed], timeout=300): |
||||
async def callback(index, _ctx, _message): |
||||
await message.edit(embed=embeds[index]) |
||||
async def make_tabbed_message(ctx: Context, message: Message, emoji_ids: List[int], embeds: List[Embed], timeout=300): |
||||
emoji_ids = list(emoji_ids) |
||||
|
||||
await make_reaction_message(ctx, message, emote_ids, callback, timeout) |
||||
async def callback(emoji_id, _ctx, _message): |
||||
await message.edit(embed=embeds[emoji_ids.index(emoji_id)]) |
||||
|
||||
await make_reaction_message(ctx, message, emoji_ids, callback, timeout) |
||||
|
||||
async def make_reaction_message(ctx: Context, message: Message, emote_ids: List[int], |
||||
callback: Callable[[int, Context, Message], Awaitable[None]], timeout = 300): |
||||
for emote_id in emote_ids: |
||||
await message.add_reaction(ctx.bot.get_emoji(emote_id)) |
||||
|
||||
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)) |
||||
|
||||
def check(rxn, usr): |
||||
return usr == ctx.author and rxn.emoji.id in emote_ids and rxn.message.id == message.id |
||||
return usr == ctx.author and rxn.emoji.id in emoji_ids and rxn.message.id == message.id |
||||
|
||||
while True: |
||||
try: |
||||
reaction, user = await ctx.bot.wait_for('reaction_add', timeout=timeout, check=check) |
||||
emote_index = emote_ids.index(reaction.emoji.id) |
||||
await callback(emote_index, ctx, message) |
||||
await callback(reaction.emoji.id, ctx, message) |
||||
await message.remove_reaction(reaction, user) |
||||
except asyncio.TimeoutError: |
||||
for emote_id in emote_ids: |
||||
await message.remove_reaction(ctx.bot.get_emoji(emote_id), ctx.bot.user) |
||||
for emoji_id in emoji_ids: |
||||
await message.remove_reaction(ctx.bot.get_emoji(emoji_id), ctx.bot.user) |
||||
break |
||||
|
Loading…
Reference in new issue