Esempio n. 1
0
def main(args):
    global irc, flooder, socks5ip, socks5port

    getEventManager().addListener(LAZER_RECV, lazerParseHook)
    getEventManager().addListener(START_LAZER, lazerStartHook)
    getEventManager().addListener(IRC_RESTART, restartIRCHook)

    try:
        host = args[1]
        port = int(args[2])
        channel = args[3]
        if len(args[4:]):
            try:
                opts, argv = getopt.getopt(args[4:], "ts:", ["tor","socks5="])
            except getopt.GetoptError:
                print "Usage: python main.py <hivemind irc server> <irc port> <irc channel> [--tor] [--socks5=ip:port]"
                sys.exit()

            for o, a in opts:
                if o in ("-t", "--tor"):
                    socks5ip = "127.0.0.1"
                    socks5port = 9050
                elif o in ("-s", "--socks5"):
                    socks5 = a.split(':')
                    socks5ip = socket.gethostbyname(socks5[0])
                    socks5port = int(socks5[1])

    except (ValueError, IndexError):
        print "Usage: python main.py <hivemind irc server> <irc port> <irc channel> [--tor] [--socks5=ip:port]"
        sys.exit()

    if channel[0] != '#':
        channel = '#' + channel

    getEventManager().start()

    irc = IRC(host, port, channel)

    while running:
        try:
            i = raw_input()
            if i.find("connect") == 0:
                info = i.split(" ")
                print info
                if len(info) == 4 and info[2].isdigit():
                    newhost = info[1]
                    newport = int(info[2])
                    newchannel = info[3].replace("\\", "")
                    if newhost == host and newport == port and irc.connected:
                        print "changing channel to", newchannel
                        irc.changeChannel(newchannel)
                        channel = newchannel
                    else:
                        host = newhost
                        port = newport
                        channel = newchannel
                        print "changing host to", host, port, channel
                        irc.disconnect()
                        irc.host = host
                        irc.port = port
                        irc.channel = channel
                        irc.connect()
                else:
                    print "not enough info. connect server port channel"
            elif i == "stopflood":
                if flooder:
                    flooder.stop()
            elif i == "startflood":
                if flooder:
                    flooder.start()
            elif i == "floodcount":
                if flooder:
                    print flooder.floodCount()
            elif i == "quit" or i == "exit":
                irc.disconnect()
                if flooder:
                    flooder.stop()
                getEventManager().stop()
                break
        except KeyboardInterrupt:
            irc.disconnect()
            if flooder:
                flooder.stop()
            getEventManager().stop()
            break

    time.sleep(1)
    sys.exit()