Example #1
0
    async def next_number(self, ctx: commands.Context):
        user_number = usernumber.generate(ctx.author.id)

        # Send out the generated number
        embed = Crombed(description="Your next number is: " + user_number,
                        author=ctx.author)
        await ctx.send(embed=embed)
Example #2
0
    async def b64encode(self, ctx: commands.Context, *, data: str):
        """ Encode a string to base64. """
        b64_text = base64.b64encode(bytes(data, "utf-8")).decode("utf-8")

        embed = Crombed(title="Base64 encoded data", description=b64_text)

        await ctx.send(embed=embed)
Example #3
0
    async def text2bf(self, ctx: commands.Context, *, text: str):
        """ Make a BF program that outputs the given text. """
        bf_program = string_to_bf(text)

        embed = Crombed(title="Brainfuck program", description=bf_program)

        await ctx.send(embed=embed)
Example #4
0
    async def executeBF(self, ctx: commands.Context, *, data: str):
        """ Execute and print the output of a BF program. """
        program_out = run_bf

        embed = Crombed(title="Brainfuck output", description=program_out)

        await ctx.send(embed=embed)
Example #5
0
 async def code(self, ctx: commands.Context):
     """ Look at cromgis's code! """
     embed = Crombed(
         title = "Source code",
         description = "cromgis is an open-source bot made by the /r/Ooer hivemind. See its code here:\nhttps://github.com/kaylynn234/Ooer-Discord-Bot"
     )
     await ctx.reply(embed=embed)
Example #6
0
    async def horse(self, ctx: commands.Context):
        """ Generate a horse from thishorsedoesnotexist.com/.com. """
        url = f"https://thishorsedoesnotexist.com/?{random_string(32)}"

        embed = Crombed(title="Horse", author=ctx.author).set_image(url=url)

        await ctx.send(embed=embed)
Example #7
0
    async def decompress(self, ctx: commands.Context, *, b64_text: str):
        """ Decompress base64-encoded, zlib-compressed data. """
        decoded = base64.b64decode(b64_text)
        decompressed = zlib.decompress(decoded).decode("utf-8")

        embed = Crombed(title="Decompressed data", description=decompressed)

        await ctx.send(embed=embed)
Example #8
0
    async def compress(self, ctx: commands.Context, *, data: str):
        """ Compress data with zlib (compression level 9). """
        compressed_data = zlib.compress(bytes(data, "utf-8"), 9)
        b64_text = base64.b64encode(compressed_data).decode("utf-8")

        embed = Crombed(title="Compressed data", description=b64_text)

        await ctx.send(embed=embed)
Example #9
0
 def __init__(self, bot):
     self.bot = bot
     self.craiyon_failure_embed = Crombed(
         title="Craiyon instance expired",\
         description="cromgis needs a new Craiyon link.\n"
         "[Follow the instructions on this webpage](https://colab.research.google.com/drive/1uGpVB4GngBdONlHebVJ5maVFZDV-gtIe)"
         " to get one, then do `ooer relink <new_link>` to restore `ooer craiyon`.",
     )
Example #10
0
    async def cat(self, ctx: commands.Context):
        """ Generate a cat from thiscatdoesnotexist.com. """
        url = f"https://thiscatdoesnotexist.com/?{random_string(32)}"

        embed = Crombed(
            title = "Cat"
        ).set_image(url=url)

        await ctx.reply(embed=embed)
Example #11
0
    async def mp4togifv(self, ctx: commands.Context, mp4_url: str):
        gifv_url = imgur.upload_image(
            path=mp4_url, title="cromgis video (Uploaded with PyImgur)").link

        embed = Crombed(title="GIF converted from MP4",
                        url=gifv_url,
                        author=ctx.author)

        await ctx.send(embed=embed)
Example #12
0
  async def vendingmachine(self, ctx: commands.Context):
      """Get something from the vending machine!"""
      # with help from lumien

      iemb = Crombed(
        title = random.choice(v_titles),
        description = vending_machine(),
        color_name = "teal"
      )
      await ctx.send(embed=iemb)
