Wip SVGs!

Multiple hours' woerk
This commit is contained in:
TheTechRobo 2021-06-29 21:10:54 -04:00
parent 1a61aadd31
commit ad8cb546cb
3 changed files with 9476 additions and 4 deletions

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 711 KiB

18
bot.py
View File

@ -1,8 +1,8 @@
# {{{ Imports
import discord, requests, json, time
import discord, requests, json, time, os, hypixel_bot_tools.errors, tempfile
from discord.ext import commands
from hypixel_bot_tools import *
import hypixel_bot_tools.errors
from cairosvg import svg2png
hypierror = hypixel_bot_tools.errors
# }}}
# {{{ Get token
@ -76,8 +76,10 @@ async def hypixel(ctx,player,ConvertToUUID=True):
raise
item[i] = "N/A"
currentStatus_Message = f"{item['gameType']} ({_('mode')} {item['mode']}); {_('on map')} {item['map']}"
onlinecolour = "green"
except KeyError:
currentStatus_Message = _("Offline")
onlinecolour = "#454545"
for i in ("karma",): #these are fields that might not exist
try:
contents[i]
@ -87,14 +89,24 @@ async def hypixel(ctx,player,ConvertToUUID=True):
em = discord.Embed(
title=f"{contents['displayname']}'{_('s Hypixel Stats')}",
footer=_("Thanks for using Hypibot!"))
val = f"{round(RawXPToLevel(contents['networkExp']),2)} ({_('raw')} {int(contents['networkExp'])})"
em.add_field(name=_("UUID"),value=getuuid(player),inline=True)
em.add_field(name=_("Rank"), value=contents['rank'],inline=True)
em.add_field(name=_("Network Level"),value=f"{round(RawXPToLevel(contents['networkExp']),2)} ({_('raw')} {contents['networkExp']})",inline=True)
em.add_field(name=_("Network Level"),value=val,inline=True)
em.add_field(name=_("Karma"),value=contents['karma'],inline=True)
em.add_field(name=_("Friends"),value=lenfriends,inline=True)
em.add_field(name="\u200b",value="\u200b",inline=True)#newline; \u200b is a zero width space that is allowed by dcord
em.add_field(name=_("Online?"),value=statusAPI_Message,inline=True)
em.add_field(name=_("Current Game"),value=currentStatus_Message,inline=True)
with open("AnyConv.com__minecraft-2053886_960_7200.svg") as file:
svg = file.read().format(uuid=getuuid(player), userhtml="""<text x="25" y="100" style="font-size:40px;">{rank}&#8194;{displayname}</text>""".format(rank=contents['rank'], displayname=contents['displayname']), exp=val, karma=contents['karma'], friends=lenfriends,
onlinehtml=f'<text x="20" y="250" style="fill:{onlinecolour}; font-size:31px;">{currentStatus_Message}</text>')
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, 'png.pngpng.png') #https://stackoverflow.com/a/45803022/9654083
svg2png(bytestring=svg, write_to=path) #https://stackoverflow.com/questions/6589358/convert-svg-to-png-in-python
with open(path, "rb") as file: #https://stackoverflow.com/questions/60913131/how-to-send-a-image-with-discord-py
file = discord.File(file, filename=path)
await ctx.send(file=file)
await thing.edit(embed=em, content="Player data down below.")
@bot.command()
async def bedwars(ctx, player, ConvertToUUID=True):

View File

@ -18,7 +18,7 @@ def translaterank(rank):
#the following if statements are exceptions
if rank == "SUPERSTAR": rank = "MVP_PLUS_PLUS"
if rank == "YOUTUBER": rank = "YOUTUBE"
if rank is None: return "Regular"
if rank is None: return "(None)"
rank = rank.replace("_","").replace("PLUS","+")
for letter in "abcdefghijklmnopqrstuvwxyz0123456789_[]§": #safe since there aren't lowercases in ranks and ive never seen numbers in ranks before
rank = rank.replace(letter,"")