Esempio n. 1
0
    def getRoster(self):
        t = time.time()
        
        if self.last_roster is not None and self.last_roster_check_time is not None:
            if self.last_roster_check_time + self.MIN_DELAY_BETWEEN_ROSTER_CHECKS > t:
                return self.last_roster
        
        Logger.debug(self, "Checking Steam Roster")
        roster = {}
        
        try:
            for friend in self.user.friends:

                if friend.state == 0:
                    continue
                
                roster[friend.steamid] = {
                        'name': str(friend),
                        'special': friend.currently_playing is not None,
                        'currently_playing': friend.currently_playing
                    }
        except:
            Logger.debug(self, "Exception while trying to load Steam user friends/state!")
            return self.last_roster
        
        
        self.last_roster = roster
        self.last_roster_check_time = t
        
        return roster
Esempio n. 2
0
 def __init__(self, chatbot, alias, config):
     self._config = {}
     self._chatbot = {}
     self._isAlive = True
     self._alias = None
     self._tunnel_regex = {}
     self._message_queue = Queue()
     self._last_message_sent = time.time()
     self.MIN_DELAY_BETWEEN_MESSAGES = 0.5
     
     self._roster_changes_last_roster = None
     
     Logger.info(self, "%s %s initalizing..." % (alias, config['medium']))
     self._alias = alias
     self._config = config
     self._chatbot = chatbot
     
     Thread(target=self.processMessageQueue, args=()).start()
     
     
     if self._config.has_key('tunnels'):
         for tunnel_id,patterns in self._config['tunnels'].iteritems():
             regexs = []
             for pattern in patterns:
                 regexs.append(re.compile(pattern))
                 self._tunnel_regex[tunnel_id] = regexs
Esempio n. 3
0
 def start(self):
     super(SteamChatMedium, self).start()
     
     Logger.debug(self, "Starting SteamChat for '%s'" % self._alias)
     steamapi.core.APIConnection(api_key=self._config['api_key'])
     self.user = steamapi.user.SteamUser(self._config['SteamUser'])
     while True:
         time.sleep(10)
Esempio n. 4
0
 def on_privmsg(self, connection, event):
     body = string.join(event.arguments, " ")
     sendern = event.source.nick
     
     Logger.info(self._chat_medium, "Privmsg: %s said %s" % (sendern, body))
     med = self._chat_medium
     message = Message(med._alias, med.getMediumName(), med.CHANNEL_TYPE_INDIVIDUAL, sendern, sendern, sendern, body)
     self._chat_medium.onIrcMessage(message)
Esempio n. 5
0
 def start(self):
     super(IrcChatMedium, self).start()
     
     while True:
         Logger.debug(self, "Starting IrcChat for '%s'" % self._alias)
         self._irc = IRCBot(self)
         self._irc.start()
         Logger.warning(self, "IrcChat loop for '%s' ended" % self._alias)
         time.sleep(10)
Esempio n. 6
0
 def on_pubmsg(self, connection, event):
     body = string.join(event.arguments, " ")
     sendern = event.source.nick
     channel = event.target
     
     Logger.info(self._chat_medium, "Pubmsg: %s in %s said %s" % (sendern, channel, body))
     med = self._chat_medium
     message = Message(med._alias, med.getMediumName(), med.CHANNEL_TYPE_GROUP, channel, sendern, sendern, body)
     self._chat_medium.onIrcMessage(message)
Esempio n. 7
0
 def sendMessage(self, message):
     super(JabberChatMedium, self).sendMessage(message)
     assert isinstance(message, babelpr.Message.Message)
     
     if(self._xmpp is None):
         return
     
     Logger.info(self, "%s sending %s message to '%s': %s" % (self._alias, message.channel_type, message.channel_id, message.body))
     
     mtype = "chat" if message.channel_type == self.CHANNEL_TYPE_INDIVIDUAL else "groupchat"
     self._xmpp.send_message(message.channel_id, message.body, None, mtype)
Esempio n. 8
0
 def session_start(self, event):
     Logger.info(self._chat_medium, "Jabber Session Starting...")
     self.plugin['xep_0045'].rooms = {}
     
     self.send_presence()
     self.get_roster()
     
     
     if self._chat_medium._config.has_key('channels'):
         for channel in self._chat_medium._config['channels']:
             Logger.info(self._chat_medium, "Attempting to join '%s'" % channel)
             self.plugin['xep_0045'].joinMUC(channel, self._chat_medium.getOwnNick(), wait=True, pfrom=self.boundjid)
