Example #1
0
 def process_botnumeric(self, host, numeric, user, message):
     if self.config["numerics"].get(numeric, None) != None:
         commandMethod = getattr(self, self.config["numerics"][numeric])
         commandMethod(host, user, message)
     elif numeric == "NOTICE":
         utility.consoleMessage(VirBotLogType.NOTICE, message)
     else:
         utility.consoleMessage(VirBotLogType.SERVER, message)
Example #2
0
 def process_botcommand(self, sender, requester, command, message):
     if self.config["botcommands"].get(command, None) != None:
         utility.consoleMessage(
             VirBotLogType.RECEIVED,
             command + " command FROM " + requester + " (" + sender + ")")
         commandMethod = getattr(self, self.config["botcommands"][command])
         if (len(message.split()) == 1):
             commandMethod(requester, None)
         else:
             commandMethod(requester, message.replace(command, ""))
Example #3
0
 def numeric_333(self, host, user, message):
     topicinfo = message.split(' ')
     channel = topicinfo[0]
     setby = topicinfo[1]
     seton = datetime.datetime.fromtimestamp(int(float(
         topicinfo[2]))).strftime('%c')
     seton.replace("  ", " ")
     utility.consoleMessage(
         VirBotLogType.CHANNEL,
         "[TOPIC in #" + channel + "] Set By " + setby + " @ " + seton)
Example #4
0
def main(argv):
    sentUser = False
    sentNick = False

    irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    irc.connect((config["server"]["name"], config["server"]["port"]))

    botCommands = VirBotCommands(irc, config)
    botNumerics = VirBotNumerics(irc, config)

    try:
        while True:
            data = irc.recv(2048)
            if len(data) <= 0:
                continue

            if config["debugmode"]:
                print data

            if data.startswith('ERROR') == True:
                #TODO: Add proper error output and reconnection if configured
                utility.consoleMessage(VirBotLogType.ERROR, data)
                sys.exit()

            if data.find('PING') != -1 and data.find(u"\u0001PING") == -1:
                irc.send(config["irccommands"]["pong"].format(data.split()[1]))
                utility.consoleMessage(
                    VirBotLogType.SENT,
                    "PONG to SERVER" + " (" + data.split()[1][1:] + ")")
                continue

            if data.find(u"\u0001PING") != -1:
                requester = utility.getRequester(True, data)
                if requester != None:
                    pingindex = data.index(u"\u0001PING")
                    pingreply = data[pingindex:]
                    pingreply = pingreply.replace("\r\n", "")
                    irc.send(u"NOTICE " + requester + u" :" + pingreply +
                             u"\u0001\n")
                    utility.consoleMessage(
                        VirBotLogType.SENT,
                        "PONG to " + requester + " (" + pingreply[6:] + ")")
                    continue

            if sentUser == False:
                irc.send(config["irccommands"]["user"].format(
                    nick, nick, nick, realname))
                sentUser = True
                utility.consoleMessage(VirBotLogType.SENT, "USER")
                continue

            if sentUser and sentNick == False:
                irc.send(config["irccommands"]["nick"].format(nick))
                sentNick = True
                utility.consoleMessage(VirBotLogType.SENT,
                                       "NICK" + " (" + nick + ")")
                continue

            for lineText in data.split("\r\n"):
                messageMatches = re.search(
                    "(:[\\w\\.]+\\s)(\\d{3}\\s|[A-Z]+\\s)([\\w]+\\s)(.+)",
                    lineText)
                if messageMatches:
                    host = messageMatches.group(1)[1:-1]
                    numeric = messageMatches.group(2)[:-1]
                    user = messageMatches.group(3)[:-1]
                    message = messageMatches.group(4)[1:]
                    botNumerics.process_botnumeric(host, numeric, user,
                                                   message)
                    continue

                messageMatches = re.search(
                    "(:.+@.+\\s)([A-Z]+\\s)([\\w#]+\\s)(:?.+)", lineText)
                if messageMatches:
                    sender = messageMatches.group(1)[1:-1]
                    command = messageMatches.group(2)[:-1]
                    receiver = messageMatches.group(3)[:-1]
                    message = messageMatches.group(4)
                    message = message[1:] if message.startswith(
                        ":") else message
                    requester = utility.getRequester(
                        False, sender) if receiver == nick else receiver
                    commandLookup = message.split()[0]
                    botCommands.process_botcommand(sender, requester,
                                                   commandLookup, message)
                    continue

    except KeyboardInterrupt:
        botCommands.kill_command(None, None)
Example #5
0
 def numeric_376(self, host, user, message):
     utility.consoleMessage(VirBotLogType.GENERICBOLD, "[MOTD] " + message)
Example #6
0
 def numeric_353(self, host, user, message):
     names = message[message.find(':') + 1:]
     channel = message.split(':')[0][2:-1]
     utility.consoleMessage(VirBotLogType.CHANNEL,
                            "[USERS in #" + channel + "] " + names)
Example #7
0
 def numeric_332(self, host, user, message):
     topic = message[message.find(':') + 1:]
     channel = message.split(':')[0][:-1]
     utility.consoleMessage(VirBotLogType.CHANNEL,
                            "[TOPIC in #" + channel + "] " + topic)