Exemplo n.º 1
0
    def set_random_state(self):
        seed()
        Ls = range(2, 8)

        self.feet = np.array([
            get_random_item(Ls),
            get_random_item(Ls),
            get_random_item(Ls),
            get_random_item(Ls)
        ])
Exemplo n.º 2
0
    async def meme(self, ctx, *, args: str = None):
        """Meme Generator. Format is <top>;<bottom>|<img_url>

        Alternatively, image could be an attachment so format is <top>;<bottom>"""

        loading_msg = await self.bot.send_message(
            ctx.message.channel, "Making memes, bear with me for a bit...")
        message = args
        img_url = None
        gif_index = None
        if args:
            msg_list = args.split('|', maxsplit=2)
            message = msg_list[0]
            if len(msg_list) > 1:
                img_url = msg_list[1].strip()
            if len(msg_list) > 2:
                try:
                    gif_index = int(msg_list[2])
                    logging.debug("gif_index = {}".format(gif_index))
                except ValueError:
                    logging.warning("Not a number")

        # Check if an attachment is present. Prioritize that
        if ctx.message.attachments and ctx.message.attachments[0].get('url'):
            img_url = ctx.message.attachments[0].get('url')
        if not img_url:
            # If no image provided, use a random subreddit
            subreddit = tools.get_random_item(list(tools.subreddits.values()))
            img_dict = tools.get_subreddit_image_list(subreddit)
            if not img_dict.get('error'):
                img_item = tools.get_random_item(img_dict.get('img_list', []))
                img_url = img_item if img_item else None

        img_result = tools.generate_meme_from_text(message, img_url, gif_index)
        if img_result:
            try:
                with io.BytesIO(img_result) as new_image:
                    filename = "{0}-{1}.{2}".format(
                        "meme",
                        datetime.now().strftime("%d-%m-%y_%H%M"), "png")
                    await self.bot.delete_message(loading_msg)
                    return await self.bot.send_file(ctx.message.channel,
                                                    fp=new_image,
                                                    filename=filename)
            except discord.HTTPException:
                logging.exception("Exception when uploading meme image.")
                return await self.bot.edit_message(
                    loading_msg,
                    new_content=
                    "The image I got was way too big I'm sorry :sob:")
            except Exception:
                logging.exception(
                    "Exception when trying to generate meme image")
                pass
        return await self.bot.edit_message(loading_msg, "wut")
Exemplo n.º 3
0
 def explore_alternative_actions(self, state):
     Qa_values = self.Q[state]
     Vmax = Qa_values.max()
     alternative_actions = [i for i in range(5) if Qa_values[i] >= Vmax / 2]
     if len(alternative_actions) != 0:
         return get_random_item(alternative_actions)
     else:
         return Qa_values.argmax()
Exemplo n.º 4
0
    def get_greedy_policy(self, state):
        assert state < 4096

        Qa_values = self.Q[state]
        Vmax = Qa_values.max()
        indices = [i for i in range(5) if Qa_values[i] == Vmax]

        return get_random_item(indices)
Exemplo n.º 5
0
    async def reddit(self, ctx):
        """Gets an image from a subreddit.

        Could also use the following inside the brackets instead to call a
        specific subreddit
        """
        subreddit = tools.subreddits.get(ctx.invoked_with)
        if not subreddit:
            subreddit = tools.get_random_item(list(tools.subreddits.values()))
        return await self.random_reddit_image(ctx.message, subreddit)
Exemplo n.º 6
0
 async def random_reddit_image(self, message, subreddit: str = 'Thinking'):
     img_dict = tools.get_subreddit_image_list(subreddit)
     if not img_dict.get('error'):
         img_item = tools.get_random_item(img_dict.get('img_list', []))
         if img_item:
             embed = discord.Embed(color=message.author.color)
             embed.set_image(url=img_item)
             return await self.bot.send_message(message.channel,
                                                embed=embed)
         else:
             return await self.bot.send_message(
                 message.channel,
                 ":thinking: | Couldn\'t find an image in this subreddit.")
     return await self.bot.send_message(
         message.channel, ":thinking: | {0}".format(img_dict.get('error')))
Exemplo n.º 7
0
 async def choose(self, *args):
     """Choose one or more items asked"""
     items = [text.replace(',', '') for text in args if text.lower() != "or"]
     size = len(items)
     if size == 0:
         return await self.bot.say("There wasn't anything to choose from. :cry:")
     elif size == 1:
         return await self.bot.say(
             "Well... I guess {0} since that's the only option!".format(
                 str(items[0])))
     else:
         item_chosen = tools.get_random_item(items)
         if item_chosen == "me":
             item_chosen = "you"
         return await self.bot.say("I choose... {0}!".format(
             str(item_chosen)))
Exemplo n.º 8
0
    async def get_mood(self, message):
        # Retrieve a random item from custom emojis from the server
        # Make sure the emojis are unrestricted otherwise they will be ignored
        custom_emojis = [emoji for emoji in self.bot.get_all_emojis() if not emoji.roles]

        if not custom_emojis:
            return await self.bot.say((
                "Aww... "
                "There's no custom emojis I can express in this server. "
                "In that case my mood is :poop:"))

        # Retrieve random emoji retrieved from server and format it to be shown on chat.
        emoji_string = tools.format_emoji(
            tools.get_random_item(custom_emojis))

        # Display on Discord
        new_msg = await self.bot.send_message(message.channel, "I'm feeling... " + emoji_string)
        await asyncio.sleep(1)
        await self.bot.edit_message(new_msg, new_content=(
                new_msg.content + "\n\t...for now anyways."))
Exemplo n.º 9
0
 def get_random_policy():
     return get_random_item(range(5))