async def update(self, ctx, thing): if thing.lower() == "data": async with aiofiles.open("data/data.json", "r", encoding="utf8") as d: self.d = recursive_update(self.d, cj.loads(await d.read())) self.d.findables = cj.classify(self.d.special_findables + self.d.default_findables) elif thing.lower() == "text": async with aiofiles.open("data/text.json", "r", encoding="utf8") as t: # recursive shit not needed here self.bot.langs.update(cj.loads(await t.read())) elif thing.lower() == "mcservers": self.d.additional_mcservers = await self.db.fetch_all_mcservers() else: await self.bot.send(ctx, 'Invalid, options are "data", "text", or "mcservers"') return await ctx.message.add_reaction(self.d.emojis.yes)
def load_text() -> cj.ClassyDict: text = {} for filename in os.listdir("data/text"): with open(f"data/text/{filename}", "r", encoding="utf8") as f: text.update(cj.loads(f.read())) return cj.ClassyDict(text)
async def steal_skin(self, ctx, player): if 17 > len(player) > 1 and player.lower().strip( 'abcdefghijklmnopqrstuvwxyz1234567890_') == '': with ctx.typing(): res = await self.ses.get( f'https://api.mojang.com/users/profiles/minecraft/{player}' ) if res.status == 204: await self.bot.send(ctx, ctx.l.minecraft.invalid_player) return elif res.status != 200: await self.bot.send(ctx, ctx.l.minecraft.stealskin.error) return jj = await res.json() uuid = jj['id'] elif len(player) in ( 32, 36, ) and player.lower().strip('abcdefghijklmnopqrstuvwxyz1234567890-' ) == '': # player is a uuid uuid = player.replace('-', '') else: await self.bot.send(ctx, ctx.l.minecraft.invalid_player) return with ctx.typing(): res = await self.ses.get( f'https://sessionserver.mojang.com/session/minecraft/profile/{uuid}' ) if res.status != 200: await self.bot.send(ctx, ctx.l.minecraft.stealskin.error) return profile = await res.json() skin_url = None for prop in profile['properties']: if prop['name'] == 'textures': skin_url = cj.loads(base64.b64decode( prop['value'])).textures.get('SKIN', {}).get('url') break if skin_url is None: await self.bot.send(ctx, ctx.l.minecraft.stealskin.no_skin) return embed = discord.Embed( color=self.d.cc, description=ctx.l.minecraft.stealskin.embed_desc.format( profile['name'], skin_url)) embed.set_thumbnail(url=skin_url) embed.set_image(url=f'https://visage.surgeplay.com/full/{uuid}.png') await ctx.send(embed=embed)
async def steal_skin(self, ctx, player): if 17 > len(player) > 1 and player.lower().strip( "abcdefghijklmnopqrstuvwxyz1234567890_") == "": with ctx.typing(): res = await self.ses.get( f"https://api.mojang.com/users/profiles/minecraft/{player}" ) if res.status == 204: await self.bot.send(ctx, ctx.l.minecraft.invalid_player) return elif res.status != 200: await self.bot.send(ctx, ctx.l.minecraft.stealskin.error) return jj = await res.json() uuid = jj["id"] elif (len(player) in ( 32, 36, ) and player.lower().strip("abcdefghijklmnopqrstuvwxyz1234567890-") == ""): # player is a uuid uuid = player.replace("-", "") else: await self.bot.send(ctx, ctx.l.minecraft.invalid_player) return with ctx.typing(): res = await self.ses.get( f"https://sessionserver.mojang.com/session/minecraft/profile/{uuid}" ) if res.status != 200: await self.bot.send(ctx, ctx.l.minecraft.stealskin.error) return profile = await res.json() skin_url = None for prop in profile["properties"]: if prop["name"] == "textures": skin_url = cj.loads(base64.b64decode( prop["value"])).textures.get("SKIN", {}).get("url") break if skin_url is None: await self.bot.send(ctx, ctx.l.minecraft.stealskin.no_skin) return embed = discord.Embed( color=self.d.cc, description=ctx.l.minecraft.stealskin.embed_desc.format( profile["name"], skin_url)) embed.set_thumbnail(url=skin_url) embed.set_image(url=f"https://visage.surgeplay.com/full/{uuid}.png") await ctx.send(embed=embed)
async def minecraft_profile(self, ctx, player): if 17 > len(player) > 1 and player.lower().strip('abcdefghijklmnopqrstuvwxyz1234567890_') == '': with ctx.typing(): res = await self.ses.get(f'https://api.mojang.com/users/profiles/minecraft/{player}') if res.status == 204: await self.bot.send(ctx, ctx.l.minecraft.invalid_player) return elif res.status != 200: await self.bot.send(ctx, ctx.l.minecraft.profile.error) return jj = await res.json() uuid = jj['id'] elif len(player) in (32, 36,) and player.lower().strip('abcdefghijklmnopqrstuvwxyz1234567890-') == '': # player is a uuid uuid = player.replace('-', '') else: await self.bot.send(ctx, ctx.l.minecraft.invalid_player) return with ctx.typing(): resps = await asyncio.gather( self.ses.get(f'https://api.mojang.com/user/profiles/{uuid}/names'), self.ses.get(f'https://sessionserver.mojang.com/session/minecraft/profile/{uuid}') ) for res in resps: if res.status == 204: await self.bot.send(ctx, ctx.l.minecraft.invalid_player) return elif res.status != 200: await self.bot.send(ctx, ctx.l.minecraft.profile.error) return names = cj.classify(await resps[0].json()) profile = cj.classify(await resps[1].json()) skin_url = None cape_url = None for prop in profile['properties']: if prop['name'] == 'textures': textures = cj.loads(base64.b64decode(prop['value'])).textures skin_url = textures.get('SKIN', {}).get('url') cape_url = textures.get('CAPE', {}).get('url') break name_hist = '\uFEFF' for i, name in enumerate(reversed(names)): time = name.get('changedToAt') if time is None: time = ctx.l.minecraft.profile.first else: time = arrow.Arrow.fromtimestamp(time) time = time.format('MMM D, YYYY', locale=ctx.l.lang) + ', ' + time.humanize(locale=ctx.l.lang) name_hist += f'**{len(names)-i}.** `{name.name}` - {time}\n' embed = discord.Embed(color=self.d.cc, title=ctx.l.minecraft.profile.mcpp.format(profile.name)) if skin_url is not None: embed.description = f'[**{ctx.l.minecraft.profile.skin}**]({skin_url})' if cape_url is not None: embed.description += f' | [**{ctx.l.minecraft.profile.cape}**]({cape_url})' else: embed.description += f' | {ctx.l.minecraft.profile.nocape}' embed.set_thumbnail(url=f'https://visage.surgeplay.com/head/{uuid}.png') embed.add_field(name=':link: UUID', value=f'`{uuid[:8]}-{uuid[8:12]}-{uuid[12:16]}-{uuid[16:20]}-{uuid[20:]}`\n`{uuid}`', inline=False) embed.add_field(name=(':label: ' + ctx.l.minecraft.profile.hist), value=name_hist, inline=False) await ctx.send(embed=embed)
def load_data() -> cj.ClassyDict: with open("data/data.json", "r", encoding="utf8") as f: data = cj.loads(f.read()) mod_data(data) return data
def load_secrets() -> cj.ClassyDict: with open("../secrets.json", "r", encoding="utf8") as f: return cj.loads(f.read())
async def minecraft_profile(self, ctx, player): if 17 > len(player) > 1 and player.lower().strip( "abcdefghijklmnopqrstuvwxyz1234567890_") == "": with ctx.typing(): res = await self.ses.get( f"https://api.mojang.com/users/profiles/minecraft/{player}" ) if res.status == 204: await self.bot.send(ctx, ctx.l.minecraft.invalid_player) return elif res.status != 200: await self.bot.send(ctx, ctx.l.minecraft.profile.error) return jj = await res.json() uuid = jj["id"] elif (len(player) in (32, 36) and player.lower().strip("abcdefghijklmnopqrstuvwxyz1234567890-") == ""): # player is a uuid uuid = player.replace("-", "") else: await self.bot.send(ctx, ctx.l.minecraft.invalid_player) return with ctx.typing(): resps = await asyncio.gather( self.ses.get( f"https://api.mojang.com/user/profiles/{uuid}/names"), self.ses.get( f"https://sessionserver.mojang.com/session/minecraft/profile/{uuid}" ), ) for res in resps: if res.status == 204: await self.bot.send(ctx, ctx.l.minecraft.invalid_player) return elif res.status != 200: await self.bot.send(ctx, ctx.l.minecraft.profile.error) return names = cj.classify(await resps[0].json()) profile = cj.classify(await resps[1].json()) skin_url = None cape_url = None for prop in profile["properties"]: if prop["name"] == "textures": textures = cj.loads(base64.b64decode(prop["value"])).textures skin_url = textures.get("SKIN", {}).get("url") cape_url = textures.get("CAPE", {}).get("url") break name_hist = "\uFEFF" for i, name in enumerate(list(reversed(names))[:20]): time = name.get("changedToAt") if time is None: time = ctx.l.minecraft.profile.first else: time = arrow.Arrow.fromtimestamp(time) time = time.format("MMM D, YYYY", locale=ctx.l.lang) + ", " + time.humanize( locale=ctx.l.lang) name_hist += f"**{len(names)-i}.** `{name.name}` - {time}\n" embed = discord.Embed(color=self.d.cc, title=ctx.l.minecraft.profile.mcpp.format( profile.name)) if skin_url is not None: embed.description = f"**[{ctx.l.minecraft.profile.skin}]({skin_url})**" if cape_url is not None: embed.description += f" | **[{ctx.l.minecraft.profile.cape}]({cape_url})**" # else: # embed.description += f" | {ctx.l.minecraft.profile.nocape}" embed.set_thumbnail( url=f"https://visage.surgeplay.com/head/{uuid}.png") embed.add_field( name=":link: UUID", value= f"`{uuid[:8]}-{uuid[8:12]}-{uuid[12:16]}-{uuid[16:20]}-{uuid[20:]}`\n`{uuid}`", inline=False, ) embed.add_field(name=(":label: " + ctx.l.minecraft.profile.hist), value=name_hist, inline=False) await ctx.send(embed=embed)
async def read_packet(self) -> cj.ClassyDict: (length, ) = struct.unpack(">i", await self.reader.read( LENGTH_LENGTH)) # read the length of the upcoming packet data = await self.reader.read(length) # read the rest of the packet return cj.loads(data, object_hook=special_obj_hook)