示例#1
0
    def on_pubmsg(self, connection, event):
        """Respond to command requests in public channels"""
        channel = event.target
        nick = event.source.nick
        message = event.arguments[0]

        url_regex = re.compile(
            r'(?i)\b((?:https?://|[a-z0-9.\-]+[.][a-z]{2,4}/)'
            r'(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))'
            r'+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|'
            r'''[^\s`!()\[\]{};:'".,<>?«»“”‘’]))''', re.IGNORECASE)

        if url_regex.search(message):
            message_list = [
                element for element in message.split(' ')
                if url_regex.match(element)
            ]
            for element in message_list:
                title = url_announce.parse_url(element)
                if title is not None:
                    self.say(channel, title)

        command_regex = re.compile(
            r'^(' + re.escape(self.nick) + '( |[:,] ?)'
            r'|' + re.escape(self.prefix) + ')'
            r'([^ ]*)( (.*))?$', re.IGNORECASE)

        if command_regex.match(message):
            command = command_regex.match(message).group(3)
            arguments = command_regex.match(message).group(5)
            self.do_command(event, self.channels[channel].is_oper(nick),
                            channel, command, arguments)
示例#2
0
    def on_pubmsg(self, connection, event):
        """Respond to command requests in public channels"""
        channel = event.target
        nick = event.source.nick
        message = event.arguments[0]

        url_regex = re.compile(
            r'(?i)\b((?:https?://|[a-z0-9.\-]+[.][a-z]{2,4}/)'
            r'(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))'
            r'+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|'
            r'''[^\s`!()\[\]{};:'".,<>?«»“”‘’]))''', re.IGNORECASE)

        if url_regex.search(message):
            message_list = [element for element in message.split(' ')
                            if url_regex.match(element)]
            for element in message_list:
                title = url_announce.parse_url(element)
                if title is not None:
                    self.say(channel, title)

        command_regex = re.compile(
            r'^(' + re.escape(self.nick) + '( |[:,] ?)'
            r'|' + re.escape(self.prefix) + ')'
            r'([^ ]*)( (.*))?$', re.IGNORECASE)

        if command_regex.match(message):
            command = command_regex.match(message).group(3)
            arguments = command_regex.match(message).group(5)
            self.do_command(event, self.channels[channel].is_oper(nick),
                            channel, command, arguments)
示例#3
0
 def do_command(self, event, isOper, source, command, arguments):
     """Commands the bot will respond to"""
     user = event.source.nick
     factoid = FactInfo.FactInfo().fcget(command, user)
     if factoid:
         self.say(source, factoid.format(user))
     elif command == "devour":
         if arguments is None or arguments.isspace():
             self.do(source, "noms {0}".format(user))
         else:
             self.do(
                 source,
                 "takes a large bite out of {0}".format(arguments.strip()))
     elif command == "dice":
         if arguments is None or arguments.isspace():
             self.say(
                 source, "Please tell me how many sides the die "
                 "should have. dice <num>")
         else:
             roll = dice.rollDie(arguments)
             self.say(source, roll)
     elif command == "slap":
         if arguments is None or arguments.isspace():
             self.do(
                 source,
                 "slaps {0} around a bit with a large trout".format(user))
         else:
             self.do(
                 source,
                 "slaps {0} around a bit with a large trout.".format(
                     arguments.strip()))
     elif command == "rot13":
         if arguments is None:
             self.say(
                 source, "I'm sorry, I need a message to cipher,"
                 " try \"!rot13 message\"")
         else:
             self.say(source, codecs.encode(arguments, 'rot13'))
     elif command == "bloat":
         if arguments is None:
             self.say(source, "{0} is bloat.".format(user))
         else:
             self.say(source, "{0} is bloat".format(arguments.strip()))
     elif command == "ddg":
         query = search.ddg(arguments)
         self.say(source, query)
         title = url_announce.parse_url(query)
         if title is not None:
             self.say(source, title)
     elif command == "w":
         query = search.wiki(arguments)
         self.say(source, query)
     elif command == "alw":
         query = search.alwiki(arguments)
         self.say(source, query)
     elif command == "gh":
         query = search.github(arguments)
         self.say(source, query)
     elif command == "help":
         self.say(
             source, "Available commands: ![devour, dice <num>, "
             "bloat <message>, slap, rot13 <message>, "
             "ddg <search>, w <search>, alw <search>, gh <search>, "
             "disconnect, die, help]")
     elif command == "disconnect":
         if isOper:
             self.disconnect(msg="I'll be back!")
         else:
             self.say(source, "You don't have permission to do that")
     elif command == "die":
         if isOper:
             #new_thread.join()
             self.die(msg="Bye, cruel world!")
         else:
             self.say(source, "You don't have permission to do that")
     else:
         self.connection.notice(
             user,
             "I'm sorry, {0}. I'm afraid I can't do that.".format(user))
示例#4
0
 def do_command(self, event, isOper, source, command, arguments):
     """Commands the bot will respond to"""
     user = event.source.nick
     factoid = FactInfo.FactInfo().fcget(command,user)
     if factoid:
         self.say(source,factoid.format(user))
     elif command == "devour":
         if arguments is None or arguments.isspace():
             self.do(source, "noms {0}".format(user))
         else:
             self.do(source, "takes a large bite out of {0}"
                     .format(arguments.strip()))
     elif command == "dice":
         if arguments is None or arguments.isspace():
             self.say(source, "Please tell me how many sides the die "
                      "should have. dice <num>")
         else:
             roll = dice.rollDie(arguments)
             self.say(source, roll)
     elif command == "slap":
         if arguments is None or arguments.isspace():
             self.do(source, "slaps {0} around a bit with a large trout"
                     .format(user))
         else:
             self.do(source, "slaps {0} around a bit with a large trout."
                     .format(arguments.strip()))
     elif command == "rot13":
         if arguments is None:
             self.say(source, "I'm sorry, I need a message to cipher,"
                      " try \"!rot13 message\"")
         else:
             self.say(source, codecs.encode(arguments, 'rot13'))
     elif command == "bloat":
         if arguments is None:
             self.say(source, "{0} is bloat.".format(user))
         else:
             self.say(source, "{0} is bloat".format(arguments.strip()))
     elif command == "ddg":
         query = search.ddg(arguments)
         self.say(source, query)
         title = url_announce.parse_url(query)
         if title is not None:
             self.say(source, title)
     elif command == "w":
         query = search.wiki(arguments)
         self.say(source, query)
     elif command == "alw":
         query = search.alwiki(arguments)
         self.say(source, query)
     elif command == "gh":
         query = search.github(arguments)
         self.say(source, query)
     elif command == "help":
         self.say(source, "Available commands: ![devour, dice <num>, "
                  "bloat <message>, slap, rot13 <message>, "
                  "ddg <search>, w <search>, alw <search>, gh <search>, "
                  "disconnect, die, help]")
     elif command == "disconnect":
         if isOper:
             self.disconnect(msg="I'll be back!")
         else:
             self.say(source, "You don't have permission to do that")
     elif command == "die":
         if isOper:
             #new_thread.join()
             self.die(msg="Bye, cruel world!")
         else:
             self.say(source, "You don't have permission to do that")
     else:
         self.connection.notice(user, "I'm sorry, {0}. I'm afraid I can't do that."
                           .format(user))