diff --git a/Reuse/fonts/GTAmericaMono.ttf b/Reuse/fonts/GTAmericaMono.ttf new file mode 100644 index 0000000..b718d0f Binary files /dev/null and b/Reuse/fonts/GTAmericaMono.ttf differ diff --git a/Reuse/getLeaderboard.py b/Reuse/getLeaderboard.py index 8c59af8..5672256 100644 --- a/Reuse/getLeaderboard.py +++ b/Reuse/getLeaderboard.py @@ -1,3 +1,5 @@ +import datetime +from PIL import Image, ImageDraw, ImageFont import discord import requests @@ -21,6 +23,42 @@ def getleaderboard(board:str, weaponid="", weaponname="", server=""): result = sorted(players, key=handler, reverse=True)[:10] + counter = 1 + message = "" + for p in result: + message = message + str(f"{str(counter):<2} | ") + str(f"{response[p]['username']:<18}:") + str(f'{str(round(handler(p), 1)):<6}' + f"{str(' ' + board.replace('_', ' '))}\n") + counter= counter+1 + + return message + + +def create_leaderboard_image(board:str, weaponid="", weaponname="", server=""): + message = getleaderboard(board, weaponid, weaponname, server) + image_width = 600 + image_height = 300 + background_color = (43, 45, 49) + + font_size = 24 + font_color = (255, 255, 255) + monospace_font_path = r'C:\Users\larsh\Documents\GitHub\Sonar\Reuse\Fonts\GTAmericaMono.ttf' + + image = Image.new('RGB', (image_width, image_height), background_color) + + font = ImageFont.truetype(monospace_font_path, font_size) + + draw = ImageDraw.Draw(image) + + text_width, text_height = draw.textsize(message, font=font) + + text_x = (image_width - text_width) // 2 + text_y = (image_height - text_height) // 2 + + draw.text((text_x, text_y), message, font=font, fill=font_color) + + image.save('Reuse/images/leaderboard.png') + +def create_leaderboard_message(board:str, weaponid="", weaponname="", server=""): + create_leaderboard_image(board, weaponid, weaponname, server) if(server == ""): server = "all" if(weaponname == ""): @@ -33,9 +71,11 @@ def getleaderboard(board:str, weaponid="", weaponname="", server=""): else: botmessage.set_thumbnail(url="https://toneapi.github.io/ToneAPI_webclient/weapons/notfound.png") - counter = 1 - for p in result: - botmessage.add_field(name="", value=str(str(f"**{str(counter):<2} |** " + f"**{response[p]['username']}" + ":** ") + f'{str(round(handler(p), 1))}' + f"{str(' ' + board.replace('_', ' '))}"), inline=False) - counter= counter+1 + date_time = datetime.datetime.utcnow() + time = str(date_time)[11:16] + date = str(date_time)[0:10] + img_file = discord.File("Reuse/images/leaderboard.png", filename="leaderboard.png") + botmessage.set_image(url="attachment://leaderboard.png") + botmessage.set_footer(text=f"Brought to you by ToneAPI, created at {date} on {time}") - return botmessage + return botmessage, img_file \ No newline at end of file diff --git a/cogs/images/OutofBounds.png b/Reuse/images/OutofBounds.png similarity index 100% rename from cogs/images/OutofBounds.png rename to Reuse/images/OutofBounds.png diff --git a/cogs/images/fall.png b/Reuse/images/fall.png similarity index 100% rename from cogs/images/fall.png rename to Reuse/images/fall.png diff --git a/cogs/images/human_execution.png b/Reuse/images/human_execution.png similarity index 100% rename from cogs/images/human_execution.png rename to Reuse/images/human_execution.png diff --git a/cogs/images/invalid.png b/Reuse/images/invalid.png similarity index 100% rename from cogs/images/invalid.png rename to Reuse/images/invalid.png diff --git a/Reuse/images/leaderboard.png b/Reuse/images/leaderboard.png new file mode 100644 index 0000000..7b8874c Binary files /dev/null and b/Reuse/images/leaderboard.png differ diff --git a/cogs/images/mind_crime.png b/Reuse/images/mind_crime.png similarity index 100% rename from cogs/images/mind_crime.png rename to Reuse/images/mind_crime.png diff --git a/cogs/images/mp_weapon_alternator.png b/Reuse/images/mp_weapon_alternator.png similarity index 100% rename from cogs/images/mp_weapon_alternator.png rename to Reuse/images/mp_weapon_alternator.png diff --git a/cogs/images/mp_weapon_arc_launcher.png b/Reuse/images/mp_weapon_arc_launcher.png similarity index 100% rename from cogs/images/mp_weapon_arc_launcher.png rename to Reuse/images/mp_weapon_arc_launcher.png diff --git a/cogs/images/mp_weapon_autopistol.png b/Reuse/images/mp_weapon_autopistol.png similarity index 100% rename from cogs/images/mp_weapon_autopistol.png rename to Reuse/images/mp_weapon_autopistol.png diff --git a/cogs/images/mp_weapon_car.png b/Reuse/images/mp_weapon_car.png similarity index 100% rename from cogs/images/mp_weapon_car.png rename to Reuse/images/mp_weapon_car.png diff --git a/cogs/images/mp_weapon_defender.png b/Reuse/images/mp_weapon_defender.png similarity index 100% rename from cogs/images/mp_weapon_defender.png rename to Reuse/images/mp_weapon_defender.png diff --git a/cogs/images/mp_weapon_dmr.png b/Reuse/images/mp_weapon_dmr.png similarity index 100% rename from cogs/images/mp_weapon_dmr.png rename to Reuse/images/mp_weapon_dmr.png diff --git a/cogs/images/mp_weapon_doubletake.png b/Reuse/images/mp_weapon_doubletake.png similarity index 100% rename from cogs/images/mp_weapon_doubletake.png rename to Reuse/images/mp_weapon_doubletake.png diff --git a/cogs/images/mp_weapon_epg.png b/Reuse/images/mp_weapon_epg.png similarity index 100% rename from cogs/images/mp_weapon_epg.png rename to Reuse/images/mp_weapon_epg.png diff --git a/cogs/images/mp_weapon_esaw.png b/Reuse/images/mp_weapon_esaw.png similarity index 100% rename from cogs/images/mp_weapon_esaw.png rename to Reuse/images/mp_weapon_esaw.png diff --git a/cogs/images/mp_weapon_frag_grenade.png b/Reuse/images/mp_weapon_frag_grenade.png similarity index 100% rename from cogs/images/mp_weapon_frag_grenade.png rename to Reuse/images/mp_weapon_frag_grenade.png diff --git a/cogs/images/mp_weapon_g2.png b/Reuse/images/mp_weapon_g2.png similarity index 100% rename from cogs/images/mp_weapon_g2.png rename to Reuse/images/mp_weapon_g2.png diff --git a/cogs/images/mp_weapon_grenade_electric_smoke.png b/Reuse/images/mp_weapon_grenade_electric_smoke.png similarity index 100% rename from cogs/images/mp_weapon_grenade_electric_smoke.png rename to Reuse/images/mp_weapon_grenade_electric_smoke.png diff --git a/cogs/images/mp_weapon_grenade_emp.png b/Reuse/images/mp_weapon_grenade_emp.png similarity index 100% rename from cogs/images/mp_weapon_grenade_emp.png rename to Reuse/images/mp_weapon_grenade_emp.png diff --git a/cogs/images/mp_weapon_grenade_gravity.png b/Reuse/images/mp_weapon_grenade_gravity.png similarity index 100% rename from cogs/images/mp_weapon_grenade_gravity.png rename to Reuse/images/mp_weapon_grenade_gravity.png diff --git a/cogs/images/mp_weapon_grenade_sonar.png b/Reuse/images/mp_weapon_grenade_sonar.png similarity index 100% rename from cogs/images/mp_weapon_grenade_sonar.png rename to Reuse/images/mp_weapon_grenade_sonar.png diff --git a/cogs/images/mp_weapon_hemlok.png b/Reuse/images/mp_weapon_hemlok.png similarity index 100% rename from cogs/images/mp_weapon_hemlok.png rename to Reuse/images/mp_weapon_hemlok.png diff --git a/cogs/images/mp_weapon_hemlok_smg.png b/Reuse/images/mp_weapon_hemlok_smg.png similarity index 100% rename from cogs/images/mp_weapon_hemlok_smg.png rename to Reuse/images/mp_weapon_hemlok_smg.png diff --git a/cogs/images/mp_weapon_lmg.png b/Reuse/images/mp_weapon_lmg.png similarity index 100% rename from cogs/images/mp_weapon_lmg.png rename to Reuse/images/mp_weapon_lmg.png diff --git a/cogs/images/mp_weapon_lstar.png b/Reuse/images/mp_weapon_lstar.png similarity index 100% rename from cogs/images/mp_weapon_lstar.png rename to Reuse/images/mp_weapon_lstar.png diff --git a/cogs/images/mp_weapon_mastiff.png b/Reuse/images/mp_weapon_mastiff.png similarity index 100% rename from cogs/images/mp_weapon_mastiff.png rename to Reuse/images/mp_weapon_mastiff.png diff --git a/cogs/images/mp_weapon_mgl.png b/Reuse/images/mp_weapon_mgl.png similarity index 100% rename from cogs/images/mp_weapon_mgl.png rename to Reuse/images/mp_weapon_mgl.png diff --git a/cogs/images/mp_weapon_pulse_lmg.png b/Reuse/images/mp_weapon_pulse_lmg.png similarity index 100% rename from cogs/images/mp_weapon_pulse_lmg.png rename to Reuse/images/mp_weapon_pulse_lmg.png diff --git a/cogs/images/mp_weapon_r97.png b/Reuse/images/mp_weapon_r97.png similarity index 100% rename from cogs/images/mp_weapon_r97.png rename to Reuse/images/mp_weapon_r97.png diff --git a/cogs/images/mp_weapon_rocket_launcher.png b/Reuse/images/mp_weapon_rocket_launcher.png similarity index 100% rename from cogs/images/mp_weapon_rocket_launcher.png rename to Reuse/images/mp_weapon_rocket_launcher.png diff --git a/cogs/images/mp_weapon_rspn101.png b/Reuse/images/mp_weapon_rspn101.png similarity index 100% rename from cogs/images/mp_weapon_rspn101.png rename to Reuse/images/mp_weapon_rspn101.png diff --git a/cogs/images/mp_weapon_rspn101_og.png b/Reuse/images/mp_weapon_rspn101_og.png similarity index 100% rename from cogs/images/mp_weapon_rspn101_og.png rename to Reuse/images/mp_weapon_rspn101_og.png diff --git a/cogs/images/mp_weapon_satchel.png b/Reuse/images/mp_weapon_satchel.png similarity index 100% rename from cogs/images/mp_weapon_satchel.png rename to Reuse/images/mp_weapon_satchel.png diff --git a/cogs/images/mp_weapon_semipistol.png b/Reuse/images/mp_weapon_semipistol.png similarity index 100% rename from cogs/images/mp_weapon_semipistol.png rename to Reuse/images/mp_weapon_semipistol.png diff --git a/cogs/images/mp_weapon_shotgun.png b/Reuse/images/mp_weapon_shotgun.png similarity index 100% rename from cogs/images/mp_weapon_shotgun.png rename to Reuse/images/mp_weapon_shotgun.png diff --git a/cogs/images/mp_weapon_shotgun_pistol.png b/Reuse/images/mp_weapon_shotgun_pistol.png similarity index 100% rename from cogs/images/mp_weapon_shotgun_pistol.png rename to Reuse/images/mp_weapon_shotgun_pistol.png diff --git a/cogs/images/mp_weapon_smart_pistol.png b/Reuse/images/mp_weapon_smart_pistol.png similarity index 100% rename from cogs/images/mp_weapon_smart_pistol.png rename to Reuse/images/mp_weapon_smart_pistol.png diff --git a/cogs/images/mp_weapon_smr.png b/Reuse/images/mp_weapon_smr.png similarity index 100% rename from cogs/images/mp_weapon_smr.png rename to Reuse/images/mp_weapon_smr.png diff --git a/cogs/images/mp_weapon_sniper.png b/Reuse/images/mp_weapon_sniper.png similarity index 100% rename from cogs/images/mp_weapon_sniper.png rename to Reuse/images/mp_weapon_sniper.png diff --git a/cogs/images/mp_weapon_softball.png b/Reuse/images/mp_weapon_softball.png similarity index 100% rename from cogs/images/mp_weapon_softball.png rename to Reuse/images/mp_weapon_softball.png diff --git a/cogs/images/mp_weapon_thermite_grenade.png b/Reuse/images/mp_weapon_thermite_grenade.png similarity index 100% rename from cogs/images/mp_weapon_thermite_grenade.png rename to Reuse/images/mp_weapon_thermite_grenade.png diff --git a/cogs/images/mp_weapon_vinson.png b/Reuse/images/mp_weapon_vinson.png similarity index 100% rename from cogs/images/mp_weapon_vinson.png rename to Reuse/images/mp_weapon_vinson.png diff --git a/cogs/images/mp_weapon_wingman.png b/Reuse/images/mp_weapon_wingman.png similarity index 100% rename from cogs/images/mp_weapon_wingman.png rename to Reuse/images/mp_weapon_wingman.png diff --git a/cogs/images/mp_weapon_wingman_n.png b/Reuse/images/mp_weapon_wingman_n.png similarity index 100% rename from cogs/images/mp_weapon_wingman_n.png rename to Reuse/images/mp_weapon_wingman_n.png diff --git a/cogs/images/notfound.png b/Reuse/images/notfound.png similarity index 100% rename from cogs/images/notfound.png rename to Reuse/images/notfound.png diff --git a/cogs/images/phase_shift.png b/Reuse/images/phase_shift.png similarity index 100% rename from cogs/images/phase_shift.png rename to Reuse/images/phase_shift.png diff --git a/cogs/leaderboard.py b/cogs/leaderboard.py index fec44d4..4464499 100644 --- a/cogs/leaderboard.py +++ b/cogs/leaderboard.py @@ -2,7 +2,7 @@ import aiohttp import discord from discord.ext import commands import requests -from Reuse.getLeaderboard import getleaderboard +from Reuse.getLeaderboard import create_leaderboard_message from Reuse.getServer import getserver from Reuse.getWeapon import getweaponid @@ -53,10 +53,9 @@ class Leaderboard(commands.Cog): botmessage = botmessage + "\n*Note you need to split filters with comma's(,)" await ctx.send(f"```{botmessage}```") + botmessage, img_file = create_leaderboard_message(weaponid=weaponid, weaponname=weaponname, server=server, board=board) - botmessage = getleaderboard(weaponid=weaponid, weaponname=weaponname, server=server, board=board) - - await ctx.send(embed=botmessage) + await ctx.send(file=img_file, embed=botmessage) async def setup(client): diff --git a/slashcogs/slashleaderboard.py b/slashcogs/slashleaderboard.py index 496bd5d..cdec0e2 100644 --- a/slashcogs/slashleaderboard.py +++ b/slashcogs/slashleaderboard.py @@ -3,7 +3,7 @@ import discord from discord.ext import commands from discord import app_commands import requests -from Reuse.getLeaderboard import getleaderboard +from Reuse.getLeaderboard import create_leaderboard_message, getleaderboard from Reuse.getServer import getserver from Reuse.getWeapon import getweaponid @@ -31,17 +31,17 @@ class SlashLeaderboard(commands.Cog): server = getserver(session,servername) if(board in boards): - botmessage = getleaderboard(weaponid=weaponid, weaponname=weaponname, server=server, board=board) + botmessage, img_file = create_leaderboard_message(weaponid=weaponid, weaponname=weaponname, server=server, board=board) else: botmessage = "You gave a none existing filter" - await interaction.response.send_message(f'```{botmessage}```') + await interaction.response.send_message(file=img_file, embed=botmessage) @leaderboard.autocomplete("weapon") async def autocomplete_weapon(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]: data = [] - weaponlist = ['execution', 'car', 'charge rifle', 'double take', 'epg', 'volt', 'lstar', 'r97', 'r-201', 'smart pistol', 'kraber', 'flatline', 're-45 auto', 'alternator', 'frag grenade', 'g2', 'spitfire', 'smr', 'softball', 'firestar', 'melee', 'masstiff', 'mgl', 'r-101', 'wingman', 'invalid', 'thunderbolt', 'dmr', 'electric smoke', 'cold war', 'satchel', 'eva-8 auto', 'mozambique', 'wingman elite', 'gravity star', 'pulse blade', 'archer', 'outOfBounds', 'mind crime', 'devotion', 'fall', 'p2016', 'arc grenade', 'hemlok', 'phase shift'] + weaponlist = ['execution', 'car', 'charge rifle', 'double take', 'epg', 'volt', 'lstar', 'r97', 'r-201', 'smart pistol', 'kraber', 'flatline', 're-45 auto', 'alternator', 'frag grenade', 'g2', 'spitfire', 'smr', 'softball', 'firestar', 'melee', 'mastiff', 'mgl', 'r-101', 'wingman', 'invalid', 'thunderbolt', 'dmr', 'electric smoke', 'cold war', 'satchel', 'eva-8 auto', 'mozambique', 'wingman elite', 'gravity star', 'pulse blade', 'archer', 'outOfBounds', 'mind crime', 'devotion', 'fall', 'p2016', 'arc grenade', 'hemlok', 'phase shift'] for weapon_choice in weaponlist: if(current.lower() in weapon_choice.lower()): data.append(app_commands.Choice(name=weapon_choice, value=weapon_choice)) diff --git a/slashcogs/slashstats.py b/slashcogs/slashstats.py index c7a94aa..ccf6106 100644 --- a/slashcogs/slashstats.py +++ b/slashcogs/slashstats.py @@ -48,7 +48,7 @@ class SlashStats(commands.Cog): @stats.autocomplete("weapon") async def autocomplete_weapon(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]: data = [] - weaponlist = ['execution', 'car', 'charge rifle', 'double take', 'epg', 'volt', 'lstar', 'r97', 'r-201', 'smart pistol', 'kraber', 'flatline', 're-45 auto', 'alternator', 'frag grenade', 'g2', 'spitfire', 'smr', 'softball', 'firestar', 'melee', 'masstiff', 'mgl', 'r-101', 'wingman', 'invalid', 'thunderbolt', 'dmr', 'electric smoke', 'cold war', 'satchel', 'eva-8 auto', 'mozambique', 'wingman elite', 'gravity star', 'pulse blade', 'archer', 'outOfBounds', 'mind crime', 'devotion', 'fall', 'p2016', 'arc grenade', 'hemlok', 'phase shift'] + weaponlist = ['execution', 'car', 'charge rifle', 'double take', 'epg', 'volt', 'lstar', 'r97', 'r-201', 'smart pistol', 'kraber', 'flatline', 're-45 auto', 'alternator', 'frag grenade', 'g2', 'spitfire', 'smr', 'softball', 'firestar', 'melee', 'mastiff', 'mgl', 'r-101', 'wingman', 'invalid', 'thunderbolt', 'dmr', 'electric smoke', 'cold war', 'satchel', 'eva-8 auto', 'mozambique', 'wingman elite', 'gravity star', 'pulse blade', 'archer', 'outOfBounds', 'mind crime', 'devotion', 'fall', 'p2016', 'arc grenade', 'hemlok', 'phase shift'] for weapon_choice in weaponlist: if(current.lower() in weapon_choice.lower()): data.append(app_commands.Choice(name=weapon_choice, value=weapon_choice))