Example #1
0
 def on_quit(self, c, e):
     nick = nm_to_n(e.source())
     userHost = nm_to_uh(e.source())
     for name, ch in self.channels.items():
         if ch.has_user(nick):
             self.log(name, "* " + nick + " (" + userHost + ") Quit")
             self.seen(nick, name, False)
Example #2
0
    def quit(self):
        '''Logs and handles channel quits.'''
        host = irclib.nm_to_uh(self.event.source())
        msg = self.event.arguments()[0]

        self.core.record('-!- %s [%s] has quit [%s]' % (self.nick, host, msg),
                         self.chan)
Example #3
0
    def join(self):
        '''Logs and handles channel joins.'''
        host = irclib.nm_to_uh(self.event.source())

        self.core.record(
            '-!- %s [%s] has joined %s' % (self.nick, host, self.chan),
            self.chan)
Example #4
0
 def on_part(self,c,e):
     source = e.source()
     nick = nm_to_n(source)
     rest = nm_to_uh(source)
     channel = e.target()
     if self.is_listening(channel):
         msg = "%s (%s) has left %s" % (nick, rest, channel)
         self.writeLog("part", source, channel, msg)
Example #5
0
 def on_quit(self,c,e):
     args = e.arguments()
     source = e.source()
     nick = nm_to_n(source)
     rest = nm_to_uh(source)
     msg = "%s (%s) has quit IRC [%s]" % (nick, rest, args[0])
     for channel in self.channels.keys():
         if self.is_listening(channel) and nick in self.channels[channel].users():
             self.writeLog("quit", source, channel, msg)
Example #6
0
 def on_part(self, c, e):
     channel = e.target()
     userHost = nm_to_uh(e.source())
     nick = nm_to_n(e.source())
     if (nick == c.get_nickname()):
         time = strftime("%a %b %d %H:%M:%S %Y", localtime())
         self.logWithoutTime(e, "Session Close: " + time)
         return
     self.log(e.target(), "* " + nick + " (" + userHost + ") has left " + channel)
     self.seen(nick, channel, False)
Example #7
0
    def part(self):
        '''Logs and handles channel parts.'''
        host = irclib.nm_to_uh(self.event.source())
        msg = ''

        if len(self.event.arguments()) == 1:
            msg = self.event.arguments()[0]

        self.core.record(
            '-!- %s [%s] has left %s [%s]' % (self.nick, host, self.chan, msg),
            self.chan)
Example #8
0
    def RegisterNick(self, event):
        print event.source()
        nick = irclib.nm_to_n(event.source()).lower()
        if not nick in self.people:
            self.people[nick] = Nick(nick, event.source())
        if (not hasattr(self.people[nick], "mask")) and  \
            "!" in event.source():
            self.people[nick].mask = irclib.nm_to_uh(event.source())

        self.people[nick].seen = datetime.datetime.now()
        return self.people[nick]
Example #9
0
    def on_ctcp(self, c, e):
        print "ctcp"
        print e.arguments()

        if not e.arguments()[0]=='ACTION':
            SingleServerIRCBot.on_ctcp(self, c,e)
        else:
            if nm_to_n( e.source() ) not in self.komconn.bot.keys():
                #send_message( self.komconn, self.komconn.confs[ e.target() ],
                # str(e.source()) + " " + str( e.arguments()[0] ))
                send_comment( self.komconn, self.komconn.confs[ e.target().lower() ],
                              str(e.source())+" gör något",
                              nm_to_n(e.source()) + " " + str( e.arguments()[1] ),
                              nm_to_n(e.source()), nm_to_uh(e.source()), 1)
Example #10
0
    def on_pubmsg(self, c, e):
        print "pubmsg"

        print e
        print dir(e)
        print e.target()
        
        print "From %s " % nm_to_n( e.source() )
        print self.komconn.bot.keys()

        if nm_to_n( e.source() ) not in self.komconn.bot.keys():
            #send_message( self.komconn, self.komconn.confs[ e.target() ], str(e.source()) + " " + str( e.arguments()[0] ))
            send_comment( self.komconn,  self.komconn.confs[ e.target().lower() ], str(e.source()) + " säger ", str( e.arguments()[0] ),
                          nm_to_n(e.source()), nm_to_uh(e.source()), 1)

        return
