def joinResp(server,i,otherStuff):#The join message #!--JOIN MSG--!# if "JOIN" in i: m = ResponseParser.parseMsg(i,False) if m is not False: #Make sure it's a JOIN msg. if m.typeMsg == "JOIN": #If it's you that JOINed, check if there is a TreeIter already for this channel #and if not then add one. if m.nick.lower() == server.cNick.lower(): addNewUser=True #Check if there is already a channel created... for ch in server.channels: if ch.cName == m.channel: addNewUser=False if addNewUser==True: nChannel = IRC.channel() nChannel.cName = m.channel nChannel.cTextBuffer = gtk.TextBuffer() nChannel.UserListStore = gtk.ListStore(str,str) try: nChannel.cTreeIter = server.listTreeStore.append(server.cTreeIter, \ [m.channel, None, otherStuff.settings.normalTColor, "channel"]) except: import traceback; traceback.print_exc() nChannel.cMsgBuffer = [] #This fixes the weird problem with the queue being in the wrong channel. #Add the newly JOINed channel to the Servers channel list server.channels.append(nChannel) #Send the MODE message, to ask for the MODE of the channel. server.cSocket.send("MODE " + m.channel + "\r\n") server.cSocket.send("WHO " + m.channel + "\r\n") else: #Add the user who JOINed to the list of users for ch in server.channels: if ch.cName == m.channel: usr=IRC.user() usr.cNick=m.nick usr.cChannel=ch usr.cTextBuffer = gtk.TextBuffer() ch.cUsers.append(usr) try: cIndex=findIndex(usr,server,ch) except: import traceback;traceback.print_exc() #Call the onUsersChange event for event in IRC.eventFunctions: if event.eventName == "onUserJoin" and event.cServer == server: #Set the users cTreeIter immediately event.aFunc(ch,server,cIndex,usr) #Might couse some random SEGFAULTS!!!!!!!!!!!!!! for event in IRC.eventFunctions: if event.eventName == "onJoinMsg" and event.cServer == server: gobject.idle_add(event.aFunc,m,server,otherStuff)
def userStuff(server,i):#The user list. global USERS if len(i.split(" ")) > 1: msgCode = i.split(" ")[1] else: return #!--USERS STUFF--!# if ("353" == msgCode): if i.startswith(":"): USERS += "\n" USERS += i if ("366" == msgCode): USERS += "\n" USERS += i m = ResponseParser.parseServer(i) for channel in server.channels: if channel.cName == m[0].channel: #Add the users correctly. pDebug("\033[1;34mParsed server msg 'channel' is " + m[0].channel + "\033[1;m") channel.cUsers = [] for user in ResponseParser.parseUsers(USERS,server,channel): usr = IRC.user() #Get the user mode. userF=user usr.cChannel=channel usr.cTextBuffer=gtk.TextBuffer() while(userF.startswith("*") or userF.startswith("!") or userF.startswith("@") or userF.startswith("%") or userF.startswith("+") or userF.startswith("~") or userF.startswith("&")): usr.cMode += userF[:1] userF=userF[1:] #Get the nickname. usr.cNick = user.replace(usr.cMode,"").replace(" ","") channel.cUsers.append(usr) pDebug("\033[1;32mAdded " + usr.cNick + " to " + channel.cName + " users list " + " with mode " + usr.cMode + "\033[1;m") USERS = "" for event in IRC.eventFunctions: if event.eventName == "onUsersChange" and event.cServer == server: #event.aFunc(channel,server) gobject.idle_add(event.aFunc,channel, server, priority=gobject.PRIORITY_HIGH)
def sendMsg(server,cChannel,msg): if "\n" in msg or len(msg) > 400: #If there are new lines in the msg if "\n" in msg: #Just split it into new lines. msgSplit=msg.split("\n") #Else, if the message is bigger then 400 characters else: #split the message into 400 characters msgSplit=[] iMsg=msg while (len(iMsg) > 400): msgSplit.append(iMsg[:400]) iMsg=iMsg[400:] msgSplit.append(iMsg) newMsgSplit=[] #Loop through the msgSplit to see if any of the messages are more then 400 characters for i in range(0,len(msgSplit)): if len(msgSplit[i]) > 400: #If this message is bigger then 400 characters then split it. iMsg=msgSplit[i] while (len(iMsg) > 400): newMsgSplit.append(iMsg[:400]) iMsg=iMsg[400:] newMsgSplit.append(iMsg) else: #If this message is not bigger then 400 characters, then add it to the new list without spliting it. newMsgSplit.append(msgSplit[i]) msgSplit=newMsgSplit #Loops through the parts of the message(the split message) for i in range(0,len(msgSplit)): if msgSplit[i] != "": import time instantMsg=False #If this is set to true the message won't be added to the msg buffer. #Loops through the channels to find the right channel, to append the new msgBuffer for ch in server.channels: usrDest=IRC.user() #Made it not None, it couses a bug with or ch.cName == usrDest.cChannel.cName, so i changed it to this... if cChannel.startswith("#") == False: for usr in ch.cUsers: if usr.cNick == cChannel: usrDest=usr if ch.cName == cChannel or ch.cName == usrDest.cChannel.cName: channel=ch pDebug("Setting channel to " + ch.cName) #If this message is the 5th message to be sent in a row, then add >the number of sendInstantly equal to False msgBuffers< * 3 #(So it waits 3 times the number of non instantly sent messages, to send this message.) if i >= 5: time=time.time() + (3*(len(channel.cMsgBuffer)+1)) elif i < 5 and len(channel.cMsgBuffer) != 0: time=time.time() + (3*(len(channel.cMsgBuffer)+1)) #Else, this is a message to be sent instantly. else: cmdSendMsg(server,cChannel,msgSplit[i]) instantMsg=True if instantMsg != True: msgBuff=IRC.msgBuffer() msgBuff.msg=msgSplit[i] msgBuff.sendTimestamp=time msgBuff.dest=cChannel channel.cMsgBuffer.append(msgBuff) #Call all the onByteSendChange events for event in IRC.eventFunctions: if event.eventName == "onByteSendChange" and event.cServer == server: gobject.idle_add(event.aFunc,server,len(channel.cMsgBuffer)) else: msgSent = False for ch in server.channels: usrDest=IRC.user() #Made it not None, it couses a bug with or ch.cName == usrDest.cChannel.cName, so i changed it to this... if cChannel.startswith("#") == False: for usr in ch.cUsers: if usr.cNick == cChannel: usrDest=usr if ch.cName == cChannel or ch.cName == usrDest.cChannel.cName: #If the msgBuffer(msg queue) has no messages waiting to be sent, send this message right now. if len(ch.cMsgBuffer) == 0: cmdSendMsg(server,cChannel,msg) msgSent = True break #If the msgBuffer(msg queue) has messages waiting, add this new message to the end of the queue. else: import time instantMsg=False #If this is set to true the message won't be added to the msg buffer. #If this message is the 5th message to be sent in a row, then add >the number of sendInstantly equal to False msgBuffers< * 3 #(So it waits 3 times the number of non instantly sent messages, to send this message.) if len(ch.cMsgBuffer) >= 5: time=time.time() + (3*(len(ch.cMsgBuffer)+1)) #Else, this is a message to be sent instantly. else: cmdSendMsg(server, ch.cName, msg) instantMsg = True msgSent = True if instantMsg != True: msgBuff=IRC.msgBuffer() msgBuff.msg=msg msgBuff.sendTimestamp=time msgBuff.dest=cChannel ch.cMsgBuffer.append(msgBuff) pDebug("\033[1;31mAdded to " + ch.cName) #Call all the onByteSendChange events for event in IRC.eventFunctions: if event.eventName == "onByteSendChange" and event.cServer == server: gobject.idle_add(event.aFunc,server,len(ch.cMsgBuffer)) break #If you can't find a message buffer for a channel or a user, just send the message #TODO: Maybe make it add to the server buffer ?? if msgSent == False: cmdSendMsg(server, cChannel, msg)