add base asset url to bot class

pull/1/head
qwewqa 4 years ago
parent 777e423aa5
commit 4200658897
  1. 2
      miyu_bot/bot/bot.py
  2. 8
      miyu_bot/commands/cogs/card.py
  3. 18
      miyu_bot/commands/cogs/event.py
  4. 54
      miyu_bot/commands/cogs/music.py
  5. 2
      miyu_bot/commands/common/asset_paths.py
  6. 2
      miyu_bot/commands/common/reaction_message.py

@ -10,6 +10,8 @@ class D4DJBot(commands.Bot):
asset_filters: MasterFilterManager asset_filters: MasterFilterManager
aliases: NameAliases aliases: NameAliases
asset_url = 'https://qwewqa.github.io/d4dj-dumps/'
def __init__(self, assets, asset_filters, *args, **kwargs): def __init__(self, assets, asset_filters, *args, **kwargs):
self.assets = assets self.assets = assets
self.asset_filters = asset_filters self.asset_filters = asset_filters

@ -10,6 +10,7 @@ from discord.ext import commands
from miyu_bot.bot.bot import D4DJBot from miyu_bot.bot.bot import D4DJBot
from miyu_bot.commands.common.argument_parsing import ParsedArguments, parse_arguments, ArgumentError from miyu_bot.commands.common.argument_parsing import ParsedArguments, parse_arguments, ArgumentError
from miyu_bot.commands.common.asset_paths import get_card_icon_path, get_card_art_path
from miyu_bot.commands.common.emoji import rarity_emoji_ids, attribute_emoji_ids_by_attribute_id, \ from miyu_bot.commands.common.emoji import rarity_emoji_ids, attribute_emoji_ids_by_attribute_id, \
unit_emoji_ids_by_unit_id, parameter_bonus_emoji_ids_by_parameter_id unit_emoji_ids_by_unit_id, parameter_bonus_emoji_ids_by_parameter_id
from miyu_bot.commands.common.formatting import format_info from miyu_bot.commands.common.formatting import format_info
@ -173,11 +174,8 @@ class Card(commands.Cog):
def get_card_embed(self, card: CardMaster, limit_break): def get_card_embed(self, card: CardMaster, limit_break):
embed = discord.Embed(title=self.format_card_name(card)) embed = discord.Embed(title=self.format_card_name(card))
card_hash = hash_master(card) thumb_url = self.bot.asset_url + get_card_icon_path(card, limit_break)
icon_path = card.icon_path(limit_break) art_url = self.bot.asset_url + get_card_art_path(card, limit_break)
thumb_url = f'https://qwewqa.github.io/d4dj-dumps/cards/icons/{icon_path.stem}_{card_hash}{icon_path.suffix}'
art_path = card.art_path(limit_break)
art_url = f'https://qwewqa.github.io/d4dj-dumps/cards/art/{art_path.stem}_{card_hash}{art_path.suffix}'
embed.set_thumbnail(url=thumb_url) embed.set_thumbnail(url=thumb_url)
embed.set_image(url=art_url) embed.set_image(url=art_url)

@ -12,6 +12,7 @@ from pytz import UnknownTimeZoneError
from miyu_bot.bot.bot import D4DJBot from miyu_bot.bot.bot import D4DJBot
from miyu_bot.commands.common.argument_parsing import parse_arguments, ArgumentError from miyu_bot.commands.common.argument_parsing import parse_arguments, ArgumentError
from miyu_bot.commands.common.asset_paths import get_event_logo_path
from miyu_bot.commands.common.emoji import attribute_emoji_ids_by_attribute_id, unit_emoji_ids_by_unit_id, \ 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, \ parameter_bonus_emoji_ids_by_parameter_id, \
event_point_emoji_id event_point_emoji_id
@ -85,10 +86,7 @@ class Event(commands.Cog):
def get_event_embed(self, event, timezone): def get_event_embed(self, event, timezone):
embed = discord.Embed(title=event.name) embed = discord.Embed(title=event.name)
event_hash = hash_master(event) embed.set_thumbnail(url=self.bot.asset_url + get_event_logo_path(event))
event_logo_path = event.logo_path
embed.set_thumbnail(
url=f'https://qwewqa.github.io/d4dj-dumps/events/logos/{event_logo_path.stem}_{event_hash}{event_logo_path.suffix}')
duration_hour_part = round((event.duration.seconds / 3600), 2) duration_hour_part = round((event.duration.seconds / 3600), 2)
duration_hour_part = duration_hour_part if not duration_hour_part.is_integer() else int(duration_hour_part) duration_hour_part = duration_hour_part if not duration_hour_part.is_integer() else int(duration_hour_part)
@ -178,10 +176,7 @@ class Event(commands.Cog):
embed = discord.Embed(title=event.name) embed = discord.Embed(title=event.name)
event_hash = hash_master(event) embed.set_thumbnail(url=self.bot.asset_url + get_event_logo_path(event))
event_logo_path = event.logo_path
embed.set_thumbnail(
url=f'https://qwewqa.github.io/d4dj-dumps/events/logos/{event_logo_path.stem}_{event_hash}{event_logo_path.suffix}')
progress = None progress = None
@ -238,12 +233,9 @@ class Event(commands.Cog):
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get('http://www.projectdivar.com/eventdata/t20') as resp: async with session.get('http://www.projectdivar.com/eventdata/t20') as resp:
leaderboard = await resp.json(encoding='utf-8') leaderboard = await resp.json(encoding='utf-8')
event = self.bot.asset_filters.events.get_latest_event(ctx) event = self.bot.asset_filters.events.get_latest_event(ctx)
event_hash = hash_master(event) embed = discord.Embed(title=f'{event.name} t20')
event_logo_path = event.logo_path embed.set_thumbnail(url=self.bot.asset_url + get_event_logo_path(event))
embed = discord.Embed(title=f'{event.name} t20').set_thumbnail(
url=f'https://qwewqa.github.io/d4dj-dumps/events/logos/{event_logo_path.stem}_{event_hash}{event_logo_path.suffix}')
max_points_digits = len(str(leaderboard[0]['points'])) max_points_digits = len(str(leaderboard[0]['points']))
nl = "\n" nl = "\n"
update_date = dateutil.parser.isoparse(leaderboard[0]["date"]).replace(microsecond=0) update_date = dateutil.parser.isoparse(leaderboard[0]["date"]).replace(microsecond=0)