Example #11
0
def on_join(c, e):
    # temporary for now, until I figure out config options
    if irclib.nm_to_n(e.source()) == bot._nickname:
        lognames[e.target()] = e.target() + ".log"
    log = lognames.get(e.target(), None)
    if log == None:
        return
    logfile = open(logdirectory + log, 'a')
    if irclib.nm_to_n(e.source()) == bot._nickname:
        print >> logfile, "-- Log opened %s" % (
            time.strftime("%a %b %d %Y %H:%M:%S %Z"))
        currentday[e.target()] = datetime.date.today()
    print >> logfile, "%s -!- %s [%s] has joined %s" % (
        timestamp(), irclib.nm_to_n(e.source()), irclib.nm_to_uh(
            e.source()), e.target())
    logfile.close()
Example #12
0
def on_quit(c, e):
    log = lognames.get(e.target(), None)
    if log == None:
        return
    logfile = open(logdirectory + log, 'a')
    quitreason = ""
    try:
        quitreason = e.arguments()[0]
    except IndexError:
        quitreason = "Client quit"
    print >> logfile, "%s -!- %s [%s] has quit [%s]" % (
        timestamp(), irclib.nm_to_n(e.source()), irclib.nm_to_uh(
            e.source()), quitreason)
    if irclib.nm_to_n(e.source()) == bot._nickname:
        print >> logfile, "-- Log closed %s" % (
            time.strftime("%a %b %d %Y %H:%M:%S %Z"))
        del currentday[e.target()]
    logfile.close()
Example #13
0
 def on_join(self, c, e):
     nick = nm_to_n(e.source())
     channel = e.target()
     if (nick == c.get_nickname()):
         if (not channel in self.channels):
             newChannel = Channel()
             newChannel.logging = self.channelsDict[channel]["logging"]
             newChannel.folder = self.channelsDict[channel]["folder"]
             newChannel.ai = self.channelsDict[channel]["ai"]
             newChannel.quoting = self.channelsDict[channel]["quoting"]
             self.channels[channel] = newChannel
         self.channels[channel].add_user(nick)
         time = strftime("%a %b %d %H:%M:%S %Y", localtime())
         self.logWithoutTime(e.target(), "\nSession Start: " + time)
         self.logWithoutTime(e.target(), "Session Ident: " + channel)
         self.log(e.target(), "* Now talking in " + channel)
         return
     self.channels[channel].add_user(nick)
     userHost = nm_to_uh(e.source())
     self.log(channel, "* " + nick + " (" + userHost + ") has joined " + channel)
     self.seen(nick, channel, True)
Example #14
0
	def message_handler(self, connection, event):
		"""Handle all incoming messages"""
		message = event.arguments()[0] # irclib gives us a list of length 1 for some reason
		mask = irclib.nm_to_uh(event.source()) #userhost portion of nickmask
		nick = irclib.nm_to_n(event.source())
		if event.target() == self.server.get_nickname(): # It's a private (query) message /
			source = irclib.nm_to_n(nick) # so return to sender
		else:
			source = event.target() # message was sent to a channel, so reply to there
		if message.startswith(self.prefix) and not message == self.prefix: # ignore just the prefix
			module, args = message.split(self.prefix, 1)[1].split()[0].lower(), message.split(self.prefix, 1)[1].split()[1:]
			print(u"%s received: %s / Args: %s / Sender: %s / Target: %s") % (event.eventtype(), module, args, event.source(), event.target())
			if module in self.modules:
				try:
					self.modules[module].command(self, source, nick, mask, args)
				except Exception, e:
					print(u"%s: %s") % (module, e)
			elif module in self.core:
				try:
					self.core[module](source, nick, mask, args)
				except Exception, e:
					print(u"%s: %s") % (module, e)
Example #15
0
 def on_part(self, c, e):
     nick = nm_to_n(e.source())
     host = nm_to_uh(e.source())
     self.log('%s [%s] has left %s' % (nick, host, str(self.channel)))
Example #16
0
 def on_join(self, c, e):
     nick = nm_to_n(e.source())
     host = nm_to_uh(e.source())
     self.log('%s [%s] has joined %s' % (nick, host, str(self.channel)))
