Exemplo n.º 1
0
Arquivo: fun.py Projeto: kyanha/Helix3
 async def meow(self, ctx):
     """Get a random cat picture with custom text"""
     prefix = getPrefix(self.bot, ctx.message)
     message = ctx.message.content.replace(prefix, "")
     message = message.replace("meow", "").strip()
     message = message.replace(" ", "%20")
     url = "https://cataas.com/cat/says/{}".format(message)
     em = discord.Embed(colour=0x260068)
     em.set_image(url=url)
     await self.bot.say(embed=em)
Exemplo n.º 2
0
 async def urban(self, ctx):
     """Query Urban Dictionary"""
     await self.bot.send_typing(ctx.message.channel)
     message = ctx.message.content.strip()
     message = message.lower()
     messages = message.replace("urban ", "")
     messages = messages.replace(self.bot.user.mention, '')
     terms = messages.replace(getPrefix(self.bot, ctx.message), '')
     try:
         async with aiohttp.ClientSession(loop=self.bot.loop) as session:
             async with session.get(
                 ("http://api.urbandictionary.com/v0/define?term=" +
                  terms)) as r:
                 if not r.status == 200:
                     await self.bot.say(
                         "Unable to connect to Urban Dictionary")
                 else:
                     j = await r.json()
                     if j["result_type"] == "no_results":
                         msg = "No results for "
                         msg = msg + terms
                         em = discord.Embed(description=msg,
                                            colour=16711680)
                         em.set_author(
                             name='Urban',
                             icon_url=
                             "https://pilotmoon.com/popclip/extensions/icon/ud.png"
                         )
                         await self.bot.say(embed=em)
                         return
                     elif j["result_type"] == "exact":
                         word = j["list"][0]
                     definerer = (word["definition"])
                     n = ("%s - Urban Dictionary" % word["word"])
                     em = discord.Embed(description=definerer,
                                        colour=(random.randint(0,
                                                               16777215)))
                     em.set_author(
                         name=n,
                         icon_url=
                         "https://pilotmoon.com/popclip/extensions/icon/ud.png"
                     )
                     await self.bot.say(embed=em)
     except Exception as e:
         await self.bot.say(
             ("Unable to connect to Urban Dictionary " + str(e)))
Exemplo n.º 3
0
 async def google(self, ctx):
     """Searches google and gives you top result."""
     server = ctx.message.server
     channel = ctx.message.channel
     message = ctx.message.content.strip()
     message = message.lower()
     message = message.replace("google ", "")
     message = message.replace(self.bot.user.mention, '')
     query = message.replace(getPrefix(self.bot, ctx.message), '')
     try:
         entries = await self.get_google_entries(query)
     except RuntimeError as e:
         await self.bot.say(str(e))
     else:
         next_two = entries[3:5]
         if next_two:
             formatted = "\n"
             for item in next_two:
                 item = str(item)
                 formatted += "{}\n".format(
                     item.replace("(", "").replace("'", "").replace(
                         "\\n", "")[:-5] + "...")
             msg = formatted
         else:
             try:
                 msg = entries[0]
             except IndexError:
                 msg = "No results"
                 em = discord.Embed(description=msg, colour=16711680)
                 em.set_author(
                     name='Google:',
                     icon_url=
                     "https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/2000px-Google_%22G%22_Logo.svg.png"
                 )
                 await self.bot.send_message(channel, embed=em)
                 return
         em = discord.Embed(description=msg,
                            colour=(random.randint(0, 16777215)))
         em.set_author(
             name='Google:',
             icon_url=
             "https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/2000px-Google_%22G%22_Logo.svg.png"
         )
         await self.bot.send_message(channel, embed=em)