Esempio n. 9
0
 def processMessageQueue(self):
     while True:
         message = self._message_queue.get(True)
         
         if message is None:
             Logger.debug(self, "No message found in processMessageQueue, skipping...")
             continue
         
         #Logger.debug(self, "Message queue found message to send.")
         
         if time.time() - self._last_message_sent < self.MIN_DELAY_BETWEEN_MESSAGES:
             sleep_time = self.MIN_DELAY_BETWEEN_MESSAGES - (time.time() - self._last_message_sent)
             Logger.debug(self, "Recently sent a message. Sleeping for %f seconds..." % sleep_time)
             time.sleep(sleep_time)
         
         #Logger.debug(self, "Message queue sending message.")     
         self.sendMessage(message)
Esempio n. 10
0
 def start(self):
     super(JabberChatMedium, self).start()
     
     while True:
         Logger.debug(self, "Starting JabberChat for '%s'" % self._alias)
         self._xmpp = JabberBot(self._config['username'], self._config['password'], self)
         self._xmpp.register_plugin('xep_0030') # Service Discovery
         self._xmpp.register_plugin('xep_0045') # Multi-User Chat
         #self._xmpp.register_plugin('xep_0249') # Direct MUC Invitations
         self._xmpp.register_plugin('xep_0199') # XMPP Ping                     
         
         self._xmpp.add_event_handler("message", self.onJabberMessage)
         self._xmpp.add_event_handler("groupchat_message", self.onJabberGroupMessage)
         
         use_ssl = self._config.has_key('use_ssl') and self._config['use_ssl']
         self._xmpp.connect((self._config['server'], self._config['port']), use_ssl=use_ssl)
         self._xmpp.process(threaded=False)
         
         self._xmpp = None
     
         Logger.warning(self, "JabberChat loop for '%s' ended" % self._alias)
         time.sleep(10)
Esempio n. 11
0
 def onChangedStatus(self, event):
     try:
         # let them know we can do MUC
         jid = event.get_from()
         jid_str = "%s" % jid
         if jid not in self.plugin['xep_0045'].rooms and jid != self.boundjid and jid_str.find("private-chat-") == -1:
             if jid_str not in self.presence_history:
                 send_it = True
             else:
                 send_it = time.time() - self.presence_history[jid_str] > 60
                                     
             if send_it:
                 self.presence_history[jid_str] = time.time()
                 Logger.info(self._chat_medium, "Sending presence to %s..." % jid)
                 data = '<presence to="%s" from="%s"><status /><priority>24</priority><c xmlns="http://jabber.org/protocol/caps" node="http://mail.google.com/xmpp/client/caps" ext="pmuc-v1" ver="1.1" /></presence>'
                 self.send_raw(data % (jid, self.boundjid))
     except:
         pass
         
         
     
     event_str = "%s" % event
     
     if event_str.find('<nick') > 0:
         matches = self.nick_re.search(event_str)
         if matches is None:
             return
         
         group = matches.groupdict()
         from_parts = group['from'].split('/')
         
         rooms = self.plugin['xep_0045'].rooms
         if rooms.has_key(from_parts[0]):
             self.chatnick_to_nick[from_parts[1]] = group['nick']
             
             user_parts = group['jid'].split('/')
             if len(user_parts) == 2:
                 self.jid_to_nick[group['jid']] = group['nick']
Esempio n. 12
0
 def on_welcome(self, c, e):
     config = self._chat_medium._config
     
     Logger.info(self._chat_medium, "IRC Bot identifying with nickserv.")
     self.connection.privmsg("nickserv","identify %s" % config['password'])
     time.sleep(3)
     Logger.info(self._chat_medium, "Joining channels...")
     
     for channel in config['channels']:
         Logger.info(self._chat_medium, "Joining channel: %s" % channel)
         c.join(channel)
Esempio n. 13
0
 def start(self):
     Logger.info(self, "%s %s starting..." % (self._alias, self._config['medium']))
Esempio n. 14
0
 def setGroupChannel(self, channel):
     if channel != self._last_group_channel:
         Logger.info(self, "%s changing main group channel to '%s'" % (self._alias, channel))
         self._last_group_channel = channel
Esempio n. 15
0
 def start(self):
     Logger.info(self._chat_medium, "IRC Bot starting processing loop.")
     irc.bot.SingleServerIRCBot.start(self)        
     Logger.info(self._chat_medium, "Exiting my connection function.")
Esempio n. 16
0
 def on_disconnect(self, connection, event):
     Logger.info(self._chat_medium, "Warning: IRC Has disconnected.")