Netshroud Posted January 24, 2010 Share Posted January 24, 2010 Hi, I'm developing an IRC Bot, and was wondering if there's any way to simplify what I've done, so it isn't messy (e.g. reduce the nested tuples, simplifying the user mode changes). import sys import socket import string #Settings HOST="irc3.zone-9.net" PORT=6667 NICK="Psyduck" IDENT="Psyduck" REALNAME="Psychosis" #Seems not to do anything, TODO: look into it CHANNELS=["#<redacted>"] #Channels to join on connection NICKPASS="<redacted>" ADMIN_HOSTMASK=["Psychosis!Psychosis@127.184.168.98"] #Nick and hostmask of bot's admin(s). readbuffer="" #User modes powerlevels = { "" : 0, "+": 1, "%": 2, "@": 4, "&": 8, "~": 16} def getsymbol( powerlevel ): if (powerlevel >= 32): return "" for k in powerlevels: if powerlevels[k] == powerlevel: return k power=0 for k in powerlevels: if powerlevels[k] < powerlevel: power+=powerlevels[k] return getsymbol((power+1)/2) #Connect to the server s=socket.socket( ) s.connect((HOST, PORT)) #Set Nick s.send("NICK %s\r\n" % NICK) s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME)) #Identify to NickServ s.send("PRIVMSG NickServ :IDENTIFY %s\r\n" % NICKPASS) #Join channels and initialise user cache chancount=0 users=list() for chan in CHANNELS: s.send("JOIN %s\r\n" % chan) users.append([chan, list()]) quit=0 while (quit==0): readbuffer=readbuffer+s.recv(1024) temp=string.split(readbuffer, "\n") readbuffer=temp.pop( ) for recvline in temp: recvline=string.rstrip(recvline) #print(recvline) #For debug purposes, mostly. line=string.split(recvline) #Reply to pings so the server doesn't drop us if(line[0]=="PING"): s.send("PONG %s\r\n" % line[1]) #Initialise user cache for channel if(line[1]=="353"): for chanlist in users: if (chanlist[0]==line[4]): chanlist[1]=list() for user in line[5:]: if user[:1]==":": user = user[1:] if(user[:1] in ['+','%','@','&','~']): #Probably should recode this if to take advantage of the powerlevels dictionary if (powerlevels.get(user[:1]) > 4): chanlist[1].append([user[1:], powerlevels.get(user[:1]) + 4 ]) else: chanlist[1].append([user[1:], powerlevels.get(user[:1])]) else: chanlist[1].append([user,0]) #!kick command if(line[1]=="PRIVMSG" and line[2].startswith("#") and line[3][1:]=="!kick"): if(len(line)>=5): if (line[4] == NICK): s.send("PRIVMSG %s :\x01ACTION is confused!\x01\r\n" % line[2]) #Pokemon reference #1 else: my_level=0 target_level=0 for chan in users: if chan[0]==line[2]: for user in chan[1]: if (user[0]==NICK): my_level=user[1] if (user[0]==line[4]): target_level=user[1] if (target_level < my_level): #Only kick users that are lower than us. i.e. if we're opped, don't try to kick the owner. s.send("PRIVMSG %s :\x01ACTION used Psybeam!\x01\r\n" % line[2]) #Pokemon reference #2 s.send("KICK %s %s :It's super effective!\r\n" % (line[2], line[4])) else: s.send("PRIVMSG %s :Nice try.\r\n" % line[2]) else: s.send("KICK %s :%s\r\n" % (line[2], line[0].split("!")[0][1:])) #Kick the person who said "!kick" if they didn't specify a user #!nicks command - print nicks cache if(line[0][1:] in ADMIN_HOSTMASK and line[1]=="PRIVMSG" and line[3][1:]=="!nicks"): for chan in users: nickslistsingleline="" for nick in chan[1]: if (len(line)>4 and line[4]=="nosym"): #symbols are sometimes annoying nickslistsingleline="%s %s" % (nickslistsingleline, nick[0]) else: nickslistsingleline="%s %s%s" % (nickslistsingleline, getsymbol(nick[1]), nick[0]) nickslistsingleline="Users in %s:%s" % (chan[0], nickslistsingleline) if(line[2].startswith("#")): s.send("PRIVMSG %s :%s\r\n" % (line[2], nickslistsingleline)) else: s.send("PRIVMSG %s :%s\r\n" % (line[0].split("!")[0][1:], nickslistsingleline)) #!nicks command - print nicks cache if(line[0][1:] in ADMIN_HOSTMASK and line[1]=="PRIVMSG" and line[3][1:]=="!nickdebug"): print(users) #remove a user who left the channel from the cache if(line[1]=="PART" or line[1]=="QUIT" or line[1]=="KICK"): if(line[1]=="KICK"): parteduser=line[3] else: parteduser=line[0].split("!")[0][1:] for chanlist in users: for nicks in chanlist[1]: if nicks[0]==parteduser: parteduser=[parteduser, nicks[1]] i=0 if(not parteduser==NICK): while (i<len(users)): if(users[i][0]==line[2]): users[i][1].remove(parteduser) i=i+1 if( line[1]=="PART" ): print("%s has left %s" % (parteduser[0], line[2])) elif(line[1]=="QUIT"): print("%s has quit: %s" % (parteduser[0], " ".join(line[2:])[1:])) elif(line[1]=="KICK"): print("%s was kicked from %s by %s : %s" % (parteduser[0], line[2], line[0].split("!")[0][1:], " ".join(line[4:])[1:])) #add a user who joined to the cache if(line[1]=="JOIN" and not line[0].split("!")[0][1:]==NICK): joineduser=line[0].split("!")[0][1:] i=0 while (i<len(users)): if(users[i][0]==line[2][1:]): users[i][1].append([joineduser, 0]) i=i+1 print("%s has joined %s" % (joineduser, line[2][1:])) #update cache if a user changes their nick if(line[1]=="NICK"): newmodeuser=line[0].split("!")[0][1:] i=0 while(i<len(users)): j=0 while(j<len(users[i][1])): if (users[i][1][j][0]==newmodeuser): users[i][1][j]=[ line[2][1:], users[i][1][j][1] ] j=j+1 i=i+1 #update cache when user is (de)voice/hop/op/sop/owner-ed #Following ^Doom^'s advice - it's safe to assume that an owner or SOP is also opped. This won't work if someone screws around with the modes though #such as -o'ing an owner or SOP, then de-(own/SOP)ing them. if(line[1]=="MODE" and line[2][:1]=="#"): count=1 while (count < len(line)-3): user = line[count+3] mode = line[3][count:][:1] newmode=0 if (line[3][:1]=="+"): if(mode=='v'): newmode=1 elif(mode=='h'): newmode=2 elif(mode=='o'): newmode=4 elif(mode=='a'): newmode=8 elif(mode=='q'): newmode=16 elif (line[3][:1]=="-"): if(mode=='v'): newmode=-1 elif(mode=='h'): newmode=-2 elif(mode=='o'): newmode=-4 elif(mode=='a'): newmode=-8 elif(mode=='q'): newmode=-16 i=0 while(i<len(users)): if(users[i][0]==line[2]): j=0 while(j<len(users[i][1])): if (users[i][1][j][0]==user): users[i][1][j][1]+=newmode j=j+1 i=i+1 count=count+1 #Rejoin when kicked. if(line[1]=="KICK" and not line[0].split("!")[0][1:]==NICK and line[3]==NICK): s.send("JOIN %s\r\n" % line[2]) s.send("PRIVMSG %s :That wasn't very nice of you, %s.\r\n" % (line[2], line[0].split("!")[0][1:])) #Tell off the user who kicked us. #Join a channel when told to by the bot's admin if(line[0][1:] in ADMIN_HOSTMASK and line[1]=="PRIVMSG" and not line[2].startswith("#") and line[3][1:]=="join" and line[4].startswith("#")): s.send("JOIN %s\r\n" % line[4]) chanfound=0 for chan in users: if (chan[0]==line[4]): chanfound=1 if (chanfound==0): users.append([line[4],list()]) #Leave a channel when told to by the bot's admin if(line[0][1:] in ADMIN_HOSTMASK and line[1]=="PRIVMSG" and not line[2].startswith("#") and line[3][1:]=="part" and line[4].startswith("#")): s.send("PART %s\r\n" % line[4]) i=0 while (i<len(users)): if (users[i][0]==line[4]): users[i][1]=list() i=i+1 #Quit when told to by the bot's admin if(line[0][1:] in ADMIN_HOSTMASK and line[1]=="PRIVMSG" and line[3][1:]=="!quit"): s.send("QUIT :%s fainted!\r\n" % NICK) #Pokemon reference #3 quit=1 #Say something when told to by bot's admin if(len(line)>5 and line[0][1:] in ADMIN_HOSTMASK and line[1]=="PRIVMSG" and not line[2].startswith("#") and line[3][1:]=="say"): s.send("PRIVMSG %s :%s\r\n" % (line[4], " ".join(line[5:]))) #/me when told to by bot's admin if(len(line)>5 and line[0][1:] in ADMIN_HOSTMASK and line[1]=="PRIVMSG" and not line[2].startswith("#") and line[3][1:]=="act"): s.send("PRIVMSG %s :\x01ACTION %s\x01\r\n" % (line[4], " ".join(line[5:]))) (I was going to call is Psybot, but thought Psyduck would be better. Please don't bash me ) Quote Link to comment Share on other sites More sharing options...
555 Posted January 25, 2010 Share Posted January 25, 2010 Very nice, what does the import syntax do at the top? import modules or functions? like perhaps another *.py file to use with this one? I am just starting out using Python 2.5 IDLE.. Is it easy to import other languages to use with python or to build webapps with python like php? Quote Link to comment Share on other sites More sharing options...
Netshroud Posted January 25, 2010 Author Share Posted January 25, 2010 Imports modules to my understanding. What do you mean by 'import other languages'? (Updated code in original post to latest version) Quote Link to comment Share on other sites More sharing options...
555 Posted January 25, 2010 Share Posted January 25, 2010 Import other languages, I guess meaning using python in combination with another language. Sort of how HTML, you can put PHP and Javascript in it and they all work together good. Is Python compatible like this with alot of other languages? and when importing a module in python you dont have to put an extention such as "Import socket.py" or "Import socket.h"? so it just auto assumes you are importing a *.py file that the import is calling thats in the same directory? thanks man Quote Link to comment Share on other sites More sharing options...
Netshroud Posted January 25, 2010 Author Share Posted January 25, 2010 No clue on the cross-language integration. Import doesn't require a .py, looks like it just assumes it's .py Quote Link to comment Share on other sites More sharing options...
GeekGoneCrazy Posted January 30, 2010 Share Posted January 30, 2010 Wow! You put a lot of work into that! A whole lot more then the bot I built a while back! Here Which I think I heavily followed some of the existing bots. Quote Link to comment Share on other sites More sharing options...
Zimmer Posted January 31, 2010 Share Posted January 31, 2010 Take a look at twisted, at first you will have a huge headache then you will be happy and gay singing away (I'll be glad to help :) also see irc.freenode.net #twisted and twistedmatrix.com) Quote Link to comment Share on other sites More sharing options...
Netshroud Posted January 31, 2010 Author Share Posted January 31, 2010 Thanks, I'll have a look at it. That said, I have almost finished recoding Psybot/Psyduck so it's Object-Oriented, alot easier to read and modify, neater, and not so repetitive. I'll post it here once I finish recoding and testing the User Cache system. Quote Link to comment Share on other sites More sharing options...
Zimmer Posted January 31, 2010 Share Posted January 31, 2010 will enjoy lookig at the code :) Quote Link to comment Share on other sites More sharing options...
Netshroud Posted January 31, 2010 Author Share Posted January 31, 2010 Might need to do a little more work, but here is Psybot 1.1a: #!/usr/bin/python2.6 import sys import socket import string import thread from time import strftime # ######################################################### # ## Psybot Settings ## # ######################################################### #Server to connect to server = 'irc.some-server.com:6667' #Bot's Nickname nick = 'Psybot' #Bot's Identification ident = 'Psybot 1.1a' #Real Name of bot realName = 'Psybot' #Channels to join on connection channels = [ '#somechannel', '#someotherchannel'] nickservPass = 'lamepassword' #Character indicating a command. Most bots seem to use '!'. commandChar = '^' #CTCP Version: version = 'Psybot v1.1 by Psychosis' # ######################################################### # ## IRC Class ## # ######################################################### class IRCConnection: #More Settings: #Hostmasks of admins adminHostMasks = [ 'Some!Controller@somewhere', 'Another!Trusted@person'] #Quit and Part messages: quitMessage = '*yawn*' partMessage = 'I\'m falling aPART.' kickReason = 'with a steel boot' #Output everything to console debug = False #Log everything to file logToFile = False #Location (absolute or relative) of log files logFileLocation= '.' queue = [] partial = '' users = [] powerlevels = { '' : 0, '+': 1, '%': 2, '@': 4, '&': 8, '~': 16} def getModeSymbol( powerlevel ) : if (powerlevel >= 32) : return '' for k in powerlevels : if powerlevels[k] == powerlevel : return k power=0 for k in powerlevels : if powerlevels[k] < powerlevel : power+=powerlevels[k] return getsymbol((power+1)/2) def __init__ ( self, network, port, name, hostName, realName ) : self.network = network self.port = int ( port ) self.hostName = hostName self.realName = realName self.socket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM ) self.socket.connect ( ( self.network, self.port ) ) self.nick ( name ) self.send ( 'USER ' + self.name + ' ' + self.hostName + ' * :' + self.realName ) if self.logToFile : self.logFile = open(strftime('%Y-%m-%d_%H-%M-%S.log'), 'w') def send ( self, text ) : self.socket.send ( text + '\r\n' ) def quit ( self ) : self.send ( 'QUIT :%s' % self.quitMessage ) def nick ( self, name ) : self.name = name self.send ( 'NICK ' + self.name ) def privmsg ( self, destination, message ) : self.send ( 'PRIVMSG ' + destination + ' :' + message ) def notice ( self, destination, message ) : self.send ( 'NOTICE %s :%s' % ( destination, message ) ) def join ( self, channel ) : self.send ( 'JOIN %s' % channel ) def part ( self, channel ) : self.send ( 'PART %s :%s'% ( channel, self.partMessage ) ) i = 0 while i < len ( self.users ) : if self.users [ i ][ 0 ] == channel : self.users.remove ( self.users [ i ] ) i+=1 def cycle ( self, channel ) : self.part ( channel ) self.join ( channel ) def topic ( self, channel, topic = '' ) : self.send ( 'TOPIC ' + channel + ' ' + topic ) def names ( self, channel ) : self.send ( 'NAMES ' + channel ) def invite ( self, nick, channel ) : self.send ( 'INVITE ' + nick + ' ' + channel ) def mode ( self, channel, mode, nick = '' ) : self.send ( 'MODE ' + channel + ' ' + mode + ' ' + nick ) def kick ( self, channel, nick, reason = '' ) : if not nick == self.name : self.send ( 'KICK ' + channel + ' ' + nick + ' ' + reason ) def logwrite( self, data ) : if self.logToFile : logfile.write('%s\n' % data) logfile.flush() #Lets us read the log while the bot still has it open if self.debug: print(data) def recv ( self, size = 4096 ) : commands = self.socket.recv ( size ).split ( '\r\n' ) if len ( self.partial ) : commands [ 0 ] = self.partial + commands [ 0 ] self.partial = '' if len ( commands [ -1 ] ) : self.partial = commands [ -1 ] self.queue.extend ( commands [ :-1 ] ) else: self.queue.extend ( commands ) def retrieve ( self ) : if len ( self.queue ) : command = self.queue [ 0 ] self.queue.pop ( 0 ) return command else: return False def dismantle ( self, command ) : if command : #PING doesn't have the same format as other responses. #Whereas other responses are in the form: # :<source> <command> [<paramaters>] [: <more paramaters>] #PING is in the form PING :<source> #Here we flip it so it's parsed the same as other commands. if command [ :4 ] == 'PING' : command = ':%s %s' % ( command.split ( ':' ) [ 1 ] , command.split ( ':' ) [ 0 ].strip() ) source = command.split ( ':' ) [ 1 ].split ( ' ' ) [ 0 ] parameters = command.split ( ':' ) [ 1 ].split ( ' ' ) [ 1: ] if not len ( parameters [ -1 ] ) : parameters.pop() if command.count ( ':' ) > 1 : parameters.append ( ':'.join ( command.split ( ':' ) [ 2: ] ) ) return source, parameters #User Cache functions: def addUser ( self, channel, name, mode = 0 ) : i = 0 while i < len ( self.users ) : if self.users [ i ] [ 0 ] == channel: self.users [ i ] [ 1 ].append( [ name, mode ] ) i+=1 def delUser ( self, channel, name ) : i = 0 while i < len ( self.users ) : if self.users [ i ] [ 0 ] == channel: j = 0 while j < len ( self.users [ i ] [ 1 ] ) : if self.users[ i ] [ 1 ] [ j ] [ 0 ] == name : self.users[ i ] [ 1 ].remove ( [ self.users[ i ] [ 1 ] [ j ] [ 0 ], self.users[ i ] [ 1 ] [ j ] [ 1 ] ] ) j+=1 i+=1 def changeUserMode ( self, channel, name, mode ) : i = 0 while i < len ( self.users ) : if self.users [ i ] [ 0 ] == channel: j = 0 while j < len ( self.users [ i ] [ 1 ] ) : if self.users[ i ] [ 1 ] [ j ] [ 0 ] == name : self.users[ i ] [ 1 ] [ j ] [ 1 ] += mode j+=1 i+=1 def changeUserName ( self, name, newname ) : i = 0 while i < len ( self.users ) : j = 0 while j < len ( self.users [ i ] [ 1 ] ) : if self.users[ i ] [ 1 ] [ j ] [ 0 ] == name : self.users[ i ] [ 1 ] [ j ] [ 0 ] = newname j+=1 i+=1 def initUsers ( self, data ) : i=0 foundindex = -1 while i < len ( self.users ) : if self.users [ i ] [ 0 ] == data [ 1 ] [ 3 ] : foundindex = i i+=1 if foundindex == -1 : self.users.append ( [ data [ 1 ] [ 3 ], [] ] ) while i < len ( self.users ) : if self.users [ i ] [ 0 ] == data [ 1 ] [ 3 ] : foundindex = i i+=1 if foundindex >= 0 : for user in data [ 1 ] [ 4 ].strip().split ( ' ' ) : if user [ :1 ] in ['+','%','@','&','~'] : if self.powerlevels.get ( user [ :1 ] ) > 4 : self.users [ foundindex ] [ 1 ].append ( [ user [ 1: ], self.powerlevels.get ( user [ :1 ] ) + 4 ] ) else: self.users [ foundindex ] [ 1 ].append ( [ user [ 1: ], self.powerlevels.get ( user [ :1 ] ) ] ) else: self.users [ foundindex ] [ 1 ].append ( [ user, 0 ] ) #These functions dont need to be part of IRCCommand, but it can't hurt, right? def isAdminCommand ( self, data ) : if data [ 0 ] in self.adminHostMasks : return True else : return False def isChanMessage ( self, data ) : if data [ 1 ] [ 1 ] [ :1 ] == '#' : return true else : return false def isPrivateMessage ( self, data ) : return not isChanMessage ( data ) # ######################################################### # ## Main Program ## # ######################################################### def autoRecieve() : while True : irc.recv() irc = IRCConnection( server.split(':')[0], server.split(':')[1], nick, ident, realName ) thread.start_new_thread ( autoRecieve, () ) for channel in channels: irc.join ( channel ) quit=0 while not quit : data = irc.dismantle ( irc.retrieve() ) if data: if irc.debug : print ( data ) #Respond to server PINGs so we dont get dropped if data [ 1 ] [ 0 ] == 'PING' : irc.send ( 'PONG %s' % data [ 0 ] ) #Manage redirects (channels with +L) if data [ 1 ] [ 0 ] == '470' : i = 0 while ( i < len ( irc.users ) ) : if ( irc.users [ i ] [ 0 ] == data [ 1 ] [ 3 ] ): irc.users [ i ] [ 0 ] = data[ 1 ] [ len ( data [ 1 ] ) -1 ].lower() i+=1 if data [ 1 ] [ 0 ] == 'PRIVMSG' : #Reply to CTCP VERSION commands if data [ 1 ] [ 2 ] == '\x01VERSION\x01' : irc.notice ( data [ 0 ].split( '!' )[ 0 ], version ) if data [ 1 ] [ 2 ].split ( ' ' ) [ 0 ] [ :1 ] == commandChar : command = data [ 1 ] [ 2 ].split ( ' ' ) [ 0 ] [ 1: ].lower() arguments = data [ 1 ] [ 2 ].split ( ' ' ) [ 1: ] #Multikick #Usage: ^mkick nick1 nick2 nick3 ... if command == 'mkick' and len(data [ 1 ]) > 2 : for victim in arguments : irc.kick ( data [ 1 ] [ 1 ], victim ) #Kick someone #Usage: ^kick <nick> <reason> elif command == 'kick' : irc.kick ( data [ 1 ] [ 1 ], arguments [ 0 ], ' '.join ( arguments [ 1: ] ) ) #Say something #Usage: ^say <text> elif command == 'say' and irc.isAdminCommand ( data ) : irc.privmsg ( arguments [ 0 ], ' '.join ( arguments [ 1: ] ) ) irc.logwrite('SAID\t%s\t%s: %s' % ( data[ 1 ] [ 1 ], data [ 1 ] [ 2 ].split ( ' ' ) [ 1 ], ' ' .join ( data [ 1 ] [ 2 ].split ( ' ' ) [ 1: ] ) ) ) #Perform an action #Usage: ^do <action> elif ( command == 'do' or command == 'act' or command == 'action' ) and irc.isAdminCommand ( data ) : irc.privmsg ( arguments [ 0 ], '\x01ACTION %s\x01' % ' '.join ( arguments [ 1: ] ) ) irc.logwrite ( 'DID\t%s\t%s: %s' % ( data[ 1 ] [ 1 ], data [ 1 ] [ 2 ].split ( ' ' ) [ 1 ], ' ' .join ( data [ 1 ] [ 2 ].split ( ' ' ) [ 1: ] ) ) ) #Join channels #Usage: ^join #channel1 #channel2 #channel3 ... elif command == 'join' and irc.isAdminCommand ( data ) : for channel in arguments : irc.join ( channel ) #Leave channels #Usage: ^part #channel1 #channel2 #channel3 ... elif command == 'part' and irc.isAdminCommand ( data ) : for channel in arguments : irc.part ( channel ) #Cycle channels #Usage: ^cycle #channel1 #channel2 #channel3 ... elif command == 'cycle' and irc.isAdminCommand ( data ) : for channel in arguments : irc.part ( channel ) irc.join ( channel ) #Quit #Usage: ^quit elif command == 'quit' and irc.isAdminCommand ( data ) : irc.quit() quit=1 #Print nicks cache to console (DEBUG only) #Usage: ^nicksdbg elif command == 'nicksdbg' and irc.debug and irc.isAdminCommand ( data ) : print ( irc.users ) #Turns DEBUG mode on/off #Usage: ^debug <on|off> elif command == 'debug' and irc.isAdminCommand ( data ) : if len ( arguments ) == 1 : if arguments [ 0 ].lower() == 'on' : irc.debug = 1 elif arguments [ 0 ].lower() == 'off' : irc.debug = 0 #Change bot's nick #Usage: ^nick NewNick elif command == 'nick' and irc.isAdminCommand ( data ) : if len ( arguments ) == 1 : irc.nick ( arguments [ 0 ] ) else : if data [ 1 ] [ 1 ] [ :1 ] == '#' : irc.logwrite ( 'CHANMSG\t%s\t%s: %s' % ( data [ 1 ] [ 1 ], data [ 0 ].split ( '!' ) [ 0 ], data [ 1 ] [ 2 ] ) ) else : irc.logwrite ( 'PRIVATE\t%s\t%s: %s' % ( data [ 1 ] [ 1 ], data [ 0 ].split ( '!' ) [ 0 ], data [ 1 ] [ 2 ] ) ) #NAMES List if data [ 1 ] [ 0 ] == '353' : irc.initUsers ( data ) #User left the channel if data [ 1 ] [ 0 ] == 'PART' and not data [ 0 ].split ( ' ! ' ) == irc.name: irc.delUser ( data [ 1 ] [ 1 ], data [ 0 ].split ( '!' ) [ 0 ] ) #User joined the channel if data [ 1 ] [ 0 ] == 'JOIN' and not data [ 0 ].split ( ' ! ' ) == irc.name: irc.addUser ( data [ 1 ] [ 1 ], data [ 0 ].split ( '!' ) [ 0 ] ) #User quit if data [ 1 ] [ 0 ] == 'QUIT' and not data [ 0 ].split ( ' ! ' ) == irc.name: for channel in irc.users : irc.delUser ( channel[ 0 ], data [ 0 ].split ( '!' ) [ 0 ] ) #User changed their nick if data [ 1 ] [ 0 ] == 'NICK' : irc.changeUserName ( data [ 0 ].split ( '!' ) [ 0 ], data [ 1 ] [ 1 ] ) #Mode was changed if data [ 1 ] [ 0 ] == 'MODE' : if len ( data [ 1 ] ) > 3 : i = 0 nicks = data [ 1 ] [ 3 ].split ( ' ' ) while i < len ( nicks ) : modechange = data [ 1 ] [ 2 ] [ i+1: ][ :1 ] user = nicks [ i ] powerchange = 0 if modechange == 'v' : powerchange = 1 elif modechange == 'h' : powerchange = 2 elif modechange == 'o' : powerchange = 4 elif modechange == 'a' : powerchange = 8 elif modechange == 'q' : powerchange = 16 if data [ 0 ] [ 2 ] [ :1 ] == '-': powerchange *= -1 irc.changeUserMode ( data [ 1 ] [ 1 ], user, powerchange ) i+=1 irc.socket.close() I hope I haven't forgotten anything Edit: oops, turns out I forgot to get it to identify with nickserv. Will add that in for the next revision. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.