diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common.py | 19 | ||||
-rw-r--r-- | src/connection.py | 3 | ||||
-rw-r--r-- | src/contact.py | 1 | ||||
-rw-r--r-- | src/core.py | 65 | ||||
-rw-r--r-- | src/tabs.py | 2 | ||||
-rw-r--r-- | src/theming.py | 3 | ||||
-rw-r--r-- | src/windows.py | 12 |
7 files changed, 100 insertions, 5 deletions
diff --git a/src/common.py b/src/common.py index 5b62732c..16fcfba5 100644 --- a/src/common.py +++ b/src/common.py @@ -315,6 +315,25 @@ def format_tune_string(infos): elems.append('[' + mins + ':' + secs + ']') return ' '.join(elems) +def format_gaming_string(infos): + """ + Construct a string from a dict containing the "user gaming" + informations. + (for now, only use address and name) + + :param dict infos: The informations + :returns: The formatted string + :rtype: :py:class:`str` + """ + name = infos.get('name') + if not name: + return '' + + server_address = infos.get('server_address') + if server_address: + return '%s on %s' % (name, server_address) + return name + def safeJID(*args, **kwargs): """ Construct a :py:class:`sleekxmpp.JID` object from a string. diff --git a/src/connection.py b/src/connection.py index 8565a616..b72c8d1f 100644 --- a/src/connection.py +++ b/src/connection.py @@ -84,6 +84,9 @@ class Connection(sleekxmpp.ClientXMPP): if config.get('enable_user_activity', 'true') != 'false': self.register_plugin('xep_0108') + if config.get('enable_user_gaming', 'true') != 'false': + self.register_plugin('xep_0196') + if config.get('send_poezio_info', 'true') == 'true': info = {'name':'poezio', 'version': options.version} diff --git a/src/contact.py b/src/contact.py index 8e6595db..5074a0dc 100644 --- a/src/contact.py +++ b/src/contact.py @@ -68,6 +68,7 @@ class Contact(object): self._name = '' self.error = None self.tune = {} + self.gaming = {} self.mood = '' self.activity = '' diff --git a/src/core.py b/src/core.py index 0b041f2d..ff982ae7 100644 --- a/src/core.py +++ b/src/core.py @@ -265,9 +265,11 @@ class Core(object): if config.get('enable_user_nick', 'true') != 'false': self.xmpp.add_event_handler("user_nick_publish", self.on_nick_received) if config.get('enable_user_mood', 'true') != 'false': - self.xmpp.add_event_handler("user_mood_publish", self.on_mood) + self.xmpp.add_event_handler("user_mood_publish", self.on_mood_event) if config.get('enable_user_activity', 'true') != 'false': - self.xmpp.add_event_handler("user_activity_publish", self.on_activity) + self.xmpp.add_event_handler("user_activity_publish", self.on_activity_event) + if config.get('enable_user_gaming', 'true') != 'false': + self.xmpp.add_event_handler("user_gaming_publish", self.on_gaming_event) self.xmpp.register_handler(self.all_stanzas) self.initial_joins = [] @@ -2215,6 +2217,20 @@ class Core(object): return self.information('%s is not a correct value for an activity' % specific, 'Error') self.xmpp.plugin['xep_0108'].publish_activity(general, specific, text, block=False) + def command_gaming(self, arg): + """ + /gaming [<game name> [server address]] + """ + args = common.shell_split(arg) + if not args: + return self.xmpp.plugin['xep_1096'].stop(block=False) + name = args[0] + if len(args) > 1: + address = args[1] + else: + address = None + return self.xmpp.plugin['xep_0196'].publish_gaming(name=name, server_address=address, block=False) + def completion_activity(self, the_input): """Completion for /activity""" txt = the_input.get_text() @@ -2303,6 +2319,8 @@ class Core(object): self.xmpp.plugin['xep_0107'].stop(block=False) if config.get('enable_user_activity', 'true') != 'false': self.xmpp.plugin['xep_0108'].stop(block=False) + if config.get('enable_user_gaming', 'true') != 'false': + self.xmpp.plugin['xep_0196'].stop(block=False) self.plugin_manager.disable_plugins() self.disconnect(msg) self.running = False @@ -2571,13 +2589,20 @@ class Core(object): ' Nothing means "stop broadcasting an activity".'), shortdesc=_('Send your activity.'), completion=self.completion_activity) - if config.get('eanble_user_activity', 'true') != 'false': + if config.get('enable_user_activity', 'true') != 'false': self.register_command('mood', self.command_mood, usage='[<mood> [text]]', desc=_('Send your current mood to your contacts (use the completion).' ' Nothing means "stop broadcasting a mood".'), shortdesc=_('Send your mood.'), completion=self.completion_mood) + if config.get('enable_user_gaming', 'true') != 'false': + self.register_command('gaming', self.command_gaming, + usage='[<game name> [server address]]', + desc=_('Send your current gaming activity to your contacts.' + ' Nothing means "stop broadcasting a mood".'), + shortdesc=_('Send your gaming activity.'), + completion=None) ####################### XMPP Event Handlers ################################## @@ -2720,7 +2745,37 @@ class Core(object): else: contact.name= '' - def on_mood(self, message): + 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'] + if item.find('{urn:xmpp:gaming:0}gaming') is not None: + 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 config.get_by_tabname('display_gaming_notifications', 'false', contact.bare_jid) == 'true': + 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_mood_event(self, message): """ Called when a pep notification for an user mood is received. @@ -2747,7 +2802,7 @@ class Core(object): else: self.information(contact.bare_jid + ' stopped having his/her mood.', 'Mood') - def on_activity(self, message): + def on_activity_event(self, message): """ Called when a pep notification for an user activity is received. diff --git a/src/tabs.py b/src/tabs.py index ed2a5998..6cd3be86 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -2855,6 +2855,8 @@ class RosterInfoTab(Tab): acc.append('Mood: %s' % cont.mood) if cont.activity: acc.append('Activity: %s' % cont.activity) + if cont.gaming: + acc.append('Game: %s' % (common.format_gaming_string(cont.gaming))) msg = '\n'.join(acc) elif isinstance(selected_row, Resource): res = selected_row diff --git a/src/theming.py b/src/theming.py index 26b66377..f7a0b431 100644 --- a/src/theming.py +++ b/src/theming.py @@ -204,7 +204,9 @@ class Theme(object): CHAR_ROSTER_ASKED = '?' CHAR_ROSTER_ACTIVITY = '☃' CHAR_ROSTER_MOOD = '☺' + CHAR_ROSTER_GAMING = '♠' + COLOR_ROSTER_GAMING = (6, -1) COLOR_ROSTER_MOOD = (2, -1) COLOR_ROSTER_ACTIVITY = (3, -1) COLOR_ROSTER_TUNE = (6, -1) @@ -225,6 +227,7 @@ class Theme(object): 'help': (10, -1), 'headline': (11, -1, 'b'), 'tune': (6, -1), + 'gaming': (6, -1), 'mood': (2, -1), 'activity': (3, -1), 'default': (7, -1), diff --git a/src/windows.py b/src/windows.py index c4927a6d..0916cadb 100644 --- a/src/windows.py +++ b/src/windows.py @@ -1942,6 +1942,8 @@ class RosterWin(Win): added += len(get_theme().CHAR_ROSTER_MOOD) if contact.activity: added += len(get_theme().CHAR_ROSTER_ACTIVITY) + if contact.gaming: + added += len(get_theme().CHAR_ROSTER_GAMING) if config.getl('show_roster_jids', 'true') == 'false' and contact.name: display_name = '%s' % contact.name @@ -1966,6 +1968,8 @@ class RosterWin(Win): self.addstr(get_theme().CHAR_ROSTER_ACTIVITY, to_curses_attr(get_theme().COLOR_ROSTER_ACTIVITY)) if contact.mood: self.addstr(get_theme().CHAR_ROSTER_MOOD, to_curses_attr(get_theme().COLOR_ROSTER_MOOD)) + if contact.gaming: + self.addstr(get_theme().CHAR_ROSTER_GAMING, to_curses_attr(get_theme().COLOR_ROSTER_GAMING)) self.finish_line() def draw_resource_line(self, y, resource, colored): @@ -2033,14 +2037,22 @@ class ContactInfoWin(Win): if contact.tune: self.addstr(i, 0, 'Current Tune: %s' % common.format_tune_string(contact.tune), to_curses_attr(get_theme().COLOR_NORMAL_TEXT)) + self.finish_line() i += 1 if contact.mood: self.addstr(i, 0, 'Mood: %s' % contact.mood, to_curses_attr(get_theme().COLOR_NORMAL_TEXT)) + self.finish_line() i += 1 if contact.activity: self.addstr(i, 0, 'Activity: %s' % contact.activity, to_curses_attr(get_theme().COLOR_NORMAL_TEXT)) + self.finish_line() + i += 1 + + if contact.gaming: + self.addstr(i, 0, 'Game: %s on %s' % (contact.gaming['name'], contact.gamin['server_address']), to_curses_attr(get_theme().COLOR_NORMAL_TEXT)) + self.finish_line() i += 1 def draw_group_info(self, group): |