@ -14,10 +14,10 @@ from discord.ext import commands
from miyu_bot.bot.bot import D4DJBot from miyu_bot.bot.bot import D4DJBot
from miyu_bot.commands.common.argument_parsing import parse_arguments, ArgumentError, list_operator_for from miyu_bot.commands.common.argument_parsing import parse_arguments, ArgumentError, list_operator_for
from miyu_bot.commands.common.asset_paths import get_chart_image_path, get_music_jacket_path
from miyu_bot.commands.common.emoji import difficulty_emoji_ids from miyu_bot.commands.common.emoji import difficulty_emoji_ids
from miyu_bot.commands.common.formatting import format_info from miyu_bot.commands.common.formatting import format_info
from miyu_bot.commands.common.fuzzy_matching import romanize from miyu_bot.commands.common.fuzzy_matching import romanize
from miyu_bot.bot.master_asset_manager import hash_master
from miyu_bot.commands.common.reaction_message import run_tabbed_message, run_paged_message from miyu_bot.commands.common.reaction_message import run_tabbed_message, run_paged_message
@ -63,14 +63,8 @@ class Music(commands.Cog):
return return
self.logger.info(f'Found song "{song}" ({romanize(song.name)}).') self.logger.info(f'Found song "{song}" ({romanize(song.name)}).')
try:
thumb = discord.File(song.jacket_path, filename='jacket.png')
except FileNotFoundError:
# Just a fallback
thumb = discord.File(self.bot.assets.path / 'ondemand/stamp/stamp_10006.png', filename='jacket.png')
embed = discord.Embed(title=song.name) embed = discord.Embed(title=song.name)
embed.set_thumbnail(url=f'attachment://jacket.png') embed.set_thumbnail(url=self.bot.asset_url + get_music_jacket_path(song))
artist_info = { artist_info = {
'Lyricist': song.lyricist, 'Lyricist': song.lyricist,
@ -97,7 +91,7 @@ class Music(commands.Cog):
value=format_info(music_info), value=format_info(music_info),
inline=False) inline=False)
await ctx.send(files=[thumb], embed=embed) await ctx.send(embed=embed)
@commands.command(name='chart', @commands.command(name='chart',
aliases=[], aliases=[],
@ -116,10 +110,10 @@ class Music(commands.Cog):
return return
self.logger.info(f'Found song "{song}" ({romanize(song.name)}).') self.logger.info(f'Found song "{song}" ({romanize(song.name)}).')
embeds, files = self.get_chart_embed_info(song) embeds = self.get_chart_embeds(song)
# Difficulty enum easy-expert are 1-4, one more than the embed index # Difficulty enum easy-expert are 1-4, one more than the embed index
asyncio.ensure_future(run_tabbed_message(ctx, self.reaction_emojis, embeds, files, difficulty - 1)) asyncio.ensure_future(run_tabbed_message(ctx, self.reaction_emojis, embeds, None, difficulty - 1))
@commands.command(name='sections', @commands.command(name='sections',
aliases=['mixes'], aliases=['mixes'],
@ -143,9 +137,9 @@ class Music(commands.Cog):
return return
self.logger.info(f'Found song "{song}" ({romanize(song.name)}).') self.logger.info(f'Found song "{song}" ({romanize(song.name)}).')
embeds, files = self.get_mix_embed_info(song) embeds = self.get_mix_embeds(song)
asyncio.ensure_future(run_tabbed_message(ctx, self.reaction_emojis, embeds, files, difficulty - 1)) asyncio.ensure_future(run_tabbed_message(ctx, self.reaction_emojis, embeds, None, difficulty - 1))
@commands.command(name='songs', @commands.command(name='songs',
aliases=['songsearch', 'song_search'], aliases=['songsearch', 'song_search'],
@ -224,27 +218,14 @@ class Music(commands.Cog):
embed = discord.Embed(title=f'Song Search "{arg}"' if arg else 'Songs') embed = discord.Embed(title=f'Song Search "{arg}"' if arg else 'Songs')
asyncio.ensure_future(run_paged_message(ctx, embed, listing)) asyncio.ensure_future(run_paged_message(ctx, embed, listing))
def get_chart_embed_info(self, song): def get_chart_embeds(self, song):
embeds = [] embeds = []
try:
thumb = discord.File(song.jacket_path, filename='jacket.png')
except FileNotFoundError:
# fallback
thumb = discord.File(self.bot.assets.path / 'ondemand/stamp/stamp_10006.png', filename='jacket.png')
files = [thumb]
for difficulty in [ChartDifficulty.Easy, ChartDifficulty.Normal, ChartDifficulty.Hard, ChartDifficulty.Expert]: for difficulty in [ChartDifficulty.Easy, ChartDifficulty.Normal, ChartDifficulty.Hard, ChartDifficulty.Expert]:
chart = song.charts[difficulty] chart = song.charts[difficulty]
chart_hash = hash_master(chart)
chart_path = chart.image_path
embed = discord.Embed(title=f'{song.name} [{chart.difficulty.name}]') embed = discord.Embed(title=f'{song.name} [{chart.difficulty.name}]')
embed.set_thumbnail(url=f'attachment://jacket.png') embed.set_thumbnail(url=self.bot.asset_url + get_music_jacket_path(song))
embed.set_image( embed.set_image(url=self.bot.asset_url + get_chart_image_path(chart))
url=f'https://qwewqa.github.io/d4dj-dumps/music/charts/{chart_path.stem}_{chart_hash}{chart_path.suffix}'
)
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()
@ -274,21 +255,16 @@ class Music(commands.Cog):
embeds.append(embed) embeds.append(embed)
return embeds, files return embeds
def get_mix_embed_info(self, song): def get_mix_embeds(self, song):
embeds = [] embeds = []
files = [discord.File(song.jacket_path, filename=f'jacket.png')]
for difficulty in [ChartDifficulty.Easy, ChartDifficulty.Normal, ChartDifficulty.Hard, ChartDifficulty.Expert]: for difficulty in [ChartDifficulty.Easy, ChartDifficulty.Normal, ChartDifficulty.Hard, ChartDifficulty.Expert]:
chart: ChartMaster = song.charts[difficulty] chart: ChartMaster = song.charts[difficulty]
chart_hash = hash_master(chart)
mix_path = chart.mix_path
embed = discord.Embed(title=f'Mix: {song.name} [{chart.difficulty.name}]') embed = discord.Embed(title=f'Mix: {song.name} [{chart.difficulty.name}]')
embed.set_thumbnail(url=f'attachment://jacket.png') embed.set_thumbnail(url=self.bot.asset_url + get_music_jacket_path(song))
embed.set_image( embed.set_image(url=self.bot.asset_url + get_chart_image_path(chart))
url=f'https://qwewqa.github.io/d4dj-dumps/music/charts/{mix_path.stem}_{chart_hash}{mix_path.suffix}'
)
note_counts = chart.note_counts note_counts = chart.note_counts
mix_info = chart.mix_info mix_info = chart.mix_info
@ -329,7 +305,7 @@ class Music(commands.Cog):
embeds.append(embed) embeds.append(embed)
return embeds, files return embeds
def parse_chart_args(self, arg: str) -> Tuple[str, ChartDifficulty]: def parse_chart_args(self, arg: str) -> Tuple[str, ChartDifficulty]:
split_args = arg.split() split_args = arg.split()

@ -9,7 +9,7 @@ from miyu_bot.bot.master_asset_manager import hash_master
def _get_asset_path(master, parent, path): def _get_asset_path(master, parent, path):
return Path(parent) / f'{path.stem}_{hash_master(master)}{path.suffix}' return str((Path(parent) / f'{path.stem}_{hash_master(master)}{path.suffix}').as_posix())
music_dir = Path('.') / 'music' music_dir = Path('.') / 'music'

@ -10,8 +10,6 @@ AnyEmoji = Union[str, Emoji]
async def run_tabbed_message(ctx: Context, emojis: List[AnyEmoji], embeds: List[Embed], files=None, starting_index=0, async def run_tabbed_message(ctx: Context, emojis: List[AnyEmoji], embeds: List[Embed], files=None, starting_index=0,
timeout=300): timeout=300):
if not files:
files = []
if len(emojis) != len(embeds): if len(emojis) != len(embeds):
raise ValueError('Emojis and embeds must have the same number of elements.') raise ValueError('Emojis and embeds must have the same number of elements.')

Loading…
Cancel
Save