add t20 command

pull/1/head
qwewqa 4 years ago
parent 20e1339976
commit 9c29b8067d
  1. 30
      miyu_bot/commands/cogs/event.py
  2. 7
      miyu_bot/commands/cogs/music.py
  3. 17
      miyu_bot/commands/common/reaction_message.py

@ -1,6 +1,9 @@
import asyncio
import datetime as dt
import logging
import aiohttp
import dateutil.parser
import discord
import pytz
from d4dj_utils.master.event_master import EventMaster, EventState
@ -14,6 +17,7 @@ from miyu_bot.commands.common.emoji import attribute_emoji_ids_by_attribute_id,
from miyu_bot.commands.common.formatting import format_info
from miyu_bot.commands.common.fuzzy_matching import romanize
from miyu_bot.commands.common.master_asset_manager import MasterFilter
from miyu_bot.commands.common.reaction_message import run_paged_message
class Event(commands.Cog):
@ -109,7 +113,8 @@ class Event(commands.Cog):
def format_time(t: dt.datetime):
return str(t.replace(microsecond=0))
embed.add_field(name='Asia/Tokyo', value=format_time(dt.datetime.now(pytz.timezone('Asia/Tokyo'))), inline=False)
embed.add_field(name='Asia/Tokyo', value=format_time(dt.datetime.now(pytz.timezone('Asia/Tokyo'))),
inline=False)
if arg:
try:
@ -194,6 +199,29 @@ class Event(commands.Cog):
except ValueError:
return max(masters.events.values(ctx), key=lambda v: v.start_datetime)
@commands.command(name='t20',
aliases=['top20', 'top_20'],
description='Displays the top 20 in the main leaderboard',
help='!t20')
async def time_left(self, ctx: commands.Context):
async with aiohttp.ClientSession() as session:
async with session.get('http://www.projectdivar.com/eventdata/t20') as resp:
leaderboard = await resp.json(encoding='utf-8')
latest = self.get_latest_event(ctx)
logo = discord.File(latest.logo_path, filename='logo.png')
embed = discord.Embed(title=f'{latest.name} t20').set_thumbnail(url=f'attachment://logo.png')
max_points_digits = len(str(leaderboard[0]['points']))
nl = "\n"
update_date = dateutil.parser.isoparse(leaderboard[0]["date"]).replace(microsecond=0)
update_date = update_date.astimezone(pytz.timezone('Asia/Tokyo'))
header = f'Updated {update_date}\n\nRank {"Points".ljust(max_points_digits)} Name'
listing = [
f'{str(player["rank"]).ljust(4)} {str(player["points"]).ljust(max_points_digits)} {player["name"].replace(nl, "")}'
for player in leaderboard]
paged = run_paged_message(ctx, embed, listing, header=header, page_size=10, files=[logo], numbered=False)
asyncio.ensure_future(paged)
def setup(bot):
bot.add_cog(Event(bot))

@ -153,7 +153,7 @@ class Music(commands.Cog):
sort = 'relevance'
if not arg:
sort = 'default'
elif arg == 'duration':
elif arg == 'sort=duration':
sort = 'duration'
arg = ''
songs = masters.music.get_sorted(arg, ctx)
@ -169,9 +169,8 @@ class Music(commands.Cog):
songs = sorted(songs, key=lambda s: -s.default_order)
listing = [f'{song.name}{" (" + song.special_unit_name + ")" if song.special_unit_name else ""}' for song in
[*songs[1:], songs[0]]] # lesson is always first
asyncio.ensure_future(run_paged_message(ctx, f'Song Search "{arg}"' if arg else 'Songs', listing))
return
embed = discord.Embed(title='Song Search "{arg}"' if arg else 'Songs')
asyncio.ensure_future(run_paged_message(ctx, embed, listing))
def get_chart_embed_info(self, song):
embeds = []

@ -18,13 +18,16 @@ async def run_tabbed_message(ctx: Context, message: Message, emojis: List[AnyEmo
await run_reaction_message(ctx, message, emojis, callback, timeout)
async def run_paged_message(ctx: Context, title: str, content: List[str], page_size: int = 15, numbered: bool = True,
timeout=300, max_tabbed_pages=4):
async def run_paged_message(ctx: Context, base_embed: discord.Embed, content: List[str], page_size: int = 15,
header='', numbered: bool = True, timeout=300, max_tabbed_pages=4, files=None):
if header:
header = header + '\n'
if max_tabbed_pages > 9:
raise ValueError('max_tabbed_pages must be 9 or less.')
if not content:
embed = discord.Embed(title=title).set_footer(text='Page 0/0')
embed = base_embed.copy().set_footer(text='Page 0/0')
await ctx.send(embed=embed)
return
@ -42,11 +45,13 @@ async def run_paged_message(ctx: Context, title: str, content: List[str], page_s
return str(item)
embeds = [
discord.Embed(title=title, description='```' + '\n'.join((format_item(i) for i in page)) + '```').set_footer(
text=f'Page {i + 1}/{len(page_contents)}')
base_embed.from_dict({
**base_embed.to_dict(),
'description': '```' + header + '\n'.join((format_item(i) for i in page)) + '```',
}).set_footer(text=f'Page {i + 1}/{len(page_contents)}')
for i, page in enumerate(page_contents)]
message = await ctx.send(embed=embeds[0])
message = await ctx.send(embed=embeds[0], files=files or [])
if len(embeds) == 1:
return

Loading…
Cancel
Save