Files
cogs/tjadb/embeds.py
T
2023-01-28 21:39:37 +01:00

60 lines
1.9 KiB
Python

import discord
# Formatting
def difficulty(song):
result = ""
for dif in ['d_kantan', 'd_futsuu', 'd_muzukashii', 'd_oni', 'd_ura']:
rate = song[dif]
if not rate:
rate="-"
result += str(rate) + '/'
return result[:-1]
async def song_namecard(song, bot, en=True):
url = await bot.conf.url()
title = song['title_en'] if en else song['title_orig']
genre = song['genre']['name_en'] if en else song['genre']['name_jp']
charter = song['charter']['charter_name']
artists = []
for a in song['artists']:
if en: artists.append(a['name_en'])
else: artists.append(a['name_orig'])
artists = " & ".join(sorted(artists))
name = f"**{title}** by {artists} ({genre})"
body = f"> Charter: {charter} | {song['bpm']}bpm | {difficulty(song)}\n"
body += f"> DL: [Original]({url}/download/orig/{song['_id']})"
body += f" - [English]({url}/download/eng/{song['_id']})"
return {'name': name, 'value': body}
# Embeds
async def embed_search(term, songs, bot):
embed = discord.Embed(title = f"__**Results for: {term}**__",
color = int(await bot.conf.color_search(), 16))
for song in songs:
embed.add_field( **await song_namecard(song, bot=bot, en=True), inline=False)
return embed
async def embed_random(song, bot):
embed = discord.Embed(title = f"__**Random Song**__",
color = int(await bot.conf.color_random(), 16))
embed.add_field( **await song_namecard(song, bot, en=True) )
return embed
async def embed_sotd(song, bot):
embed = discord.Embed(title = "__**Song of the Day**__",
color = int(await bot.conf.color_sotd(), 16))
embed.add_field( **await song_namecard(song, bot, en=True) )
return embed
def embed_color(name, color):
embed = discord.Embed(color = int(color, 16))
embed.add_field(name=name, value=f"#{color}")
return embed