Example #17
0
 def logQuit(self, e, channel):
     nick = nm_to_n(e.source())
     userHost = nm_to_uh(e.source())
     self.log(channel, "* " + nick + " (" + userHost + ") Quit")
Example #18
0
    def __process_command( self, c, e ):
        """Process a message coming from the server."""
        message = e.arguments()[0]
        # commands have to start with !
        if message[0] != '!':
            return
        # strip the ! off, and split the message
        args = message[1:].split()
        # cmd is the first item
        cmd = args.pop(0).strip()
        # test for admin
        admin = nm_to_uh( e.source() ) in self.admin
        if not admin:
            if e.target() in self.admin_channels and e.target() in self.channel_ops and nm_to_n( e.source() ) in self.channel_ops[ e.target() ]:
                admin = True

        # nick is the sender of the message, target is either a channel or the sender.
        source = nm_to_n( e.source() )
        target = e.target()
        if not is_channel( target ):
            target = source

        # see if there is a module that is willing to handle this, and make it so.
        logging.debug( '__process_command (src: %s; tgt: %s; cmd: %s; args: %s; admin: %s)', source, target, cmd, args, admin )

        # handle die outside of module (in case module is dead :( )
        if admin:
            if cmd == 'die':
                self.notice( source, 'Goodbye cruel world!' )
                raise BotExitException
            elif cmd == 'jump':
                self.jump_server()
            elif cmd == 'restart_class':
                raise BotReloadException
            # config commands
            elif cmd == 'get_config' and len( args ) <= 2:
                if len( args ) == 2:
                    try:
                        value = self.get_config( args[0], args[1] )
                        self.notice( source, 'config[{0}][{1}] = {2}'.format( args[0], args[1], value ) )
                    except:
                        self.notice( source, 'config[{0}][{1}] not set'.format( *args ) )
                elif len( args ) == 1:
                    try:
                        values = self.get_config( args[0] )
                        if len( values ) > 0:
                            self.notice( source, 'config[{}]: '.format( args[0] ) + ', '.join( [ '{}: "{}"'.format( k,v ) for ( k, v ) in values.items() ] ) )
                        else:
                            self.notice( source, 'config[{}] is empty'.format( args[0] ) )
                    except:
                        self.notice( source, 'config[{}] not set'.format( args[0] ) )
                else:
                    try:
                        self.notice( source, 'config groups: ' + ', '.join( self.get_config_groups() ) )
                    except Exception as e:
                        self.notice( source, 'No config groups: {}'.format( e ) )
            elif cmd == 'set_config' and len( args ) >= 2:
                if len( args ) >= 3:
                    config_val = ' '.join( args[2:] )
                else:
                    config_val = None
                try:
                    self.set_config( args[0], args[1], config_val )
                    self.notice( source, 'Set config setting' if config_val else 'Cleared config setting' )
                except Exception as e:
                    self.notice( source, 'Failed setting/clearing config setting: {0}'.format( e ) )
            # other base admin commands
            elif cmd == 'raw':
                self.connection.send_raw( ' '.join( args ) )
                return
            elif cmd == 'admins':
                self.notice( source, 'Current operators:' )
                self.notice( source, ' - global: {0}'.format( ' '.join( self.admin ) ) )
                for chan in [ chan for chan in self.admin_channels if chan in self.channel_ops ]:
                    self.notice( source, ' - {0}: {1}'.format( chan, ' '.join( self.channel_ops[ chan ] ) ) )
                return

        if cmd == 'help':
            if len( args ) > 0:
                if args[0] == 'module':
                    if len( args ) < 2:
                        pass
                    elif self.modules.module_is_loaded( args[1] ):
                        module = self.modules.get_module( args[1] )
                        self.notice( target, module.__doc__ )
                else:
                    for ( module_name, module ) in self.modules.get_loaded_modules():
                        if module.has_cmd( args[0] ):
                            self.notice( target, module.get_cmd( args[0] ).__doc__ )
            else:
                self.notice( target, '!help: this help text (send !help <command> for command help, send !help module <module> for module help)' )
                for ( module_name, module ) in [ lst for lst in self.modules.get_loaded_modules() if lst[1].has_commands and not lst[1].admin_only ]:
                    cmds = module.get_cmd_list()
                    self.notice( target, ' * {0}: {1}'.format( module_name, ', '.join( cmds ) if len( cmds ) > 0 else 'No commands' ) )

        elif admin and cmd == 'admin_help':
            if len( args ) > 0:
                for ( module_name, module ) in self.modules.get_loaded_modules():
                    if module.has_admin_cmd( args[0] ):
                        self.notice( source, module.get_admin_cmd( args[0] ).__doc__ )
            else:
                self.notice( source, '!admin_help: this help text (send !admin_help <command> for command help' )
                self.notice( source, '!die:                                   kill the bot' )
                self.notice( source, '!raw:                                   send raw irc command' )
                self.notice( source, '!admins:                                see who are admin' )
                self.notice( source, '!restart_class:                         restart the main Bot class' )
                for ( module_name, module ) in self.modules.get_loaded_modules():
                    cmds = module.get_admin_cmd_list()
                    if len( cmds ) > 0:
                        self.notice( source, ' * {0}: {1}'.format( module_name, ', '.join( cmds ) ) )
        else:
            for ( module_name, module ) in self.modules.get_loaded_modules():
                try:
                    if module.has_cmd( cmd ):
                        lines = module.get_cmd( cmd )( args, source, target, admin )
                        if lines:
                            for line in lines:
                                self.notice( target, line )
                    elif admin and module.has_admin_cmd( cmd ):
                        lines = module.get_admin_cmd( cmd )( args, source, target, admin )
                        if lines:
                            for line in lines:
                                self.notice( source, line )
                except Exception as e:
                    logging.exception( "Module '{0}' handle error: {1}".format( module_name, e ) )
