def on_tune_event(self, message): """ Called when a pep notification for an user tune is received """ contact = roster[message['from'].bare] if not contact: return roster.modified() item = message['pubsub_event']['items']['item'] old_tune = contact.tune if item.xml.find('{http://jabber.org/protocol/tune}tune'): item = item['tune'] contact.tune = { 'artist': item['artist'], 'length': item['length'], 'rating': item['rating'], 'source': item['source'], 'title': item['title'], 'track': item['track'], 'uri': item['uri'] } else: contact.tune = {} if contact.tune: logger.log_roster_change(message['from'].bare, 'is now listening to %s' % common.format_tune_string(contact.tune)) if old_tune != contact.tune and config.get_by_tabname('display_tune_notifications', contact.bare_jid): if contact.tune: self.information( 'Tune from '+ message['from'].bare + ': ' + common.format_tune_string(contact.tune), 'Tune') else: self.information(contact.bare_jid + ' stopped listening to music.', 'Tune')
def on_mood_event(self, message): """ Called when a pep notification for an user mood is received. """ contact = roster[message['from'].bare] if not contact: return roster.modified() item = message['pubsub_event']['items']['item'] old_mood = contact.mood if item.xml.find('{http://jabber.org/protocol/mood}mood'): mood = item['mood']['value'] if mood: mood = pep.MOODS.get(mood, mood) text = item['mood']['text'] if text: mood = '%s (%s)' % (mood, text) contact.mood = mood else: contact.mood = '' else: contact.mood = '' if contact.mood: logger.log_roster_change(contact.bare_jid, 'has now the mood: %s' % contact.mood) if old_mood != contact.mood and config.get_by_tabname('display_mood_notifications', contact.bare_jid): if contact.mood: self.information('Mood from '+ contact.bare_jid + ': ' + contact.mood, 'Mood') else: self.information(contact.bare_jid + ' stopped having his/her mood.', 'Mood')
def on_gaming_event(self, message): """ Called when a pep notification for user gaming is received """ contact = roster[message['from'].bare] if not contact: return item = message['pubsub_event']['items']['item'] old_gaming = contact.gaming if item.xml.find('{urn:xmpp:gaming:0}gaming'): item = item['gaming'] # only name and server_address are used for now contact.gaming = { 'character_name': item['character_name'], 'character_profile': item['character_profile'], 'name': item['name'], 'level': item['level'], 'uri': item['uri'], 'server_name': item['server_name'], 'server_address': item['server_address'], } else: contact.gaming = {} if contact.gaming: logger.log_roster_change(contact.bare_jid, 'is playing %s' % (common.format_gaming_string(contact.gaming))) if old_gaming != contact.gaming and config.get_by_tabname('display_gaming_notifications', contact.bare_jid): if contact.gaming: self.information('%s is playing %s' % (contact.bare_jid, common.format_gaming_string(contact.gaming)), 'Gaming') else: self.information(contact.bare_jid + ' stopped playing.', 'Gaming')
def on_groupchat_direct_invitation(self, message): """ Direct invitation received """ room = safeJID(message['groupchat_invite']['jid']) if room.bare in self.pending_invites: return inviter = message['from'] reason = message['groupchat_invite']['reason'] password = message['groupchat_invite']['password'] continue_ = message['groupchat_invite']['continue'] msg = "You are invited to the room %s by %s" % (room, inviter.full) if password: msg += ' (password: "******")' % password if continue_: msg += '\nto continue the discussion' if reason: msg += "\nreason: %s" % reason self.information(msg, 'Info') if 'invite' in config.get('beep_on').split(): curses.beep() self.pending_invites[room.bare] = inviter.full logger.log_roster_change(inviter.full, 'invited you to %s' % room.bare)
def on_got_online(self, presence): """ A JID got online """ if presence.match('presence/muc') or presence.xml.find('{http://jabber.org/protocol/muc#user}x'): return jid = presence['from'] contact = roster[jid.bare] if contact is None: # Todo, handle presence coming from contacts not in roster return roster.modified() if not logger.log_roster_change(jid.bare, 'got online'): self.information(_('Unable to write in the log file'), 'Error') resource = Resource(jid.full, { 'priority': presence.get_priority() or 0, 'status': presence['status'], 'show': presence['show'], }) self.events.trigger('normal_presence', presence, resource) self.add_information_message_to_conversation_tab(jid.full, '\x195}%s is \x194}online' % (jid.full)) if time.time() - self.connection_time > 10: # We do not display messages if we recently logged in if presence['status']: self.information("\x193}%s \x195}is \x194}online\x195} (\x19o%s\x195})" % (safeJID(resource.jid).bare, presence['status']), "Roster") else: self.information("\x193}%s \x195}is \x194}online\x195}" % safeJID(resource.jid).bare, "Roster") self.add_information_message_to_conversation_tab(jid.bare, '\x195}%s is \x194}online' % (jid.bare)) if isinstance(self.current_tab(), tabs.RosterInfoTab): self.refresh_window()
def on_groupchat_invitation(self, message): """ Mediated invitation received """ jid = message['from'] if jid.bare in self.pending_invites: return # there are 2 'x' tags in the messages, making message['x'] useless invite = StanzaBase(self.xmpp, xml=message.find('{http://jabber.org/protocol/muc#user}x/{http://jabber.org/protocol/muc#user}invite')) inviter = invite['from'] reason = invite['reason'] password = invite['password'] msg = "You are invited to the room %s by %s" % (jid.full, inviter.full) if reason: msg += "because: %s" % reason if password: msg += ". The password is \"%s\"." % password self.information(msg, 'Info') if 'invite' in config.get('beep_on').split(): curses.beep() logger.log_roster_change(inviter.full, 'invited you to %s' % jid.full) self.pending_invites[jid.bare] = inviter.full
def on_activity_event(self, message): """ Called when a pep notification for an user activity is received. """ contact = roster[message['from'].bare] if not contact: return roster.modified() item = message['pubsub_event']['items']['item'] old_activity = contact.activity if item.xml.find('{http://jabber.org/protocol/activity}activity'): try: activity = item['activity']['value'] except ValueError: return if activity[0]: general = pep.ACTIVITIES.get(activity[0]) s = general['category'] if activity[1]: s = s + '/' + general.get(activity[1], 'other') text = item['activity']['text'] if text: s = '%s (%s)' % (s, text) contact.activity = s else: contact.activity = '' else: contact.activity = '' if contact.activity: logger.log_roster_change(contact.bare_jid, 'has now the activity %s' % contact.activity) if old_activity != contact.activity and config.get_by_tabname('display_activity_notifications', contact.bare_jid): if contact.activity: self.information('Activity from '+ contact.bare_jid + ': ' + contact.activity, 'Activity') else: self.information(contact.bare_jid + ' stopped doing his/her activity.', 'Activity')
def on_got_offline(self, presence): """ A JID got offline """ if presence.match('presence/muc') or presence.xml.find('{http://jabber.org/protocol/muc#user}x'): return jid = presence['from'] if not logger.log_roster_change(jid.bare, 'got offline'): self.information(_('Unable to write in the log file'), 'Error') # If a resource got offline, display the message in the conversation with this # precise resource. if jid.resource: self.add_information_message_to_conversation_tab(jid.full, '\x195}%s is \x191}offline' % (jid.full)) self.add_information_message_to_conversation_tab(jid.bare, '\x195}%s is \x191}offline' % (jid.bare)) self.information('\x193}%s \x195}is \x191}offline' % (jid.bare), 'Roster') roster.modified() if isinstance(self.current_tab(), tabs.RosterInfoTab): self.refresh_window()