Example #1
0
 def announce(self, status):
     if not self.running or not cfg.get('watcher-enabled'):
         return
     status['time'] = mpd_duration(status['time'])
     song = cfg.get('song-status') % status
     for name in self.data.keys():
         bot = fleet.byname(name)
         if bot:
             for channel in self.data[name].keys():
                 bot.say(channel, song)
Example #2
0
 def announce(self, status):
     if not self.running or not cfg.get('watcher-enabled'):
         return
     status['time'] = mpd_duration(status['time'])
     song = cfg.get('song-status') % status
     for name in self.data.keys():
         bot = fleet.byname(name)
         if bot:
             for channel in self.data[name].keys():
                 bot.say(channel, song)
Example #3
0
 def announce(self, status, show):
     logging.info('announce(%s, %s)' % (status, show))
     #print 'announce(%s, %s)' % (status, show)
     if not self.running or not cfg.get('watcher-enabled'):
         return
     for name in fleet.list():
         bot = 0
         try: bot = fleet.byname(name)
         except: pass
         if bot and bot.type == "sxmpp":
             logging.warn('%s[%s].setstatus(%s, %s)' % (bot.name, bot.type, status, show))
             bot.setstatus(status, show)
Example #4
0
    def handle(self):
        if not cfg.get('watcher-enabled'):
            raise EventError('watcher not enabled, use "!%s-cfg watcher-enabled 1" to enable' % os.path.basename(__file__)[:-3])
        #logging.info("fleet: %s - %s" % (str(fleet), str(fleet.list())))
        bot = 0
        try: bot = fleet.byname(self.name)
        except: pass #print "fleet: %s" % str(fleet) #"fleet.byname(%s)" % self.name

        if bot != None:
            bot.connectok.wait()
        now = int(datetime.datetime.now().strftime("%H%M%S"))
        #print now
        if now > 60000 and now <= 60005:
            print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>setting topic"
            settopic(bot, "#c-base")
Example #5
0
    def handle(self):
        if not cfg.get('watcher-enabled'):
            raise Announce2342Error('watcher not enabled, use "!%s-cfg watcher-enabled 1" to enable' % os.path.basename(__file__)[:-3])
        #logging.warn("fleet: %s - %s" % (str(fleet), str(fleet.list())))
        #print "fleet: %s - %s" % (str(fleet), str(fleet.list()))
        bot = 0
        try: bot = fleet.byname(self.name)
        except: pass #print "fleet: %s" % str(fleet) #"fleet.byname(%s)" % self.name

        if bot != None:
            bot.connectok.wait()
        now = int(datetime.datetime.now().strftime("%H%M%S"))
        if now > 234200 and now <= 234205:
            bot.say(cfg.get('channel'), 'Es ist jetzt dreiundzwanzig Uhr zweiundvierzig.')
            time.sleep(2)
            bot.say(cfg.get('channel'), 'Oh.')
Example #6
0
    def _listen(self):
        """ listen for udp messages .. /msg via bot"""
        if not cfg['udp']:
            return
        for botname in cfg['udpbots']:
            if not fleet.byname(botname):
                logging.info("udp - can't find %s bot" % botname)

        try:
            fleet.startok.wait(5)
            self.sock.bind((cfg['udphost'], cfg['udpport']))
            logging.warn('udp listening on %s %s' %
                         (cfg['udphost'], cfg['udpport']))
            self.stop = 0
        except IOError:
            handle_exception()
            self.sock = None
            self.stop = 1
            return
        # loop on listening udp socket
        while not self.stop:
            try:
                input, addr = self.sock.recvfrom(64000)
            except socket.timeout:
                continue
            except Exception, ex:
                try:
                    (errno, errstr) = ex
                except ValueError:
                    errno = 0
                    errstr = str(ex)
                if errno == 4:
                    logging.warn("udp - %s - %s" % (self.name, str(ex)))
                    break
                if errno == 35:
                    continue
                else:
                    handle_exception()
                    break
            if self.stop:
                break
            self.queue.put((input, addr))
Example #7
0
 def _listen(self):
     """ listen for udp messages .. /msg via bot"""
     if not cfg['udp']:
         return
     for botname in cfg['udpbots']:
         if not fleet.byname(botname):
             logging.info("udp - can't find %s bot" % botname)
             
     try:
         fleet.startok.wait(5)
         self.sock.bind((cfg['udphost'], cfg['udpport']))
         logging.warn('udp listening on %s %s' % (cfg['udphost'], cfg['udpport']))
         self.stop = 0
     except IOError:
         handle_exception()
         self.sock = None
         self.stop = 1
         return
     # loop on listening udp socket
     while not self.stop:
         try:
             input, addr = self.sock.recvfrom(64000)
         except socket.timeout:
             continue
         except Exception, ex:
             try:
                 (errno, errstr) = ex
             except ValueError:
                 errno = 0
                 errstr = str(ex)
             if errno == 4:
                 logging.warn("udp - %s - %s" % (self.name, str(ex)))
                 break
             if errno == 35:
                 continue
             else:
                 handle_exception()
                 break
         if self.stop:
             break
         self.queue.put((input, addr))