Example #19
0
def on_nick(bot,event):
	newhost = irclib.nm_to_uh(event.source());
	if event.source() in lconfig["users"]:
		lconfig["users"]["%s!%s" %(event.target(),newhost)] = lconfig["users"][event.source()];
		del lconfig["users"][event.source()];
Example #20
0
File: bot.py Project: LuizOz/botcha
 def on_part(self, c, e):
     nick = nm_to_n(e.source())
     host = nm_to_uh(e.source())
     self.log('%s [%s] has left %s' % (nick, host, str(self.channel)))
Example #21
0
 def logQuit(self, e, channel):
     nick = nm_to_n(e.source())
     userHost = nm_to_uh(e.source())
     self.log(channel, "* " + nick + " (" + userHost + ") Quit")
Example #22
0
def on_part(c, e):
	log = lognames.get(e.target(), None)
	if log == None:
		return
	logfile = open(logdirectory+log, 'a')
	partreason = ""
	try:
		partreason = e.arguments()[0]
	except IndexError:
		partreason = "Client quit"
	print >>logfile, "%s -!- %s [%s] has left %s [%s]" % (timestamp(), irclib.nm_to_n(e.source()), irclib.nm_to_uh(e.source()), e.target(), partreason)
	if irclib.nm_to_n(e.source()) == bot._nickname:
		print >>logfile, "-- Log closed %s" % (time.strftime("%a %b %d %Y %H:%M:%S %Z"))
		del currentday[e.target()]
	logfile.close()
Example #23
0
def on_join(c, e):
	# temporary for now, until I figure out config options
	if irclib.nm_to_n(e.source()) == bot._nickname:
		lognames[e.target()] = e.target()+".log"
	log = lognames.get(e.target(), None)
	if log == None:
		return
	logfile = open(logdirectory+log, 'a')
	if irclib.nm_to_n(e.source()) == bot._nickname:
		print >>logfile, "-- Log opened %s" % (time.strftime("%a %b %d %Y %H:%M:%S %Z"))
		currentday[e.target()] = datetime.date.today()
	print >>logfile, "%s -!- %s [%s] has joined %s" % (timestamp(), irclib.nm_to_n(e.source()), irclib.nm_to_uh(e.source()), e.target())
	logfile.close()
