async def encryptout(self, ctx, convert: str, input): """ The main, modular function to control encrypt/decrypt commands """ if not input: return await ctx.send( f"Aren't you going to give me anything to encode/decode **{ctx.author.name}**" ) async with ctx.channel.typing(): if len(input) > 1900: try: data = BytesIO(input.encode("utf-8")) except AttributeError: data = BytesIO(input) try: return await ctx.send( content=f"📑 **{convert}**", file=discord.File( data, filename=default.timetext("Encryption"))) except discord.HTTPException: return await ctx.send( f"The file I returned was over 8 MB, sorry {ctx.author.name}..." ) try: await ctx.send( f"📑 **{convert}**```fix\n{input.decode('utf-8')}```") except AttributeError: await ctx.send(f"📑 **{convert}**```fix\n{input}```")
async def execute(self, ctx, *, text: str): """ Do a shell command. """ message = await ctx.send(f"Loading...") proc = await asyncio.create_subprocess_shell(text, stdin=None, stderr=PIPE, stdout=PIPE) out = (await proc.stdout.read()).decode('utf-8').strip() err = (await proc.stderr.read()).decode('utf-8').strip() if not out and not err: await message.delete() return await ctx.message.add_reaction('👌') content = "" if err: content += f"Error:\r\n{err}\r\n{'-' * 30}\r\n" if out: content += out if len(content) > 1500: try: data = BytesIO(content.encode('utf-8')) await message.delete() await ctx.send( content= f"The result was a bit too long.. so here is a text file instead 👍", file=discord.File(data, filename=default.timetext(f'Result'))) except asyncio.TimeoutError as e: await message.delete() return await ctx.send(e) else: await message.edit(content=f"```fix\n{content}\n```")
async def find_discriminator(self, ctx, *, search: str): result = [f"{i}\r\n" for i in ctx.guild.members if (search in i.discriminator)] if len(result) == 0: return await ctx.send("Your search result was empty...") data = BytesIO(''.join(result).encode('utf-8')) await ctx.send(content=f"Found **{len(result)}** on your search for **{search}**", file=discord.File(data, filename=default.timetext(f'DiscriminatorSearch')))
async def find_playing(self, ctx, *, search: str): result = [f"{i} | {i.activity.name}\r\n" for i in ctx.guild.members if (i.activity is not None) and (search.lower() in i.activity.name.lower()) and (not i.bot)] if len(result) == 0: return await ctx.send("Your search result was empty...") data = BytesIO(''.join(result).encode('utf-8')) await ctx.send(content=f"Found **{len(result)}** on your search for **{search}**", file=discord.File(data, filename=default.timetext(f'PlayingSearch')))
async def execute(self, ctx, *, text: str): """ Wykonuje komende """ message = await ctx.send(f"Loading...") proc = await asyncio.create_subprocess_shell(text, stdin=None, stderr=PIPE, stdout=PIPE) out = (await proc.stdout.read()).decode('utf-8').strip() err = (await proc.stderr.read()).decode('utf-8').strip() content = "" if err: content += f"Error:\r\n{err}\r\n{'-' * 30}\r\n" if out: content += out if len(content) > 2000: try: data = BytesIO(content.encode('utf-8')) await message.delete() await ctx.send( content= f"Wynik jest za duży, więc daje plik tekstowy z wynikiem wykonania polecenia", file=discord.File(data, filename=default.timetext(f'Result'))) except asyncio.TimeoutError as e: await message.delete() return await ctx.send(e) else: await message.edit(content=f"```fix\n{content}\n```")
async def find_name(self, ctx, *, search: str): result = [ f"{i}\r\n" for i in ctx.guild.members if (search.lower() in i.name.lower()) ] if result is None: return await ctx.send("Your search result was empty...") data = BytesIO("".join(result).encode("utf-8")) await ctx.send( content=f"Found **{len(result)}** on your search for **{search}**", file=discord.File(data, filename=default.timetext(f"NameSearch")), )
async def encrypt_out(ctx, convert, _input): if not _input: return await ctx.send(f"Aren't you going to give me anything to encode/decode **{ctx.author.name}**") async with ctx.channel.typing(): if len(_input) > 1900: try: data = BytesIO(_input.encode('utf-8')) except AttributeError: data = BytesIO(_input) try: return await ctx.send( content=f"📑 **{convert}**", file=discord.File(data, filename=default.timetext("Encryption")) ) except discord.HTTPException: return await ctx.send(f"The file I returned was over 8 MB, sorry {ctx.author.name}...") try: await ctx.send(f"📑 **{convert}**```fix\n{_input.decode('UTF-8')}```") except AttributeError: await ctx.send(f"📑 **{convert}**```fix\n{_input}```")