async def eval(self, ctx, *, code): code = "\n".join( code.split("\n")[1:] [:-3]) if code.startswith("```") and code.endswith("```") else code localvars = { "discord": discord, "commands": commands, "ctx": ctx, "__import__": __import__, "funcs": funcs, "client": self.client } stdout = StringIO() try: with redirect_stdout(stdout): exec(f"async def func():\n{indent(code, ' ')}", localvars) obj = await localvars["func"]() result = f"{stdout.getvalue()}" e = discord.Embed(description=funcs.formatting(str(result))) if obj: e.add_field(name="Returned", value=funcs.formatting(str(obj), limit=1024)) except Exception as ex: e = funcs.errorEmbed(None, str(ex)) await ctx.reply(embed=e)
async def restart(self, ctx): msg = ctx.message await msg.reply( "Are you sure? You have 10 seconds to confirm by typing `yes`.") try: msg = await self.client.wait_for( "message", check=lambda m: m.channel == ctx.channel and m.author == ctx.author \ and m.content.casefold() == "yes", timeout=10 ) except TimeoutError: return await ctx.send("Cancelling restart.") gitpull = "" await msg.reply("Pull from Git repository?") try: msg = await self.client.wait_for( "message", check=lambda m: m.channel == ctx.channel and m.author == ctx.author \ and m.content.casefold() == "yes", timeout=10 ) gitpull = f"cd {funcs.getPath()} && git pull && " except TimeoutError: await msg.reply("Not git-pulling. Commencing restart...") else: await msg.reply("Git-pulling. Commencing restart...") obj = Popen(f"{gitpull}sudo reboot", shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=False if system() == "Windows" else True) await ctx.send(embed=discord.Embed( description=funcs.formatting(obj.stdout.read().decode("utf-8")))) obj.kill()
async def morsetotext(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: text += " " output = "" ctext = "" spaces = 0 for char in text: if char != " ": if char != "-" and char != ".": if char == "·": char = "." else: continue spaces = 0 ctext += char else: spaces += 1 if spaces == 2: output += " " else: output += list(self.morsecode.keys())[list( self.morsecode.values()).index(ctext)] ctext = "" e = Embed(title="Text to Morse Code", description=funcs.formatting(output)) except Exception: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def texttobrainfuck(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: old = 0 output = "" for character in text: ordd = ord(character) if old == ordd: output += "." continue deviation = ordd - old root = int((abs(deviation))**(1 / 2)) rest = abs(deviation) - (root**2) mult = root, rest if 0 < deviation: output += "{}.".format("+" * deviation) if deviation < 6 \ else ">{}[<{}>-]<{}.".format("+" * mult[0], "+" * mult[0], "+" * mult[1]) else: output += "{}.".format("-" * abs(deviation)) if deviation > -6 \ else ">{}[<{}>-]<{}.".format("+" * mult[0], "-" * mult[0], "-" * mult[1]) old = ordd e = Embed(title="Text to Brainfuck", description=funcs.formatting(output)) except Exception: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def banlist(self, ctx): bannedusers = await ctx.guild.bans() string = "\n".join( f"- {ban.user.name}#{ban.user.discriminator}" + \ f" (Reason: {ban.reason})" for ban in bannedusers ) string = string or "None" await ctx.reply(funcs.formatting(string))
async def gitpull(self, ctx): obj = Popen(f"cd {funcs.getPath()} && git pull", shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=False if system() == "Windows" else True) await ctx.reply(embed=discord.Embed( description=funcs.formatting(obj.stdout.read().decode("utf-8")))) obj.kill()
async def texttobinary(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: e = Embed(title="Text to Binary", description=funcs.formatting( str("".join(f"{ord(i):08b}" for i in text)))) except Exception: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def hextotext(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: e = Embed(title="Hexadecimal to Text", description=funcs.formatting( bytes.fromhex(text).decode("utf-8"))) except Exception: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def gitlogchannels(self, ctx): msg = "" for channel in RIDICULOUS_CHANNEL_LIST[:-1]: if channel: try: name = f"#{channel.name} in {channel.guild.name} [{channel.guild.id}]" except: name = "DM" msg += f"- {channel.id} ({name})\n" await ctx.send( funcs.formatting(msg, limit=2000) if msg else "```None```")
async def texttohex(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: e = Embed(title="Text to Hexadecimal", description=funcs.formatting( text.encode('utf-8').hex())) except Exception: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def hextobinary(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: number = int(text.replace(" ", ""), 16) e = Embed(title="Hexadecimal to Binary", description=funcs.formatting( bin(int(number)).replace("0b", ""))) except Exception: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def hextodecimal(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: hexnumber = text.replace(" ", "") e = Embed(title="Hexadecimal to Decimal", description=funcs.formatting( funcs.removeDotZero(int(hexnumber, 16)))) except ValueError: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def decimaltohex(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: number = int(text.replace(" ", "").replace(",", "")) e = Embed(title="Decimal to Hexadecimal", description=funcs.formatting( hex(number).split("x")[-1])) except ValueError: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def binarytohex(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: text = text.replace(" ", "") hstr = "%0*X" % ((len(text) + 3) // 4, int(text, 2)) e = Embed(title="Binary to Hexadecimal", description=funcs.formatting(hstr)) except Exception: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def literalenglish(self, ctx, *, inp): res = "" try: inplist = inp.split()[:10] output = Translator().translate(inplist, dest="zh-tw") for t in output: res += t.text e = Embed(title="Literal English", description=funcs.formatting(res)) except Exception as ex: funcs.printError(ctx, ex) e = funcs.errorEmbed(None, "Rate limit reached, try again later.") await ctx.reply(embed=e)
async def literalchinese(self, ctx, *, inp): res = "" try: inplist = list(inp.replace(" ", ""))[:10] output = Translator().translate(inplist, dest="en") for t in output: res += f"{t.text} " e = Embed(title="Literal Chinese", description=funcs.formatting(res)) except Exception as ex: funcs.printError(ctx, ex) e = funcs.errorEmbed(None, "Rate limit reached, try again later.") await ctx.reply(embed=e)
async def milestokm(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: number = float(text.replace(" ", "").replace(",", "")) value = round(number * 1.609344, 5) e = Embed(title="Miles to Kilometres", description=funcs.formatting( funcs.removeDotZero(value) + " km")) except ValueError: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def kgtolbs(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: number = float(text.replace(" ", "").replace(",", "")) value = round(number * 2.2046226218, 5) e = Embed(title="Kilograms to Pounds", description=funcs.formatting( funcs.removeDotZero(value) + " lbs")) except ValueError: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def ftc(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: number = float(text.replace(" ", "").replace(",", "")) value = round((number - 32) * 5 / 9, 5) e = Embed(title="Fahrenheit to Celsius", description=funcs.formatting( funcs.removeDotZero(value) + "°C")) except ValueError: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def bartersim(self, ctx, goldingots: str = "1"): try: try: goldingots = int(goldingots) except: goldingots = int(goldingots[:-1]) * 9 if not 0 < goldingots < 10001: return await ctx.reply(embed=funcs.errorEmbed( None, f"Value must be between 1 and 10,000.")) except ValueError: return await ctx.reply( embed=funcs.errorEmbed(None, "Invalid input.")) trades = {} string, glowdust, cryobby = 0, 0, 0 for _ in range(goldingots): trade = choice(self.loottable) if trade["id"] not in list(trades.keys()): trades[trade["id"]] = {} trades[trade["id"]]["item"] = trade["item"] n = choice(trade["quantity"]) trades[trade["id"]]["quantity"] = n trades[trade["id"]]["trades"] = 1 else: n = choice(trade["quantity"]) trades[trade["id"]]["quantity"] += n trades[trade["id"]]["trades"] += 1 if trade["id"] == 13: string += n elif trade["id"] == 10: glowdust += n elif trade["id"] == 19: cryobby += n res = "You bartered {:,} gold ingot{} for:\n\n".format( goldingots, "" if goldingots == 1 else "s") for i in sorted(trades): t = trades[i] res += "{}{:,} x {} ({:,} trade{})\n".format( "*** " if i in [7, 8, 10, 12, 13, 18, 19] else " ", t["quantity"], t["item"], t["trades"], "" if t["trades"] == 1 else "s") anchors = self.chargeableAnchors(glowdust, cryobby) beds = string // 12 explosives = anchors + beds if explosives: res += "\nExplosives you can craft ({:,}):\n\n".format(explosives) if beds: res += " {:,} x Bed\n".format(beds) if anchors: res += " {:,} x Respawn Anchor (w/ enough glowstone to power)".format( anchors) await ctx.reply(funcs.formatting(res))
async def exec(self, ctx, *, cmd): try: obj = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=False if system() == "Windows" else True) e = discord.Embed(description=funcs.formatting( obj.stdout.read().decode("utf-8"))) obj.kill() except Exception as ex: e = funcs.errorEmbed(None, str(ex)) await ctx.reply(embed=e)
async def brainfucktotext(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: interpreter = BrainfuckInterpreter(text) while interpreter.available(): interpreter.step() e = Embed(title="Brainfuck to Text", description=funcs.formatting( interpreter.getOutput().read())) except Exception as ex: e = funcs.errorEmbed(None, str(ex)) await ctx.reply(embed=e)
async def binarytotext(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: text = text.replace(" ", "") e = Embed( title="Binary to Text", description=funcs.formatting("".join(chr(int(text[i * 8:i * 8 + 8], 2)) \ for i in range(len(text) // 8))) ) except Exception: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def dtd(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: number = float(text.replace(" ", "").replace(",", "")) number = 0 if number == 360 else number if not 0 <= number < 360: raise ValueError e = Embed(title="Degrees to Cardinal Direction", description=funcs.formatting( funcs.degreesToDirection(number))) except ValueError: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def ctf(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: number = float(text.replace(" ", "").replace(",", "")) e = Embed( title="Celsius to Fahrenheit", description=funcs.formatting( funcs.removeDotZero( round(funcs.celsiusToFahrenheit(number), 5)) + "°F")) except ValueError: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def hash(self, ctx, algo=None, *, msg=""): algorithms = [ "md5", "blake2b", "blake2s", "sha1", "sha224", "sha256", "sha384", "sha512", "sha", "md" ] if not algo: e = funcs.errorEmbed(None, "Please select a hashing algorithm.") else: algo = algo.casefold().replace("-", "").replace("_", "").strip() if algo not in algorithms: e = funcs.errorEmbed( "Invalid algorithm!", "Valid options:\n\n`MD5`, `BLAKE2b`, `BLAKE2s`, " + \ "`SHA1`, `SHA224`, `SHA256`, `SHA384`, `SHA512`" ) else: if algo.startswith("md"): algo = "MD5" output = str(hashlib.md5(msg.encode("utf-8")).hexdigest()) elif algo == "blake2b": algo = "BLAKE2b" output = str( hashlib.blake2b(msg.encode("utf-8")).hexdigest()) elif algo == "blake2s": algo = "BLAKE2s" output = str( hashlib.blake2s(msg.encode("utf-8")).hexdigest()) elif algo == "sha1" or algo == "sha": algo = "SHA1" output = str(hashlib.sha1(msg.encode("utf-8")).hexdigest()) elif algo == "sha224": algo = "SHA224" output = str( hashlib.sha224(msg.encode("utf-8")).hexdigest()) elif algo == "sha256": algo = "SHA256" output = str( hashlib.sha256(msg.encode("utf-8")).hexdigest()) elif algo == "sha384": algo = "SHA384" output = str( hashlib.sha384(msg.encode("utf-8")).hexdigest()) else: algo = "SHA512" output = str( hashlib.sha512(msg.encode("utf-8")).hexdigest()) e = Embed(title=algo, description=funcs.formatting(output)) await ctx.reply(embed=e)
async def gentext(self, ctx, *, text=""): try: if text: await ctx.send("Processing text. Please wait...") data = {"text": text} res = await funcs.postRequest( "https://api.deepai.org/api/text-generator", data=data, headers={"api-key": config.deepAIKey}) data = res.json() e = Embed(title="Text Generation", description=funcs.formatting(data["output"])) except Exception as ex: funcs.printError(ctx, ex) e = funcs.errorEmbed(None, "Invalid input or server error.") await ctx.reply(embed=e)
async def texttomorse(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: output = "" for char in text: try: output += self.morsecode[char.upper()] + " " except: continue output = output[:-1] e = Embed(title="Text to Morse Code", description=funcs.formatting(output)) except Exception: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def fttocm(self, ctx, feet, inches=""): try: feet = feet.replace("′", "") if not feet: raise ValueError feet = float(feet) inches = inches.replace("″", "") if not inches: inches = 0 else: inches = float(inches) value = (feet * 12 + inches) * 2.54 e = Embed(title="Feet & Inches to Centimetres", description=funcs.formatting( funcs.removeDotZero(value) + " cm")) except ValueError: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)
async def cmtoft(self, ctx, *, text: str = ""): if text == "": e = funcs.errorEmbed(None, "Cannot process empty input.") else: try: number = float(text.replace(" ", "").replace(",", "")) totalinches = number / 2.54 totalfeet = totalinches / 12 feet = int(totalfeet) e = Embed(title="Centimetres to Feet & Inches", description=funcs.formatting( "{} ft {} in ({} ft OR {} in)".format( funcs.removeDotZero(feet), funcs.removeDotZero( round(totalinches - (feet * 12), 5)), funcs.removeDotZero(round(totalfeet, 5)), funcs.removeDotZero(round(totalinches, 5))))) except ValueError: e = funcs.errorEmbed(None, "Conversion failed. Invalid input?") await ctx.reply(embed=e)