Example #24
0
    def do_command(self, e, cmd):
        nick = nm_to_n(e.source()).lower()
        c = self.connection
        cmds = cmd.split(" ")
        cmd = cmds[0]

        if cmd == "disconnect":
            if nick == self.master:
                self.disconnect()
            else:
                c.privmsg(nick, "f**k you, nice try");        
            
        elif cmd == "die":
            if nick == self.master:
                self.die()
            else:
                c.privmsg(nick, "f**k you, nice try");
                
        elif cmd == "kick":
            newtime = time.time()
            
            if len(cmds) > 1:
                tokick = cmds[1].lower()
                
                if tokick.lower() == self.nick.lower():
                    c.privmsg(nick, "f**k you nice try");
                    return
                
                users = [u.lower() for u in self.channels[self.channel].users()]
                majority = len(users)/2
                
                #c.privmsg(self.initvals["channel"], "%s votes required to kick someone" % majority)
                #print majority, "votes required to kick someone"
                
                if(tokick in users):
                
                    kicker_uh = nm_to_uh(e.source())
                    
                    c.privmsg(self.master,"%s voted for %s" % (nick,tokick))
                    print "%s voted for %s" % (nick,tokick)
                    
                    try:
                        if(kicker_uh not in self.votes[tokick]):
                            self.votes[tokick].append(kicker_uh)
                            
                            
                    except KeyError:
                        self.votes[tokick] = []
                        self.votes[tokick].append(kicker_uh)                        
                                        
                    try:
                        if time.time() - self.votetimes[tokick] > 30:
                            self.votes[tokick] = []
                            self.votes[tokick].append(kicker_uh)
                            
                        elif len(self.votes[tokick]) >= majority:
                            
                            c.privmsg(self.master,"i should kick %s now" % tokick)
                            print "i should kick %s now" % tokick
                            
                            if not self.master == tokick:
                            
                                c.kick(self.channel,tokick,":commissar:")
                                self.votes[tokick] = []
                                return
                                
                            else:
                                return

                    except KeyError:
                        pass
                    
                    #c.privmsg(self.initvals["channel"], "%s/%s votes received for %s" % (len(self.votes[tokick]), majority, tokick))
                    
                    self.votetimes[tokick] = time.time()
                        
                else:
                    c.privmsg(self.master,"%s voted for %s (who doesn't exist)" % (nick,tokick))
                    print tokick, "NOT in channel"
            
            self.time = time.time()
            return True
            
        else:
            c.privmsg(nick, "Not understood: " + cmd)
            return False
Example #25
0
 def logPart(self, e):
     channel = e.target()
     userHost = nm_to_uh(e.source())
     nick = nm_to_n(e.source())
     self.log(e.target(), "* " + nick + " (" + userHost + ") has left " + channel)
Example #26
0
 def logJoin(self, e):
     nick = nm_to_n(e.source())
     channel = e.target()
     userHost = nm_to_uh(e.source())
     self.log(channel,
              "* " + nick + " (" + userHost + ") has joined " + channel)
Example #27
0
 def logPart(self, e):
     channel = e.target()
     userHost = nm_to_uh(e.source())
     nick = nm_to_n(e.source())
     self.log(e.target(),
              "* " + nick + " (" + userHost + ") has left " + channel)
Example #28
0
File: bot.py Project: LuizOz/botcha
 def on_join(self, c, e):
     nick = nm_to_n(e.source())
     host = nm_to_uh(e.source())
     self.log('%s [%s] has joined %s' % (nick, host, str(self.channel)))
Example #29
0
 def on_privmsg(self, c, e):
     send_comment( self.komconn, self.komconn.confs[ e.target().lower() ], str(e.source()) + " säger ", str( e.arguments()[0] ),
                   nm_to_n(e.source()), nm_to_uh(e.source()), 0)
     send_message( self.komconn, self.komconn.confs[ e.target().lower() ], str(e.source()) + " " + str( e.arguments()[0] ))
     return
Example #30
0
 def kickban(self, c, e):
     ch = e.target()
     nick = nm_to_n(e.source())
     uh = nm_to_uh(e.source())
     print "i should kick %s from %s with uh: %s" % (ch, nick, uh)
Example #31
0
 def logJoin(self, e):
     nick = nm_to_n(e.source())
     channel = e.target()
     userHost = nm_to_uh(e.source())
     self.log(channel, "* " + nick + " (" + userHost + ") has joined " + channel)