#NEWLINE# def HandleCommand( self , chan , user , cmd , args = None ) : #NEWLINE# #INDENT# client = self . client . _protocol . clientFromUsername ( user ) #NEWLINE# cmd = cmd . lower ( ) #NEWLINE# if ( chan in self . _root . channels ) : #NEWLINE# #INDENT# channel = self . _root . channels [ chan ] #NEWLINE# access = channel . getAccess ( client ) #NEWLINE# if ( cmd == 'info' ) : #NEWLINE# #INDENT# founder = self . client . _protocol . clientFromID ( channel . owner ) #NEWLINE# if founder : #NEWLINE# #INDENT# founder = ( 'Founder is <%s>' % founder . username ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# founder = 'No founder is registered' #NEWLINE# #UNINDENT# admins = [ ] #NEWLINE# for admin in channel . admins : #NEWLINE# #INDENT# client = self . client . _protocol . clientFromID ( admin ) #NEWLINE# if client : #NEWLINE# #INDENT# admins . append ( client . username ) #NEWLINE# #UNINDENT# #UNINDENT# users = channel . users #NEWLINE# antispam = ( 'on' if channel . antispam else 'off' ) #NEWLINE# if ( not admins ) : #NEWLINE# #INDENT# mods = 'no operators are registered' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# mods = ( '%i registered operator(s) are <%s>' % ( len ( admins ) , '>, <' . join ( admins ) ) ) #NEWLINE# #UNINDENT# if ( len ( users ) == 1 ) : #NEWLINE# #INDENT# users = '1 user is' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# users = ( '%i users are' % len ( users ) ) #NEWLINE# #UNINDENT# return ( '#%s info: Anti-spam protection is %s. %s, %s. %s currently in the channel.' % ( chan , antispam , founder , mods , users ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'topic' ) : #NEWLINE# #INDENT# if ( access in [ 'mod' , 'founder' , 'op' ] ) : #NEWLINE# #INDENT# args = ( args or '' ) #NEWLINE# channel . setTopic ( client , args ) #NEWLINE# return ( '#%s: Topic changed' % chan ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: You do not have permission to set the topic' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'unregister' ) : #NEWLINE# #INDENT# if ( access in [ 'mod' , 'founder' ] ) : #NEWLINE# #INDENT# channel . owner = '' #NEWLINE# channel . channelMessage ( ( '#%s has been unregistered' % chan ) ) #NEWLINE# self . Send ( ( 'LEAVE %s' % chan ) ) #NEWLINE# return ( '#%s: Successfully unregistered.' % chan ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: You must contact one of the server moderators or the owner of the channel to unregister a channel' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'changefounder' ) : #NEWLINE# #INDENT# if ( access in [ 'mod' , 'founder' ] ) : #NEWLINE# #INDENT# if ( not args ) : #NEWLINE# #INDENT# return ( '#%s: You must specify a new founder' % chan ) #NEWLINE# #UNINDENT# target = self . client . _protocol . clientFromUsername ( args ) #NEWLINE# if ( not target ) : #NEWLINE# #INDENT# return '#%s: cannot assign founder status to a user who does not exist' #NEWLINE# #UNINDENT# channel . changeFounder ( client , target ) #NEWLINE# channel . channelMessage ( ( '%s Founder has been changed to <%s>' % ( chan , args ) ) ) #NEWLINE# return ( '#%s: Successfully changed founder to <%s>' % ( chan , args ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: You must contact one of the server moderators or the owner of the channel to change the founder' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'spamprotection' ) : #NEWLINE# #INDENT# if ( access in [ 'mod' , 'founder' ] ) : #NEWLINE# #INDENT# if ( args == 'on' ) : #NEWLINE# #INDENT# channel . antispam = True #NEWLINE# channel . channelMessage ( ( '%s Anti-spam protection was enabled by <%s>' % ( chan , user ) ) ) #NEWLINE# return ( '#%s: Anti-spam protection is on.' % chan ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( args == 'off' ) : #NEWLINE# #INDENT# channel . antispam = False #NEWLINE# channel . channelMessage ( ( '%s Anti-spam protection was disabled by <%s>' % ( chan , user ) ) ) #NEWLINE# return ( '#%s: Anti-spam protection is off.' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# status = 'off' #NEWLINE# if channel . antispam : #NEWLINE# #INDENT# status = 'on' #NEWLINE# #UNINDENT# return ( '#%s: Anti-spam protection is %s' % ( reason , status ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'op' ) : #NEWLINE# #INDENT# if ( access in [ 'mod' , 'founder' ] ) : #NEWLINE# #INDENT# if ( not args ) : #NEWLINE# #INDENT# return ( '#%s: You must specify a user to op' % chan ) #NEWLINE# #UNINDENT# target = self . client . _protocol . clientFromUsername ( args ) #NEWLINE# if ( target and channel . isOp ( target ) ) : #NEWLINE# #INDENT# return ( '#%s: <%s> was already an op' % ( chan , args ) ) #NEWLINE# #UNINDENT# channel . opUser ( client , target ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: You do not have permission to op users' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'deop' ) : #NEWLINE# #INDENT# if ( access in [ 'mod' , 'founder' ] ) : #NEWLINE# #INDENT# if ( not args ) : #NEWLINE# #INDENT# return ( '#%s: You must specify a user to deop' % chan ) #NEWLINE# #UNINDENT# target = self . client . _protocol . clientFromUsername ( args ) #NEWLINE# if ( target and ( not channel . isOp ( target ) ) ) : #NEWLINE# #INDENT# return ( '#%s: <%s> was not an op' % ( chan , args ) ) #NEWLINE# #UNINDENT# channel . deopUser ( client , target ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: You do not have permission to deop users' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'chanmsg' ) : #NEWLINE# #INDENT# if ( access in [ 'mod' , 'founder' , 'op' ] ) : #NEWLINE# #INDENT# if ( not args ) : #NEWLINE# #INDENT# return ( '#%s: You must specify a channel message' % chan ) #NEWLINE# #UNINDENT# target = self . client . _protocol . clientFromUsername ( args ) #NEWLINE# if ( target and channel . isOp ( target ) ) : #NEWLINE# #INDENT# args = ( 'issued by <%s>: %s' % ( user , args ) ) #NEWLINE# #UNINDENT# channel . channelMessage ( args ) #NEWLINE# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: You do not have permission to issue a channel message' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'lock' ) : #NEWLINE# #INDENT# if ( access in [ 'mod' , 'founder' , 'op' ] ) : #NEWLINE# #INDENT# if ( not args ) : #NEWLINE# #INDENT# return ( '#%s: You must specify a channel key to lock a channel' % chan ) #NEWLINE# #UNINDENT# channel . setKey ( client , args ) #NEWLINE# return ( '#%s: Locked' % chan ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: You do not have permission to lock the channel' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'unlock' ) : #NEWLINE# #INDENT# if ( access in [ 'mod' , 'founder' , 'op' ] ) : #NEWLINE# #INDENT# channel . setKey ( client , '*' ) #NEWLINE# return ( '#%s: Unlocked' % chan ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: You do not have permission to unlock the channel' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'kick' ) : #NEWLINE# #INDENT# if ( access in [ 'mod' , 'founder' , 'op' ] ) : #NEWLINE# #INDENT# if ( not args ) : #NEWLINE# #INDENT# return ( '#%s: You must specify a user to kick from the channel' % chan ) #NEWLINE# #UNINDENT# if args . count ( ' ' ) : #NEWLINE# #INDENT# ( target , reason ) = args . split ( ' ' , 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# target = args #NEWLINE# reason = None #NEWLINE# #UNINDENT# if ( target in channel . users ) : #NEWLINE# #INDENT# target = self . client . _protocol . clientFromUsername ( target ) #NEWLINE# channel . kickUser ( client , target , reason ) #NEWLINE# return ( '#%s: <%s> kicked' % ( chan , target . username ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: <%s> not in channel' % ( chan , target ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: You do not have permission to kick users from the channel' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'mute' ) : #NEWLINE# #INDENT# if ( access in [ 'mod' , 'founder' , 'op' ] ) : #NEWLINE# #INDENT# if ( not args ) : #NEWLINE# #INDENT# return ( '#%s: You must specify a user to mute' % chan ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if args . count ( ' ' ) : #NEWLINE# #INDENT# ( target , duration ) = args . split ( ' ' , 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# target = args #NEWLINE# duration = ( - 1 ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# duration = float ( duration ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# return ( '#%s: Duration must be an integer!' % chan ) #NEWLINE# #UNINDENT# target = self . client . _protocol . clientFromUsername ( target ) #NEWLINE# channel . muteUser ( client , target , duration ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: You do not have permission to mute users' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'unmute' ) : #NEWLINE# #INDENT# if ( access in [ 'mod' , 'founder' , 'op' ] ) : #NEWLINE# #INDENT# if ( not args ) : #NEWLINE# #INDENT# return ( '#%s: You must specify a user to unmute' % chan ) #NEWLINE# #UNINDENT# target = self . client . _protocol . clientFromUsername ( args ) #NEWLINE# channel . unmuteUser ( client , target ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: You do not have permission to unmute users' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == 'mutelist' ) : #NEWLINE# #INDENT# if channel . mutelist : #NEWLINE# #INDENT# mutelist = dict ( channel . mutelist ) #NEWLINE# muted = [ ( '#%s: Mute list (%i entries):  ' % ( chan , len ( mutelist ) ) ) ] #NEWLINE# for user in mutelist : #NEWLINE# #INDENT# m = mutelist [ user ] . copy ( ) #NEWLINE# client = self . client . _protocol . clientFromID ( user ) #NEWLINE# if ( not client ) : #NEWLINE# #INDENT# del mutelist [ user ] #NEWLINE# continue #NEWLINE# #UNINDENT# message = ( self . client . _protocol . _format_time ( m [ 'expires' ] ) + ( ' by IP.' if m [ 'ip' ] else '.' ) ) #NEWLINE# muted . append ( ( '%s, %s' % ( client . username , message ) ) ) #NEWLINE# #UNINDENT# return muted #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: Mute list is empty!' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( cmd == 'register' ) : #NEWLINE# #INDENT# if client . isMod ( ) : #NEWLINE# #INDENT# if ( not args ) : #NEWLINE# #INDENT# args = user #NEWLINE# #UNINDENT# self . Send ( ( 'JOIN %s' % chan ) ) #NEWLINE# channel = self . _root . channels [ chan ] #NEWLINE# target = self . client . _protocol . clientFromUsername ( args ) #NEWLINE# if target : #NEWLINE# #INDENT# channel . setFounder ( client , target ) #NEWLINE# return ( '#%s: Successfully registered to <%s>' % ( chan , args . split ( ' ' , 1 ) [ 0 ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '#%s: User <%s> does not exist.' % ( chan , args ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not ( chan in self . _root . channels ) ) : #NEWLINE# #INDENT# return ( '#%s: You must contact one of the server moderators or the owner of the channel to register a channel' % chan ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ''