diff --git a/SRC/bw.png b/SRC/bw.png deleted file mode 100644 index 948f67a..0000000 Binary files a/SRC/bw.png and /dev/null differ diff --git a/SRC/cogs/ErrorHandling.py b/SRC/cogs/ErrorHandling.py index 474f731..082813b 100644 --- a/SRC/cogs/ErrorHandling.py +++ b/SRC/cogs/ErrorHandling.py @@ -3,17 +3,29 @@ import sys from discord.ext import commands import json +from datetime import datetime with open('./config.json') as jsonload: config = json.load(jsonload) noCoolDownUsers = config.get("noCoolDownUsers") +now = datetime.now() + +logFileName = f"./logs - {now.strftime('%H ; %M ; %S')}.txt" + +print(f"Logging commands to {logFileName}") + class CommandErrorHandler(commands.Cog): def __init__(self, bot): self.bot = bot + @commands.Cog.listener() + async def on_command(self, ctx): + logs = open(logFileName, "a") + logs.write(f"\n'{ctx.command}' was executed in '{ctx.guild.name}' (ID: {ctx.guild.id}) by {ctx.author} (ID: {ctx.author.id}) at {datetime.utcnow()} UTC") + @commands.Cog.listener() async def on_command_error(self, ctx, error): if hasattr(ctx.command, 'on_error'): diff --git a/SRC/cogs/Minecraft.py b/SRC/cogs/Minecraft.py index 99647aa..65c9c88 100644 --- a/SRC/cogs/Minecraft.py +++ b/SRC/cogs/Minecraft.py @@ -17,7 +17,7 @@ hypixelapikey = config.get('hypixelapikey') -class minecraft(commands.Cog): +class Minecraft(commands.Cog): def __init__(self, client): self.client = client @@ -34,7 +34,6 @@ def __init__(self, client): @commands.command(aliases = ["bed", "bedwarz", "bedwars", "bedworz", "bedwar"]) @commands.cooldown(1, 2,commands.BucketType.user) async def bw(self, ctx, user : str = None, gamemode : str = 'overall'): - print("The BW Command was executed!") start = datetime.utcnow() mode = gamemode.lower() if user is None: @@ -141,18 +140,18 @@ async def bw(self, ctx, user : str = None, gamemode : str = 'overall'): try: bwdata = await hywrap.player(mojang_data["id"], hypixelapikey) - Wins = (bwdata["player"]["stats"]["Bedwars"]["four_four_wins_bedwars"]) - Kills = (bwdata["player"]["stats"]["Bedwars"]["four_four_kills_bedwars"]) - Deaths = (bwdata["player"]["stats"]["Bedwars"]["four_four_deaths_bedwars"]) - voiddeaths = (bwdata["player"]["stats"]["Bedwars"]["four_four_void_final_deaths_bedwars"]) - voidkills = (bwdata["player"]["stats"]["Bedwars"]["four_four_void_kills_bedwars"]) + Wins = bwdata["player"]["stats"]["Bedwars"]["four_four_wins_bedwars"] + Kills = bwdata["player"]["stats"]["Bedwars"]["four_four_kills_bedwars"] + Deaths = bwdata["player"]["stats"]["Bedwars"]["four_four_deaths_bedwars"] + voiddeaths = bwdata["player"]["stats"]["Bedwars"]["four_four_void_final_deaths_bedwars"] + voidkills = bwdata["player"]["stats"]["Bedwars"]["four_four_void_kills_bedwars"] bedsbroken = bwdata["player"]["stats"]["Bedwars"]["four_four_beds_broken_bedwars"] bedslost = bwdata["player"]["stats"]["Bedwars"]["four_four_beds_lost_bedwars"] - Losses = (bwdata["player"]["stats"]["Bedwars"]["four_four_losses_bedwars"]) - stars = (bwdata["player"]["achievements"]["bedwars_level"]) - FinalDeaths = (bwdata["player"]["stats"]["Bedwars"]["four_four_final_deaths_bedwars"]) - FinalKills = (bwdata["player"]["stats"]["Bedwars"]["four_four_final_kills_bedwars"]) - winstreak = (bwdata["player"]["stats"]["Bedwars"]["four_four_winstreak"]) + Losses = bwdata["player"]["stats"]["Bedwars"]["four_four_losses_bedwars"] + stars = bwdata["player"]["achievements"]["bedwars_level"] + FinalDeaths = bwdata["player"]["stats"]["Bedwars"]["four_four_final_deaths_bedwars"] + FinalKills = bwdata["player"]["stats"]["Bedwars"]["four_four_final_kills_bedwars"] + winstreak = bwdata["player"]["stats"]["Bedwars"]["four_four_winstreak"] FKDR = round(float(FinalKills) / float(FinalDeaths), 2) WLR = round(float(Wins) / float(Losses), 2) BBLR = round(float(bedsbroken) / float(bedslost), 2) @@ -161,7 +160,7 @@ async def bw(self, ctx, user : str = None, gamemode : str = 'overall'): bwembed = discord.Embed(title='Bedwars Stats <:bw:850964476109914112>', description=f'Fours | {IGN}', color=0x2f3136) - bwembed.add_field(name='Stars', value=f'``{stars:,}✫``', inline=True) + bwembed.add_field(name='Stars', value=f'``✫{stars:,}``', inline=True) bwembed.add_field(name='Winstreak', value=f'``{winstreak:,}``', inline=True) @@ -230,7 +229,7 @@ async def bw(self, ctx, user : str = None, gamemode : str = 'overall'): bwembed = discord.Embed(title='Bedwars Stats <:bw:850964476109914112>', description=f'Doubles | {IGN}', color=0x2f3136) - bwembed.add_field(name='Stars', value=f'``{stars:,}✫``', inline=True) + bwembed.add_field(name='Stars', value=f'``✫{stars:,}``', inline=True) bwembed.add_field(name='Winstreak', value=f'``{winstreak:,}``', inline=True) @@ -299,7 +298,7 @@ async def bw(self, ctx, user : str = None, gamemode : str = 'overall'): bwembed = discord.Embed(title='Bedwars Stats <:bw:850964476109914112>', description=f'Solo | {IGN}', color=0x2f3136) - bwembed.add_field(name='Stars', value=f'``{stars:,}✫``', inline=True) + bwembed.add_field(name='Stars', value=f'``✫{stars:,}``', inline=True) bwembed.add_field(name='Winstreak', value=f'``{winstreak:,}``', inline=True) @@ -368,7 +367,7 @@ async def bw(self, ctx, user : str = None, gamemode : str = 'overall'): bwembed = discord.Embed(title='Bedwars Stats <:bw:850964476109914112>', description=f'Threes | {IGN}', color=0x2f3136) - bwembed.add_field(name='Stars', value=f'``{stars:,}✫``', inline=True) + bwembed.add_field(name='Stars', value=f'``✫{stars:,}``', inline=True) bwembed.add_field(name='Winstreak', value=f'``{winstreak:,}``', inline=True) @@ -423,7 +422,6 @@ async def bw(self, ctx, user : str = None, gamemode : str = 'overall'): @commands.command(aliases = ["skywars", "skywar", "skywor", "skiwar", "skiwor"]) @commands.cooldown(1, 2,commands.BucketType.user) async def sw(self, ctx, user : str = None, *, gamemode : str = 'overall'): - print("The SW Command was executed!") start = datetime.utcnow() mode = gamemode.lower() if user is None: @@ -737,7 +735,6 @@ async def sw(self, ctx, user : str = None, *, gamemode : str = 'overall'): @commands.command(aliases = ["duels", "d"]) @commands.cooldown(1, 2,commands.BucketType.user) async def duel(self, ctx, user : str = None, *, gamemode : str = 'overall'): - print("The Duels Command was executed!") start = datetime.utcnow() mode = gamemode.lower() if user is None: @@ -1284,7 +1281,6 @@ async def duel(self, ctx, user : str = None, *, gamemode : str = 'overall'): @commands.command() @commands.cooldown(1, 5, commands.BucketType.user) async def compare(self, ctx, player1 : str = None, player2 : str = None): - print("The Compare Command was executed!") if player1 is None: errorembed = discord.Embed(title = 'Compare') errorembed.add_field(name = 'Usage:', value = "``.compare {Player 1} {Player 2}``") @@ -1331,7 +1327,7 @@ async def compare(self, ctx, player1 : str = None, player2 : str = None): oFinalKills = (player1api["player"]["stats"]["Bedwars"]["final_kills_bedwars"]) oFKDR = round(float(oFinalKills) / float(oFinalDeaths), 1) oWLR = round(float(oWins) / float(oLosses), 1) - oIndex = round(ostars * oFKDR * oFKDR / 10) + oIndex = round((ostars * oFKDR ** 2) / 10) tWins = (player2api["player"]["stats"]["Bedwars"]["wins_bedwars"]) tLosses = (player2api["player"]["stats"]["Bedwars"]["losses_bedwars"]) @@ -1340,7 +1336,7 @@ async def compare(self, ctx, player1 : str = None, player2 : str = None): tFinalKills = (player2api["player"]["stats"]["Bedwars"]["final_kills_bedwars"]) tFKDR = round(float(tFinalKills) / float(tFinalDeaths), 1) tWLR = round(float(tWins) / float(tLosses), 1) - tIndex = round(tstars * tFKDR * tFKDR / 10) + tIndex = round((tstars * tFKDR ** 2) / 10) player1ign = mojangplayer1["name"] player2ign = mojangplayer2["name"] @@ -1446,59 +1442,52 @@ async def compare(self, ctx, player1 : str = None, player2 : str = None): @commands.command() @commands.cooldown(1, 2,commands.BucketType.user) - async def p(self, ctx, mode : str = None, player : str = None): - print("The P Command was executed!") + async def p(self, ctx, player : str = None, mode : str = "bedwars"): gamemode = mode.lower() if player is None: errorembed = discord.Embed(title = 'Pictured Stats') - errorembed.add_field(name = 'Usage:', value = "``.p {gamemode} {IGN}``") + errorembed.add_field(name = 'Usage:', value = "``.p {IGN} {gamemode}``") errorembed.add_field(name = '❔', value = 'Returns the SkyWars / BedWars / Duels stats of a specified player in picture format.', inline = False) errorembed.set_thumbnail(url = "https://media.discordapp.net/attachments/835071270117834773/856907114517626900/error.png") errorembed.set_footer(text = 'Gamemode can be bedwars, skywars or duels') await ctx.send(embed = errorembed) - elif gamemode is None: - errorembed = discord.Embed(title = 'Pictured Stats') - errorembed.add_field(name = 'Usage:', value = "``.p {gamemode} {IGN}``") - errorembed.add_field(name = '❔', value = 'Returns the SkyWars / BedWars / Duels stats of a specified player in picture format.', inline = False) - errorembed.set_thumbnail(url = "https://media.discordapp.net/attachments/835071270117834773/856907114517626900/error.png") - await ctx.send(embed = errorembed) else: try: mojang_data = await hywrap.mojangData(player) except: await ctx.send(f"The user your provided is not valid! `{player}`") - async with ctx.typing(): - api = await hywrap.player(mojang_data["id"], hypixelapikey) - - async with aiohttp.ClientSession() as cs: - async with cs.get(f"https://api.slothpixel.me/api/players/{player}") as profiledataraw: - profiledata = await profiledataraw.json() - rank = profiledata["rank"] - - if rank == "MVP_PLUS_PLUS": - rank = "[MVP++]" - elif rank == "MVP_PLUS": - rank = "[MVP+]" - elif rank == "VIP_PLUS": - rank = "[VIP+]" - elif rank == None: - rank = "[Non]" - elif rank == "YOUTUBER": - rank = "[YOUTUBE]" - elif rank == "MODERATOR": - rank = "[MOD]" - else: - rank = f'[{profiledata["rank"]}]' + uuid = mojang_data["id"] + ign = mojang_data["name"] - IGN = mojang_data["name"] - + async with ctx.typing(): if gamemode == "bedwars": try: - img = Image.open("bw.png") + api = await hywrap.player(uuid, hypixelapikey) + + rank = await hywrap.rank(api) + + if rank == "SUPERSTAR": + rank = "[MVP++] " + elif rank == "MVP_PLUS": + rank = "[MVP+] " + elif rank == "VIP_PLUS": + rank = "[VIP+] " + elif rank == "VIP": + rank = "[VIP] " + elif rank == "YOUTUBER": + rank = "[YOUTUBE] " + elif rank == "ADMIN": + rank = "[ADMIN] " + else: + rank = "" + + IGN = mojang_data["name"] + + img = Image.open("./images/bw.png") draw = ImageDraw.Draw(img) - font = ImageFont.truetype("Minecraftia.ttf", 40) - fontbig = ImageFont.truetype("Minecraftia.ttf", 50) + font = ImageFont.truetype("./images/Minecraftia.ttf", 30) + fontbig = ImageFont.truetype("./images/Minecraftia.ttf", 40) Wins = api["player"]["stats"]["Bedwars"]["wins_bedwars"] Kills = api["player"]["stats"]["Bedwars"]["kills_bedwars"] @@ -1521,28 +1510,23 @@ async def p(self, ctx, mode : str = None, player : str = None): KDR = round(float(Kills) / float(Deaths), 1) void_kdr = round(float(voidkills) / float(voiddeaths), 1) - draw.text((200, 150), f"{rank} {IGN}", self.orangey, font=fontbig) - - draw.text((750, 270), f"Stars: {Levels:,}", self.white, font=font) - draw.text((200, 270), f"Winstreak: {winstreak:,}", self.white, font=font) - - draw.text((200, 400), f"Final Kills: {FinalKills:,}", self.white, font=font) - draw.text((200, 470), f"Final Deaths: {FinalDeaths:,}", self.white, font=font) - draw.text((200, 540), f"FKDR: {FKDR:,}", self.white, font=font) - - draw.text((750, 400), f"Wins: {Wins:,}", self.white, font=font) - draw.text((750, 470), f"Losses: {Losses:,}", self.white, font=font) - draw.text((750, 540), f"WLR: {WLR:,}", self.white, font=font) - - draw.text((200, 800), f"Coins: {coins:,}", self.white, font=font) - draw.text((750, 800), f"BBLR: {BBLR:,}", self.white, font=font) - - draw.text((1200, 400), f"Void Kills: {voidkills:,}", self.white, font=font) - draw.text((1200, 470), f"Void Deaths: {voiddeaths:,}", self.white, font=font) - draw.text((1200, 540), f"Void KDR: {void_kdr:,}", self.white, font=font) - - draw.text((1200, 800), f"KDR: {KDR:,}", self.white, font=font) - draw.text((1200, 270), f"Games Played: {games:,}", self.white, font=font) + draw.text((50, 60), f"{rank}{IGN}", self.orangey, font=fontbig) + + draw.text((50, 200), f"Games Played: {games:,}", self.white, font=font) + draw.text((50, 270), f"Final Kills: {FinalKills:,}", self.white, font=font) + draw.text((50, 340), f"Final Deaths: {FinalDeaths:,}", self.white, font=font) + draw.text((50, 410), f"FKDR: {FKDR:,}", self.white, font=font) + draw.text((50, 480), f"Void Kills: {voidkills:,}", self.white, font=font) + draw.text((50, 550), f"Void Deaths: {voiddeaths:,}", self.white, font=font) + draw.text((50, 620), f"Void KDR: {void_kdr:,}", self.white, font=font) + + draw.text((700, 200), f"Stars: {Levels:,}", self.white, font=font) + draw.text((700, 270), f"Wins: {Wins:,}", self.white, font=font) + draw.text((700, 340), f"Losses: {Losses:,}", self.white, font=font) + draw.text((700, 410), f"WLR: {WLR:,}", self.white, font=font) + draw.text((700, 480), f"BBLR: {BBLR:,}", self.white, font=font) + draw.text((700, 550), f"KDR: {KDR:,}", self.white, font=font) + draw.text((700, 620), f"Winstreak: {winstreak:,}", self.white, font=font) with io.BytesIO() as image_binary: img.save(image_binary, 'PNG') @@ -1558,15 +1542,37 @@ async def p(self, ctx, mode : str = None, player : str = None): elif gamemode == "skywars": try: + api = await hywrap.player(mojang_data["id"], hypixelapikey) + async with aiohttp.ClientSession() as cs: async with cs.get(f'https://mc-heads.net/body/{mojang_data["id"]}/right') as skin: skin_read = await skin.read() image_bytesio = io.BytesIO(skin_read) - img = Image.open("sw.png") + async with aiohttp.ClientSession() as cs: + async with cs.get(f"https://api.slothpixel.me/api/players/{player}") as profiledataraw: + profiledata = await profiledataraw.json() + rank = profiledata["rank"] + + if rank == "MVP_PLUS_PLUS": + rank = "[MVP++]" + elif rank == "MVP_PLUS": + rank = "[MVP+]" + elif rank == "VIP_PLUS": + rank = "[VIP+]" + elif rank == None: + rank = "[Non]" + elif rank == "YOUTUBER": + rank = "[YOUTUBE]" + elif rank == "MODERATOR": + rank = "[MOD]" + else: + rank = f'[{profiledata["rank"]}]' + + img = Image.open("./images/sw.png") draw = ImageDraw.Draw(img) - font = ImageFont.truetype("Minecraftia.ttf", 40) - fontbig = ImageFont.truetype("Minecraftia.ttf", 50) + font = ImageFont.truetype("./images/Minecraftia.ttf", 40) + fontbig = ImageFont.truetype("./images/Minecraftia.ttf", 50) SwWins = (api["player"]["stats"]["SkyWars"]["wins"]) Heads = (api["player"]["stats"]["SkyWars"]["heads"]) @@ -1579,7 +1585,7 @@ async def p(self, ctx, mode : str = None, player : str = None): SwWLR = round(float(SwWins) / float(SwLosses), 1) SwLvl = api["player"]["achievements"]["skywars_you_re_a_star"] - draw.text((200, 150), f"{rank} {IGN}", self.orangey, font=fontbig) + draw.text((200, 150), f"{rank} {ign}", self.orangey, font=fontbig) draw.text((800, 270), f"Stars: {SwLvl:,}", self.white, font=font) draw.text((200, 270), f"Heads: {Heads:,}", self.white, font=font) @@ -1612,17 +1618,37 @@ async def p(self, ctx, mode : str = None, player : str = None): elif gamemode == "duels": try: + duels = await hywrap.duels(mojang_data["id"], hypixelapikey) + async with aiohttp.ClientSession() as cs: async with cs.get(f'https://mc-heads.net/body/{mojang_data["id"]}/right') as skin: skin_read = await skin.read() image_bytesio = io.BytesIO(skin_read) - img = Image.open("duels.png") + async with aiohttp.ClientSession() as cs: + async with cs.get(f"https://api.slothpixel.me/api/players/{player}") as profiledataraw: + profiledata = await profiledataraw.json() + rank = profiledata["rank"] + + if rank == "MVP_PLUS_PLUS": + rank = "[MVP++]" + elif rank == "MVP_PLUS": + rank = "[MVP+]" + elif rank == "VIP_PLUS": + rank = "[VIP+]" + elif rank == None: + rank = "[Non]" + elif rank == "YOUTUBER": + rank = "[YOUTUBE]" + elif rank == "MODERATOR": + rank = "[MOD]" + else: + rank = f'[{profiledata["rank"]}]' + + img = Image.open("./images/duels.png") draw = ImageDraw.Draw(img) - font = ImageFont.truetype("Minecraftia.ttf", 40) - fontbig = ImageFont.truetype("Minecraftia.ttf", 50) - - duels = api["player"]["stats"]["Duels"] + font = ImageFont.truetype("./images/Minecraftia.ttf", 40) + fontbig = ImageFont.truetype("./images/Minecraftia.ttf", 50) ws = (duels["current_winstreak"]) best_ws = (duels["best_overall_winstreak"]) @@ -1635,7 +1661,7 @@ async def p(self, ctx, mode : str = None, player : str = None): coins = (duels["coins"]) games = (duels["games_played_duels"]) - draw.text((200, 150), f"{rank} {IGN}", self.orangey, font=fontbig) + draw.text((200, 150), f"{rank} {ign}", self.orangey, font=fontbig) draw.text((800, 270), f"Games Played: {games:,}", self.white, font=font) draw.text((200, 270), f"Coins: {coins:,}", self.white, font=font) @@ -1676,7 +1702,6 @@ async def p(self, ctx, mode : str = None, player : str = None): @commands.command(aliases = ["a", "ach"]) @commands.cooldown(1, 2,commands.BucketType.user) async def achievement(self, ctx, item : str = None, title : str = None, *, text : str = None): - print("The Achievement Command was executed!") start = datetime.utcnow() if item is None: errorembed = discord.Embed(title = 'Achievement') @@ -1729,7 +1754,6 @@ async def achievement(self, ctx, item : str = None, title : str = None, *, text @commands.command() @commands.cooldown(1, 2,commands.BucketType.user) async def server(self, ctx, server : str = "mc.hypixel.net"): - print("The Server Stats Command was executed!") start = datetime.utcnow() try: async with ctx.typing(): @@ -1765,7 +1789,6 @@ async def server(self, ctx, server : str = "mc.hypixel.net"): @commands.command(aliases = ["socials", "s", "connections"]) @commands.cooldown(1, 2,commands.BucketType.user) async def social(self, ctx, user : str = None): - print("The Socials Command was executed!") start = datetime.utcnow() if user is None: errorembed = discord.Embed(title = 'Socials') @@ -1776,9 +1799,7 @@ async def social(self, ctx, user : str = None): await ctx.send(embed = errorembed) else: try: - async with aiohttp.ClientSession() as cs: - async with cs.get(f'https://api.mojang.com/users/profiles/minecraft/{user}') as moj4ngdataraw: - mojang_data = await moj4ngdataraw.json() + mojang_data = await hywrap.mojangData(user) except: await ctx.send(f"The user you provided is not valid! `{user}`") else: @@ -1843,7 +1864,6 @@ async def social(self, ctx, user : str = None): @commands.command(aliases = ["wd", "wdr"]) @commands.cooldown(1, 5, commands.BucketType.user) async def watchdog(self, ctx): - print("The WDR Command was executed!") start = datetime.utcnow() watchdog = await hywrap.watchdogStats(hypixelapikey) @@ -1867,7 +1887,6 @@ async def watchdog(self, ctx): @commands.command() @commands.cooldown(1, 5, commands.BucketType.user) async def uuid(self, ctx, user : str = None): - print("The UUID Command was executed!") start = datetime.utcnow() if user is None: errorembed = discord.Embed(title = 'UUID') @@ -1899,7 +1918,6 @@ async def uuid(self, ctx, user : str = None): @commands.command() @commands.cooldown(1, 5, commands.BucketType.user) async def cape(self, ctx, user : str = None): - print("The Cape Command was executed!") start = datetime.utcnow() if user is None: errorembed = discord.Embed(title = 'Cape') @@ -1941,7 +1959,6 @@ async def cape(self, ctx, user : str = None): @commands.command() @commands.cooldown(1, 5, commands.BucketType.user) async def skin(self, ctx, user : str = None): - print("The Skin Command was executed!") start = datetime.utcnow() if user is None: errorembed = discord.Embed(title = 'Skin') @@ -1988,7 +2005,6 @@ async def map(self, ctx, *, mapName : str = None): errorembed.set_thumbnail(url = "https://media.discordapp.net/attachments/835071270117834773/856907114517626900/error.png") await ctx.send(embed = errorembed) else: - print("The Map command was exected!") name = mapName.lower() maps = { "zarzul": "https://media.discordapp.net/attachments/835071270117834773/876478883745116230/zarzulold-png.png", @@ -2069,8 +2085,6 @@ async def map(self, ctx, *, mapName : str = None): ) @commands.cooldown(1, 2,commands.BucketType.user) async def rq(self, ctx, user : str = None): - print("The RQ Command was executed!") - start = datetime.utcnow() if user is None: errorembed = discord.Embed(title = 'Threat Level Checker') errorembed.add_field(name = 'Usage:', value = "``.rq {username}``") @@ -2084,60 +2098,85 @@ async def rq(self, ctx, user : str = None): except: await ctx.send(f"The user you provided is not valid! `{user}`") - message = await ctx.reply(" Please wait...", mention_author = False) + message = await ctx.reply(" Please wait...", mention_author = False) - try: - bwdata = await hywrap.player(mojang_data["id"], hypixelapikey) - - stars = 0 - finalDeaths = 0 - finalKills = 0 - fkdr = 0 - index = 0 - - stars += int(bwdata["player"]["achievements"]["bedwars_level"]) - finalDeaths += (bwdata["player"]["stats"]["Bedwars"]["final_deaths_bedwars"]) - finalKills += (bwdata["player"]["stats"]["Bedwars"]["final_kills_bedwars"]) - fkdr += round(float(finalKills) / float(finalDeaths), 1) - index += round(stars * fkdr * fkdr / 10) - - if index >= 50000: - embed = discord.Embed(title = "Threat Level Checker", color = 0xff0000, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') - embed.add_field(name = f"Index: {index}", value = "It's a easy loss if you don't requeue.") - - elif index >= 10000: - embed = discord.Embed(title = "Threat Level Checker", color = 0xff2a00, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') - embed.add_field(name = f"Index: {index}", value = "Requeue right now!") - - elif index >= 1000: - embed = discord.Embed(title = "Threat Level Checker", color = 0xff4d00, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') - embed.add_field(name = f"Index: {index}", value = "You *really really* wanna requeue.") - - elif index >= 500: - embed = discord.Embed(title = "Threat Level Checker", color = 0xffa200, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') - embed.add_field(name = f"Index: {index}", value = "It's going to be a very, very sweaty game.") + try: + bwdata = await hywrap.player(mojang_data["id"], hypixelapikey) + + stars = 0 + finalDeaths = 0 + finalKills = 0 + fkdr = 0 + index = 0 + + stars += int(bwdata["player"]["achievements"]["bedwars_level"]) + finalDeaths += (bwdata["player"]["stats"]["Bedwars"]["final_deaths_bedwars"]) + finalKills += (bwdata["player"]["stats"]["Bedwars"]["final_kills_bedwars"]) + fkdr += round(float(finalKills) / float(finalDeaths), 1) + index += round((stars * fkdr ** 2) / 10) + + if index >= 50000: + embed = discord.Embed(title = "Threat Level Checker", color = 0xff0000, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') + embed.add_field(name = f"Index: {index}", value = "It's an easy loss if you don't requeue.") + + elif index >= 10000: + embed = discord.Embed(title = "Threat Level Checker", color = 0xff2a00, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') + embed.add_field(name = f"Index: {index}", value = "Requeue right now!") + + elif index >= 1000: + embed = discord.Embed(title = "Threat Level Checker", color = 0xff4d00, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') + embed.add_field(name = f"Index: {index}", value = "You *really really* wanna requeue.") + + elif index >= 500: + embed = discord.Embed(title = "Threat Level Checker", color = 0xffa200, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') + embed.add_field(name = f"Index: {index}", value = "It's going to be a very, very sweaty game.") + + elif index >= 100: + embed = discord.Embed(title = "Threat Level Checker", color = 0xffcc00, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') + embed.add_field(name = f"Index: {index}", value = "It's going to be a sweaty game.") + + elif index >= 50: + embed = discord.Embed(title = "Threat Level Checker", color = 0xeeff00, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') + embed.add_field(name = f"Index: {index}", value = "You might win the game if you play safe!") + + else: + embed = discord.Embed(title = "Threat Level Checker", color = 0x6fff00, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') + embed.add_field(name = f"Index: {index}", value = "You can win the game!") - elif index >= 100: - embed = discord.Embed(title = "Threat Level Checker", color = 0xffcc00, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') - embed.add_field(name = f"Index: {index}", value = "It's going to be a sweaty game.") + await message.edit(embed = embed, content = "") - else: - embed = discord.Embed(title = "Threat Level Checker", color = 0x6fff00, description = f'`[✫{stars}] | {mojang_data["name"]} | {fkdr}`') - embed.add_field(name = f"Index: {index}", value = "You might win the game if you play safe!") + except Exception as e: + errorembed = discord.Embed() + errorembed.add_field(name = 'Error!', value = f'{mojang_data["name"]} has not played bedwars!') + errorembed.set_thumbnail(url = "https://media.discordapp.net/attachments/835071270117834773/856907114517626900/error.png") + await message.edit(embed = errorembed, content = "") + print(f'There was an error in command rq: {e}') - await message.edit(embed = embed, content = "") - - except Exception as e: - errorembed = discord.Embed() - errorembed.add_field(name = 'Error!', value = f'{mojang_data["name"]} has not played bedwars!') - errorembed.set_thumbnail(url = "https://media.discordapp.net/attachments/835071270117834773/856907114517626900/error.png") - await message.edit(embed = errorembed, content = "") - print(f'There was an error in command rq: {e}') + @commands.command( + aliases = ["api", "apikey"] + ) + async def key(self, ctx, apikey : str = None): + if apikey is None: + apikey = hypixelapikey + + if apikey is not None: + await ctx.message.delete() + + try: + keyData = await hywrap.key(apikey) + except: + await ctx.send("Invalid API key!") + + embed = discord.Embed(title = "API Key Information", color = 0x2f3136) + embed.add_field(name = "Owner", value = f'{keyData["record"]["owner"]}', inline = False) + embed.add_field(name = f"Queries in Past Minute", value = f'{keyData["record"]["queriesInPastMin"]:,}', inline = False) + embed.add_field(name = f"Total Queries", value = f'{keyData["record"]["totalQueries"]:,}', inline = False) + embed.set_footer(text = "Bloop does NOT STORE your Hypixel API key.") + await ctx.send(embed = embed) @commands.command() @commands.cooldown(1, 2,commands.BucketType.user) async def profile(self, ctx, user : str = None): - print("The Profile Command was executed!") start = datetime.utcnow() if user is None: errorembed = discord.Embed(title = 'Profile') @@ -2227,4 +2266,4 @@ async def profile(self, ctx, user : str = None): await ctx.reply(embed=profileembed, mention_author=False) def setup(client): - client.add_cog(minecraft(client)) \ No newline at end of file + client.add_cog(Minecraft(client)) \ No newline at end of file diff --git a/SRC/cogs/Misc.py b/SRC/cogs/Misc.py index b7d6148..c2bc8cb 100644 --- a/SRC/cogs/Misc.py +++ b/SRC/cogs/Misc.py @@ -17,7 +17,6 @@ async def ping(self, ctx): pingembed.add_field(name = "Pong!", value = f"{ping} ms") await ctx.reply(embed=pingembed, mention_author=False) - print("The Ping Command was executed!") @commands.command() async def src(self, ctx): @@ -25,7 +24,6 @@ async def src(self, ctx): srcembed = discord.Embed(title="Source Code", url = "https://github.com/Supelion/Bloop", description="Bloop's SRC can be found on GitHub by clicking the title of this embed,\nor by [clicking here](http://tiny.cc/rfx2uz)", color = 0x2f3136) await ctx.reply(embed=srcembed, mention_author=False) - print("The SRC Command was executed!") @commands.command() @commands.cooldown(1, 500,commands.BucketType.user) @@ -34,7 +32,6 @@ async def suggest(self, ctx, *, message): embed.add_field(name = "Suggestion added!", value = f"{message}") await ctx.reply(embed = embed, mention_author = False) - print("The Suggest Command was executed!") channel = self.client.get_channel(837363032321294367) lolembed = discord.Embed(title = "New Suggestion") @@ -45,10 +42,9 @@ async def suggest(self, ctx, *, message): async def invite(self, ctx): invitembed = discord.Embed(color = 0x2f3136) - invitembed.add_field(name=f"Invite Link :link:", value = "https://bit.ly/bloopBot") + invitembed.add_field(name=f"Invite Link :link:", value = "https://discord.com/oauth2/authorize?client_id=835237831412547607&permissions=2147862592&scope=bot") await ctx.reply(embed=invitembed, mention_author=False) - print("The Skin Command was executed!") def setup(client): diff --git a/SRC/cogs/OwnerOnly.py b/SRC/cogs/OwnerOnly.py index ebc3e91..0cc3530 100644 --- a/SRC/cogs/OwnerOnly.py +++ b/SRC/cogs/OwnerOnly.py @@ -1,10 +1,7 @@ import discord -import json -import os -import aiohttp from discord.ext import commands -class owner(commands.Cog): +class Owner(commands.Cog): def __init__(self, client): self.client = client @@ -263,4 +260,4 @@ async def ownerhelp(self, ctx): await ctx.reply(embed = ownerhelpembed) def setup(client): - client.add_cog(owner(client)) \ No newline at end of file + client.add_cog(Owner(client)) \ No newline at end of file diff --git a/SRC/config.json b/SRC/config.json index bd695ee..8309db6 100644 --- a/SRC/config.json +++ b/SRC/config.json @@ -1,7 +1,7 @@ { - "token": "ODM2NjU1MTEyMDIxMjEzMjI0.YIhJyw.yikPEnjoryamTO7ey4KJ3Rd8XQw", - "hypixelapikey": "67068c67-02ee-444f-9f2e-8a80a27271e8", - "postgresDSN": "postgresql://postgres:5utBpuE1FRy4trJmVSCt@containers-us-west-11.railway.app:7551/railway", - "bot-log-channel": 873295884903907399, - "noCoolDownUsers": [467962329435471878, 577377630362402817, 704672855245193296] + "token": "INERT YOUR DISCORD BOT TOKEN HERE", + "hypixelapikey": "INSERT YOUR HYPIXEL API KEY HERE", + "bot-log-channel": "INSERT A CHANNEL ID HERE", + "noCoolDownUsers": ["INSERT USER IDS HERE, SEPERATED BY COMMAS"], + "prefix": "." } \ No newline at end of file diff --git a/SRC/main.py b/SRC/main.py index e0df85f..759d979 100644 --- a/SRC/main.py +++ b/SRC/main.py @@ -4,10 +4,10 @@ import json from datetime import datetime from itertools import cycle - import asyncpg import discord from discord.ext import commands, tasks - import PIL # I know, we're not usig this module right now, but its for the try except statement + import platform + import PIL # I know, we're not using this module right now, but its for the try except statement except ImportError: print("One or many requirements are missing! Installing them now.") @@ -18,31 +18,18 @@ config = json.load(f) token = config.get('token') -postgresDatabaseDSN = config.get('postgresDSN') botLogChannel = config.get('bot-log-channel') +prefix = config.get('prefix') os.system("cls") -async def create_db_pool(): - client.db = await asyncpg.create_pool(dsn = postgresDatabaseDSN) - print("Connected to the DB!") - - await client.db.execute("CREATE TABLE IF NOT EXISTS prefixes(guild_id bigint PRIMARY KEY, prefix text);") - print("Created Table") - -PRE = '.' -async def get_pre(bot, message): - if not message.guild: - return commands.when_mentioned_or(PRE)(bot,message) - prefix = await client.db.fetchval('SELECT prefix FROM prefixes WHERE guild_id = $1', message.guild.id) - if not prefix: - prefix = PRE - return commands.when_mentioned_or(prefix)(bot,message) - intents = discord.Intents.default() intents.members = True -client = commands.Bot(command_prefix = get_pre, case_insensitive = True, help_command=None, intents=intents) -client.launch_time = datetime.utcnow() +client = commands.Bot(command_prefix = prefix, case_insensitive = True, help_command=None, intents=intents) + +launch_time = datetime.utcnow() + +botVersion = "Bloop v2.7" for filename in os.listdir('./cogs'): if filename.endswith('.py'): @@ -52,8 +39,18 @@ async def get_pre(bot, message): async def on_ready(): user = client.get_user(467962329435471878) await user.send("I'm online. <:online:850325400605425684>") - print(f"I'm ready! I have logged in as {client.user}") + print(f"I have logged in as {client.user}") + print(f"Python Version: {platform.python_version()}") + print(f"Running on: {platform.system()} {platform.release()}") +@client.command() +async def reload(ctx, *, module): + try: + client.reload_extension(module) + await ctx.send("Done!") + except commands.ExtensionError as e: + await ctx.send(f'{e.__class__.__name__}: {e}') + @client.event async def on_guild_remove(guild): channel = client.get_channel(botLogChannel) @@ -73,32 +70,17 @@ async def changer(): status2 = f"Hypixel Stats! | .help" status3 = f"Open Source! (.src)| .help" status4 = f"Server Stats! | .help" -status5 = f"DLCs! | .help" -client.status = cycle([status1, status2, status3, status4, status5]) +status5 = f"Map Information! | .help" +status6 = f"Requeue Checker! | .help" +status7 = f"Stats Comparer! | .help" +status8 = f"Watchdog Stats! | .help" +client.status = cycle([status1, status2, status3, status4, status5, status6]) changer.start() -@client.command() -@commands.has_permissions(manage_guild = True) -@commands.cooldown(1, 50,commands.BucketType.guild) -async def prefix(ctx, new=None): - old = await client.db.fetchval('SELECT prefix FROM prefixes WHERE guild_id = $1', ctx.guild.id) - if not new: - old = old or '.' - await ctx.send(f"My prefix here is: `{old}`") - return - - if len(new) > 10: - return await ctx.send("Prefixes must be no longer than 10 characters long!") - if not old: - await client.db.execute('INSERT INTO prefixes(guild_id, prefix) VALUES ($1, $2)', ctx.guild.id, new) - else: - await client.db.execute('UPDATE prefixes SET prefix = $1 WHERE guild_id = $2', new, ctx.guild.id) - await ctx.send(f"The new prefix is: `{new}`") - @client.command() async def stats(ctx): - delta_uptime = datetime.utcnow() - client.launch_time + delta_uptime = datetime.utcnow() - launch_time hours, remainder = divmod(int(delta_uptime.total_seconds()), 3600) minutes, seconds = divmod(remainder, 60) days, hours = divmod(hours, 24) @@ -111,12 +93,11 @@ async def stats(ctx): statsembed.add_field(name = f"Guilds:", value = f"{len(client.guilds)}", inline = False) - statsembed.add_field(name = f"Uptime:", value = f"{hours}h, {minutes}m, {seconds}s.\n\n[Support Website](https://supelion.github.io/bl00p/)", inline = False) + statsembed.add_field(name = f"Uptime:", value = f"{days}d {hours}h, {minutes}m, {seconds}s.\n\n[Support Website](https://supelion.github.io/bl00p/)", inline = False) - statsembed.set_footer(text="Bloop v2.5 | Supelion#4275") + statsembed.set_footer(text=f"{botVersion} | Supelion#4275") await ctx.reply(embed=statsembed, mention_author=False) - print("The Stats Command was executed!") @client.command() async def help(ctx): @@ -125,16 +106,14 @@ async def help(ctx): helpembed.add_field(name = "My Prefix:", value = "``.``") - helpembed.add_field(name='<:minecraft:848988105943810095> Minecraft', value='``bw`` • ``sw`` • ``duels`` • ``profile`` • ``wdr`` • ``server``\n\n``socials`` • ``skin`` • ``p`` • ``uuid`` • ``compare``\n\n``achievement`` • ``map`` • ``requeue``', inline=False) + helpembed.add_field(name='<:minecraft:848988105943810095> Minecraft', value='``bw`` • ``sw`` • ``duels`` • ``profile`` • ``wdr`` • ``server``\n\n``socials`` • ``skin`` • ``p`` • ``uuid`` • ``compare``\n\n``achievement`` • ``map`` • ``requeue`` • ``key``', inline=False) - helpembed.add_field(name='<:misc:844235406877917234> Utility', value='``src`` • ``ping`` • ``invite`` • ``stats`` • ``suggest`` • ``prefix``', inline=False) + helpembed.add_field(name='<:utility:877105943844904980> Utility', value='``src`` • ``ping`` • ``invite`` • ``stats`` • ``suggest``', inline=False) helpembed.set_thumbnail(url='https://media.discordapp.net/attachments/8350712o70117834773/853578246984433684/lol.png?width=480&height=480') - helpembed.set_footer(text="Bloop v2.5 | Supelion#4275 | All Commmands work in DMs.") + helpembed.set_footer(text=f"{botVersion} | Supelion#4275 | All Commmands work in DMs.") await ctx.reply(embed=helpembed, mention_author = False) - print("The Help Command was executed!") -client.loop.run_until_complete(create_db_pool()) client.run(f"{token}") \ No newline at end of file diff --git a/SRC/requirements.txt b/SRC/requirements.txt index 67d5e81..bdaba97 100644 --- a/SRC/requirements.txt +++ b/SRC/requirements.txt @@ -1,4 +1,3 @@ -asyncpg -discord aiohttp -pillow \ No newline at end of file +pillow +py-cord \ No newline at end of file diff --git a/SRC/utils/hywrap.py b/SRC/utils/hywrap.py index 0a8a088..c48696f 100644 --- a/SRC/utils/hywrap.py +++ b/SRC/utils/hywrap.py @@ -155,6 +155,19 @@ async def guild(uuid : str, hypixelapikey : str = None): guild = await guildRaw.json() return guild +# Returns the player's rank, its a little complicated, but gets the job done :D +async def rank(playerdata : dict): + try: + return playerdata["player"]["rank"] + except: + if playerdata["player"].get("monthlyPackageRank") and playerdata["player"].get("monthlyPackageRank") != "NONE": + return playerdata["player"]["monthlyPackageRank"] + else: + try: + return playerdata["player"]["newPackageRank"] + except: + return None + # Returns the recent games of a player async def recentGames(uuid : str, hypixelapikey : str = None): if hypixelapikey is None: diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 67d5e81..0000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -asyncpg -discord -aiohttp -pillow \ No newline at end of file diff --git a/SRC/Minecraftia.ttf b/src/images/Minecraftia.ttf similarity index 100% rename from SRC/Minecraftia.ttf rename to src/images/Minecraftia.ttf diff --git a/src/images/bw.png b/src/images/bw.png new file mode 100644 index 0000000..60f75b4 Binary files /dev/null and b/src/images/bw.png differ diff --git a/SRC/duels.png b/src/images/duels.png similarity index 100% rename from SRC/duels.png rename to src/images/duels.png diff --git a/SRC/overall.png b/src/images/overall.png similarity index 100% rename from SRC/overall.png rename to src/images/overall.png diff --git a/SRC/sw.png b/src/images/sw.png similarity index 100% rename from SRC/sw.png rename to src/images/sw.png diff --git a/src/images/template.pdn b/src/images/template.pdn new file mode 100644 index 0000000..b8f60c7 Binary files /dev/null and b/src/images/template.pdn differ