Example #1
0
def repl(chans):

    con = ircConnection.IRCConnection(config.server, config.port)

    con.setNick(config.nick)
    con.setUser(config.userName,
                config.hostName,
                config.server,
                config.realName)

    setBot = False  # have we identified as a bot yet?

    devoiced = {}  # keep track of who's devoiced and when they can be revoiced
    while True:  # main REPL
        fromServer = con.receive()

        #  +v users whose punishments have expired
        cpy = devoiced.copy()
        for user in cpy: # cpy[u] is a tuple with (chan, time)
            if cpy[user][1] <= time.time():
                con.sendMessage("MODE " + cpy[user][0] + " +v " + user)
                del devoiced[user]

        if fromServer is not None:
            pingResponse = messageParser.pingHandler(fromServer)
            if pingResponse != "":
                con.sendMessage("PONG " + pingResponse)
                continue

            print fromServer

            mNick = messageParser.getNick(fromServer)
            mChan = messageParser.getChannel(fromServer)
            message = messageParser.getMessage(fromServer)
            isPM = messageParser.isPM(fromServer)

            if "End of /MOTD command." in fromServer and not setBot:
                setBot = True

                con.setBot(config.nick)

                if config.password != "":
                    con.authenticate(config.password)

                for chan in chans:
                    con.join(chan)


            if (('e' in message or 'E' in message) and
                    messageParser.getMessageType(fromServer) == "PRIVMSG" and
                    mNick != config.nick): # don't devoice ourselves

                badWord = ""
                for word in message.split():
                    if 'e' in word or 'E' in word:
                        badWord = word
                        break

                con.reply("'%s' is a horrid word!" % badWord,
                         mNick, mChan, isPM)
                if not isPM:
                    con.sendMessage("MODE " + mChan + " -v " + mNick)
                    devoiced[mNick] = (mChan, time.time() + 15)

            # make sure that new people get to talk,
            # and that rejoining doesn't get around a -v
            if (messageParser.getMessageType(fromServer) == "JOIN" and
                    mNick not in devoiced):
                con.sendMessage("MODE " + messageParser.chanFromJoin(fromServer)
                                          + " +v " + mNick)

            if mNick in config.admins:  #admin-only commands
                #to avoid accidental commands, ensure command has our prefix
                if messageParser.hasPrefix(fromServer):

                    if messageParser.isQuit(fromServer):
                        quitMessage = messageParser.partOrQuitMessage(fromServer)

                        con.quit(quitMessage)
                        break

                    if messageParser.isPart(fromServer):
                        partMessage = messageParser.partOrQuitMessage(fromServer)

                        if messageParser.partDefault(fromServer):
                            toPart = mChan # part current chan if none specified
                        else:
                            toPart = messageParser.getPartChannel(fromServer)

                        con.part(partMessage, toPart)

                #auto-join on any invite (by an admin)
                if messageParser.getMessageType(fromServer) == "INVITE":
                    con.join(message)

    time.sleep(0.5)
    con.close()
Example #2
0
serverName = "irc.foonetic.net"
realName = "joshz"

con = ioHandler.ircConnection("irc.foonetic.net")

con.setNick(nick)
con.setUser(userName, hostName, serverName, realName)

setMode = False # have we set +B yet?

unbans = {} # keep track of who we need to unban, and when.
while True: #main REPL
    input = con.receive()
    print input

    mNick = messageParser.getNick(input)
    mChan = messageParser.getChannel(input)
    message = messageParser.getMessage(input)
    
    if "End of /MOTD command." in input and not(setMode):
        setMode = True
        print "Setting mode +B"
        con.sendMessage("MODE " + nick + " +B") # indicate that we're a bot
    
    pingResponse = messageParser.pingHandler(input)
    if pingResponse != "":
        con.sendMessage("PONG " + pingResponse)
        #print(repr(pingResponse))
		
    #print(repr(getMessage(input)))