Exemplo n.º 1
0
def main():
    main_conf()
    opers = {}
    mainconf, tasks, cmds = (
        ConfigParser.RawConfigParser(),
        ConfigParser.RawConfigParser(),
        ConfigParser.RawConfigParser(),
    )
    mainconf._file, tasks._file, cmds._file = ("taeniurus.cfg", "tasks.cfg", "cmds.cfg")
    mainconf.read(mainconf._file)
    tasks.read(tasks._file)
    cmds.read(cmds._file)
    pidfile = mainconf.get("info", "pid file")
    logspath = mainconf.get("info", "logs path")
    irc = IRC()
    bgproc = Process(target=header, args=(irc.server, irc.port))
    bgproc.start()
    client = irc.connect()

    if bgproc.is_alive():
        bgproc.terminate()

    print "\nConnected successfully!"
    print "Connection: \033[1m\033[92m%s:%d\033[0m" % (irc.server, irc.port)
    print "Channel: \033[1m\033[92m%s\033[0m" % irc.channel
    daemon(pidfile)

    acc_den = 'irc.notice("Access is denied!", nick)'
    done_msg = 'irc.notice("Done.", nick)'

    while True:
        try:
            data = client.recv(1024)
            arg, nick, user, joined, window = irc.parse(data)
            for section in tasks.sections():
                if tasks.get(section, "code"):
                    try:
                        exec tasks.get(section, "code")
                    except:
                        for op in opers:
                            irc.notice("A problem in tasks config file!", op)
                            irc.notice("File: %s" % tasks._file, op)
                            irc.notice("Section: %s" % section, op)

            if arg:
                args = arg.split()
                if len(args) < 1:
                    continue

                try:
                    if args[0] == "!oper" and user not in opers.values() and args[1] and args[2]:
                        if args[1] == mainconf.get("oper", "user"):
                            if hashlib.md5(args[2]).hexdigest() == mainconf.get("oper", "passwd"):
                                opers[nick] = user
                                irc.notice("You are appended into opers list.", nick)
                            else:
                                irc.notice("User or password incorrect!", nick)

                        else:
                            irc.notice("User or password incorrect!", nick)

                    if args[0] in cmds.sections():
                        if cmds.get(args[0], "access") == "oper" and user not in opers.values():
                            exec acc_den
                            continue

                        exec cmds.get(args[0], "code")

                except:
                    irc.notice("It's either an argument error or I'm unable to do it.", nick)

                if args[0] == "!quit" and user in opers.values():
                    qmsg = " ".join(args[1:]) if len(args) >= 2 else "Leaving"
                    irc.quit(qmsg)
                    import signal

                    pid = os.getpid()
                    os.kill(int(pid), signal.SIGKILL)

        except:
            raise Error(data, logspath)