Exemplo n.º 4
0
    async def _chatbot(self, message):
        if self.unloading:
            # thanks to the wonders of async, theres a chance the cog could be in use DURING reload
            # this simple statement helps prevent that being a problem
            return
        try:
            await self.bot.send_typing(message.channel)
            sessionId = message.author.id
            sessionData = self.aiml_kernel.getSessionData(sessionId)

            if self.aiml_kernel.getPredicate("name", sessionId) == "":
                self.aiml_kernel.setPredicate("name", message.author.name, sessionId)

            string = message.content.replace("<@!{}>".format(self.bot.user.id), "")
            string = string.replace(self.bot.user.mention, '').replace('chatbot', '').replace(getPrefix(self.bot, message), '')
            string = string.lstrip()

            if (len(message.content) > 150):
                await self.bot.send_message(message.channel, self.toolong_message)
            else:
                aiml_response = self.aiml_kernel.respond(string, sessionId)
                await self.bot.send_message(message.channel, aiml_response)

        except Exception as e:
            fmt = 'An error occurred while processing that request: ```py\n{}: {}\n```'
            await self.bot.send_message(message.channel, fmt.format(type(e).__name__, e))
            await self.bot.send_message(message.channel, self.respondto_undefined)
Exemplo n.º 5
0
Arquivo: fun.py Projeto: kyanha/Helix3
 async def eightball(self, ctx):
     """Magic eightball"""
     channel = ctx.message.channel
     server = ctx.message.server
     await self.bot.send_typing(channel)
     dir = "data/settings/" + ctx.message.server.id + ".json"
     if not os.path.exists("data"):
         os.mkdir("data")
     if not os.path.exists("data/settings"):
         os.mkdir("data/settings")
     if not os.path.isfile(dir):
         prefix = getPrefix(self.bot, ctx.message)
     else:
         with open(dir, 'r') as r:
             data = json.load(r)
             prefix = str(data["prefix"])
     choice = "123"
     choice = random.choice(choice)
     message = ctx.message.content.strip()
     message = message.lower()
     message = message.replace("eightball ", "")
     message = message.replace(prefix, "")
     length = int(len(message))
     if length < 6:
         await self.bot.say("You didn't ask a question")
     else:
         if choice == "1":
             minichoice = random.randint(1, 10)
             if minichoice == 1:
                 await self.bot.send_message(channel, "It is certain")
             if minichoice == 2:
                 await self.bot.send_message(channel, "It is decidedly so")
             if minichoice == 3:
                 await self.bot.send_message(channel, "Without a doubt")
             if minichoice == 4:
                 await self.bot.send_message(channel, "Yes, definitely")
             if minichoice == 5:
                 await self.bot.send_message(channel, "You may rely on it")
             if minichoice == 6:
                 await self.bot.send_message(channel, "As I see it, yes")
             if minichoice == 7:
                 await self.bot.send_message(channel, "Most likely")
             if minichoice == 8:
                 await self.bot.send_message(channel, "Outlook good")
             if minichoice == 9:
                 await self.bot.send_message(channel, "Yes")
             if minichoice == 10:
                 await self.bot.send_message(channel, "Signs point to yes")
         if choice == "2":
             minichoice = random.randint(1, 5)
             if minichoice == 1:
                 await self.bot.send_message(channel,
                                             "Reply hazy try again")
             if minichoice == 2:
                 await self.bot.send_message(channel, "Ask again later")
             if minichoice == 3:
                 await self.bot.send_message(channel,
                                             "Better not tell you now")
             if minichoice == 4:
                 await self.bot.send_message(channel, "Cannot predict now")
             if minichoice == 5:
                 await self.bot.send_message(channel,
                                             "Concentrate and ask again")
         if choice == "3":
             minichoice = random.randint(1, 5)
             if minichoice == 1:
                 await self.bot.send_message(channel, "Don't count on it")
             if minichoice == 2:
                 await self.bot.send_message(channel, "My reply is no")
             if minichoice == 3:
                 await self.bot.send_message(channel, "My sources say no")
             if minichoice == 4:
                 await self.bot.send_message(channel, "Outlook not so good")
             if minichoice == 5:
                 await self.bot.send_message(channel, "Very doubtful")