Example #8
0
    def dosay(self, printto, txt):

        """ send txt to printto .. do some checks. """

        if cfg['udpparty'] and partyline.is_on(printto):
            partyline.say_nick(printto, txt)
            return
        if not cfg['udpbots']:
            bots = [cfg['udpbot'], ]
        else:
            bots = cfg['udpbots']
        for botname in bots:
            bot = fleet.byname(botname)
            if not bot:
                logging.warn("udp - can't find %s bot in fleet" % botname)
                continue
            #if not bot.jabber and not cfg['nolimiter']:
            #    time.sleep(3)
            bot.connectok.wait()
            bot.say(printto, txt)
            for i in self.loggers:
                i.log(printto, txt)
Example #9
0
    def dosay(self, printto, txt):
        """ send txt to printto .. do some checks. """

        if cfg['udpparty'] and partyline.is_on(printto):
            partyline.say_nick(printto, txt)
            return
        if not cfg['udpbots']:
            bots = [
                cfg['udpbot'],
            ]
        else:
            bots = cfg['udpbots']
        for botname in bots:
            bot = fleet.byname(botname)
            if not bot:
                logging.warn("udp - can't find %s bot in fleet" % botname)
                continue
            #if not bot.jabber and not cfg['nolimiter']:
            #    time.sleep(3)
            bot.connectok.wait()
            bot.say(printto, txt)
            for i in self.loggers:
                i.log(printto, txt)
Example #10
0
    def handle(self):
        if not cfg.get('watcher-enabled'):
            raise UserlistError('watcher not enabled, use "!%s-cfg watcher-enabled 1" to enable' % os.path.basename(__file__)[:-3])
        logging.info("fleet: %s - %s" % (str(fleet), str(fleet.list())))
        bot = 0
        try: bot = fleet.byname(self.name)
        except: pass #print "fleet: %s" % str(fleet) #"fleet.byname(%s)" % self.name

        if bot != None:
            bot.connectok.wait()

        # LTE conversion to ETA
        day = weekdays[datetime.datetime.now().weekday()]
        if day != self.oldday:
            self.oldday = day
            dayitem = LteItem(day)
            # convert LTEs to ETAs for current day
            for user in dayitem.data.ltes.keys():
                server.seteta(user, dayitem.data.ltes[user])
                if bot and bot.type == "sxmpp" and cfg.get('suppress-subs') == 0:
                    for etasub in etaitem.data.etasubs:
                        bot.say(etasub, 'ETA %s %s' % (user, dayitem.data.ltes[user]))
                del dayitem.data.ltes[user]
            # clear LTEs for current day
            dayitem.data.ltes = {}
            dayitem.save()   
        
        whoresult = server.who()['result']
            
        # check if new ETAs have been added
        newetas = server.newetas()['result']
        if len(newetas) > 0:
            for etasub in etaitem.data.etasubs:
                etalist = []
                for key in sorted(newetas.keys()):
                    if getuser2(etasub) == key:
                        print "skip notifying yourself"
                    else:
                        etalist += ['%s [%s]' % (key, newetas[key])]
                if bot and bot.type == "sxmpp" and len(etalist) > 0:
                    bot.say(etasub, 'ETA: ' + ', '.join(etalist))

        # check for new achievements
        achievements = server.achievements()
        if len(achievements) > 0:
            for user in achievements.keys():
                if achievements[user] == 'ETA':
                    print "%s++" % user
                    tmpbot = 0
                    try: 
                        tmpbot = fleet.byname(cfg.get('achievement-bot'))
                        tmpbot.say(cfg.get('achievement-channel'), '%s++' % user)
                    except: pass

        # check if new users have arrived
        arrivals = server.arrivals()['result']
        if len(arrivals) > 0:
            for arrivesub in etaitem.data.arrivesubs:
                arrivelist = ', '.join(sorted(arrivals.keys()))
                if bot and bot.type == "sxmpp":
                    bot.say(arrivesub, 'Now boarding: ' + arrivelist)
        
        # activities
	activities = server.activities()['result']
        if len(activities) > 0:
            print activities

        usercount = len(whoresult['available'])
        if self.lastcount == 0 and usercount > 0:
            if bot and bot.type == "sxmpp":
                for opensub in etaitem.data.opensubs:
                    #bot.say(opensub, 'c3pO is awake')
                    print "FUUUUUUUUUUUU"
            else:
                logging.error("bot undefined or not xmpp")

        self.lastcount = usercount
 
        if (cfg.get('set-xmpp-presence') > 0):
            if len(whoresult['available']) > 0:
                self.announce('open', 'chat')
            elif len(whoresult['eta']) > 0:
                self.announce('incoming', 'dnd')
            else:
                self.announce('closed', 'xa')

        time.sleep(cfg.get('watcher-interval'))