Example #13
0
    async def b64decode(self, ctx: commands.Context, *, b64_text: str):
        """ Decode a base64-encoded string. """
        while len(b64_text) % 4 != 0:
            b64_text += "="

        decoded_data = base64.b64decode(b64_text).decode("utf-8")

        embed = Crombed(title="Base64 decoded data", description=decoded_data)

        await ctx.send(embed=embed)
Example #14
0
 async def on_command_error(self, ctx: commands.Context,
                            exception: CommandError) -> None:
     # Ignore Command Not Found errors
     if type(exception) is CommandNotFound:
         return
     embed = Crombed(title=random.choice(failure_phrases),
                     description=str(exception),
                     color_name="red",
                     author=ctx.author)
     await ctx.send(embed=embed)
Example #15
0
 async def asherizeme(self, ctx: commands.Context):
     """Asherizes/de-asherizes you, making you speak in asherisms."""
     if not ctx.author.id == 286883056793681930:
       asherizeUser(str(ctx.author.id))
     else:
       embed = Crombed(
           title = random.choice(failure_phrases),
           description = "You are already Asher. It is impossible for you to use this. If you did, it would annihilate you.",
           color_name = "red",
           author = ctx.author
       )
       await ctx.send(embed=embed)
Example #16
0
    async def expectedValue(self, ctx: commands.Context, *, json_data: str):
        """ Calculate the expected value of a probability distribution. """
        try:
            probabilities = json.loads(json_data)
        except json.decoder.JSONDecodeError:
            return await ctx.send("Syntax error")

        prob_dist = ProbDist(probabilities)

        embed = Crombed(title="Expected value",
                        description=str(prob_dist.expected_value))
        await ctx.send(embed=embed)
Example #17
0
    async def standardDeviation(self, ctx: commands.Context, *,
                                json_data: str):
        """ Calculate the standard deviation of a probability distribution. """
        try:
            probabilities = json.loads(json_data)
        except json.decoder.JSONDecodeError:
            return await ctx.send("Syntax error")

        prob_dist = ProbDist(probabilities)

        embed = Crombed(title="Standard deviation",
                        description=str(prob_dist.standard_deviation))
        await ctx.send(embed=embed)
Example #18
0
    async def current_number(self, ctx: commands.Context):
        counter = usernumber.get_counter(ctx.author.id)

        # Number suffix
        th = "th"
        if counter[-1] == 1:
            th = "st"
        elif counter[-1] == 2:
            th = "nd"
        elif counter[-1] == 3:
            th = "rd"

        # Send out the user's current counter
        embed = Crombed(
            description=f"You are currently on your {counter}{th} number.",
            author=ctx.author)
        await ctx.send(embed=embed)
Example #19
0
    async def image(self, ctx: commands.Context, *, raw_text: str = None):
        """ Generate an image from text using the Text to Image API made by Scott Ellison Reed on deepai.org. """
        if raw_text:
            if is_mention(raw_text):
                # Evaluate mentions to nicknames
                user_id = extract_id(raw_text)
                processed_text = self.bot.get_user(user_id).display_name
            else:
                processed_text = raw_text
        else:
            processed_text = random_string(32)

        print(
            f"[garlic.py] Fetching an ooer image based on text \"{processed_text}\"..."
        )

        response = requests.post("https://api.deepai.org/api/text2img",
                                 data={
                                     "text": processed_text,
                                 },
                                 headers={
                                     "api-key": os.environ["DEEPAI_API_KEY"]
                                 }).json()

        try:
            url = response["output_url"]
        except KeyError:
            raise Exception(f"Expected key 'output_url': {str(response)}")

        embed = Crombed(
            title="Image",
            description=processed_text if raw_text else
            None,  # Only show the text cromgis used if the text came from a user
            author=ctx.author).set_image(url=url)

        await ctx.send(embed=embed)