diff options
author | mathieui <mathieui@mathieui.net> | 2021-02-03 21:04:36 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2021-02-09 19:16:03 +0100 |
commit | 2cfe56bbbe47c9bf8aa87c48324091e90623d43f (patch) | |
tree | 59a426fb8535c76d6a23bff2801849328effa6f2 /poezio/core | |
parent | ae0888bd3d6892f3da3ff0d7c3cbb60f61653f6c (diff) | |
download | poezio-2cfe56bbbe47c9bf8aa87c48324091e90623d43f.tar.gz poezio-2cfe56bbbe47c9bf8aa87c48324091e90623d43f.tar.bz2 poezio-2cfe56bbbe47c9bf8aa87c48324091e90623d43f.tar.xz poezio-2cfe56bbbe47c9bf8aa87c48324091e90623d43f.zip |
Remove activity/mood/gaming/tune from poezio core
rationale: probably 0.1% of poezio users have ever used the commands,
and a very small number of users are using the PEP events like that.
It is better to unclutter the poezio source and add it as a plugin,
with less tight coupling.
Diffstat (limited to 'poezio/core')
-rw-r--r-- | poezio/core/commands.py | 72 | ||||
-rw-r--r-- | poezio/core/completions.py | 28 | ||||
-rw-r--r-- | poezio/core/core.py | 50 | ||||
-rw-r--r-- | poezio/core/handlers.py | 173 |
4 files changed, 0 insertions, 323 deletions
diff --git a/poezio/core/commands.py b/poezio/core/commands.py index 964bd0a7..ebd8f130 100644 --- a/poezio/core/commands.py +++ b/poezio/core/commands.py @@ -15,7 +15,6 @@ from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath from poezio import common -from poezio import pep from poezio import tabs from poezio import multiuserchat as muc from poezio.bookmarks import Bookmark @@ -938,71 +937,6 @@ class CommandCore: if status else '') self.core.information(msg, 'Info') - @command_args_parser.quoted(0, 2) - def mood(self, args): - """ - /mood [<mood> [text]] - """ - if not args: - return self.core.xmpp.plugin['xep_0107'].stop() - - mood = args[0] - if mood not in pep.MOODS: - return self.core.information( - '%s is not a correct value for a mood.' % mood, 'Error') - if len(args) == 2: - text = args[1] - else: - text = None - self.core.xmpp.plugin['xep_0107'].publish_mood( - mood, text, callback=dumb_callback) - - @command_args_parser.quoted(0, 3) - def activity(self, args): - """ - /activity [<general> [specific] [text]] - """ - length = len(args) - if not length: - return self.core.xmpp.plugin['xep_0108'].stop() - - general = args[0] - if general not in pep.ACTIVITIES: - return self.core.information( - '%s is not a correct value for an activity' % general, 'Error') - specific = None - text = None - if length == 2: - if args[1] in pep.ACTIVITIES[general]: - specific = args[1] - else: - text = args[1] - elif length == 3: - specific = args[1] - text = args[2] - if specific and specific not in pep.ACTIVITIES[general]: - return self.core.information( - '%s is not a correct value ' - 'for an activity' % specific, 'Error') - self.core.xmpp.plugin['xep_0108'].publish_activity( - general, specific, text, callback=dumb_callback) - - @command_args_parser.quoted(0, 2) - def gaming(self, args): - """ - /gaming [<game name> [server address]] - """ - if not args: - return self.core.xmpp.plugin['xep_0196'].stop() - - name = args[0] - if len(args) > 1: - address = args[1] - else: - address = None - return self.core.xmpp.plugin['xep_0196'].publish_gaming( - name=name, server_address=address, callback=dumb_callback) - @command_args_parser.quoted(2, 1, [None]) async def invite(self, args): """/invite <to> <room> [reason]""" @@ -1200,12 +1134,6 @@ class CommandCore: return msg = args[0] - if config.get('enable_user_mood'): - self.core.xmpp.plugin['xep_0107'].stop() - if config.get('enable_user_activity'): - self.core.xmpp.plugin['xep_0108'].stop() - if config.get('enable_user_gaming'): - self.core.xmpp.plugin['xep_0196'].stop() self.core.save_config() self.core.plugin_manager.disable_plugins() self.core.xmpp.add_event_handler( diff --git a/poezio/core/completions.py b/poezio/core/completions.py index 98ca9ba0..88ed57b3 100644 --- a/poezio/core/completions.py +++ b/poezio/core/completions.py @@ -13,7 +13,6 @@ from functools import reduce from slixmpp import JID from poezio import common -from poezio import pep from poezio import tabs from poezio import xdg from poezio.common import safeJID @@ -318,33 +317,6 @@ class CompletionCore: comp = sorted(onlines) + sorted(offlines) return Completion(the_input.new_completion, comp, n, quotify=True) - def activity(self, the_input): - """Completion for /activity""" - n = the_input.get_argument_position(quoted=True) - args = common.shell_split(the_input.text) - if n == 1: - return Completion( - the_input.new_completion, - sorted(pep.ACTIVITIES.keys()), - n, - quotify=True) - elif n == 2: - if args[1] in pep.ACTIVITIES: - l = list(pep.ACTIVITIES[args[1]]) - l.remove('category') - l.sort() - return Completion(the_input.new_completion, l, n, quotify=True) - - def mood(self, the_input): - """Completion for /mood""" - n = the_input.get_argument_position(quoted=True) - if n == 1: - return Completion( - the_input.new_completion, - sorted(pep.MOODS.keys()), - 1, - quotify=True) - def last_activity(self, the_input): """ Completion for /last_activity <jid> diff --git a/poezio/core/core.py b/poezio/core/core.py index 703319c5..efab8810 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -297,22 +297,9 @@ class Core: self.handler.on_vcard_avatar) self.xmpp.add_event_handler("avatar_metadata_publish", self.handler.on_0084_avatar) - if config.get('enable_user_tune'): - self.xmpp.add_event_handler("user_tune_publish", - self.handler.on_tune_event) if config.get('enable_user_nick'): self.xmpp.add_event_handler("user_nick_publish", self.handler.on_nick_received) - if config.get('enable_user_mood'): - self.xmpp.add_event_handler("user_mood_publish", - self.handler.on_mood_event) - if config.get('enable_user_activity'): - self.xmpp.add_event_handler("user_activity_publish", - self.handler.on_activity_event) - if config.get('enable_user_gaming'): - self.xmpp.add_event_handler("user_gaming_publish", - self.handler.on_gaming_event) - all_stanzas = Callback('custom matcher', connection.MatchAll(None), self.handler.incoming_stanza) self.xmpp.register_handler(all_stanzas) @@ -525,12 +512,6 @@ class Core: } log.error("%s received. Exiting…", signals[sig]) - if config.get('enable_user_mood'): - self.xmpp.plugin['xep_0107'].stop() - if config.get('enable_user_activity'): - self.xmpp.plugin['xep_0108'].stop() - if config.get('enable_user_gaming'): - self.xmpp.plugin['xep_0196'].stop() self.plugin_manager.disable_plugins() self.disconnect('%s received' % signals.get(sig)) self.xmpp.add_event_handler("disconnected", self.exit, disposable=True) @@ -1693,37 +1674,6 @@ class Core: for command in get_commands(self.command, self.completion, self.plugin_manager): self.register_command(**command) - if config.get('enable_user_activity'): - self.register_command( - 'activity', - self.command.activity, - usage='[<general> [specific] [text]]', - desc='Send your current activity to your contacts ' - '(use the completion). Nothing means ' - '"stop broadcasting an activity".', - shortdesc='Send your activity.', - completion=self.completion.activity) - if config.get('enable_user_mood'): - 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'): - 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 gaming activity".', - shortdesc='Send your gaming activity.', - completion=None) - def check_blocking(self, features: List[str]): if 'urn:xmpp:blocking' in features and not self.xmpp.anon: self.register_command( diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py index 1d5dcffe..ec714915 100644 --- a/poezio/core/handlers.py +++ b/poezio/core/handlers.py @@ -27,7 +27,6 @@ from xml.etree import ElementTree as ET from poezio import common from poezio import fixes -from poezio import pep from poezio import tabs from poezio import xhtml from poezio import multiuserchat as muc @@ -539,178 +538,6 @@ class HandlerCore: else: contact.name = '' - 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 - xml_node = item.xml.find('{urn:xmpp:gaming:0}game') - # list(xml_node) checks whether there are children or not. - if xml_node is not None and list(xml_node): - 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.core.information( - '%s is playing %s' % (contact.bare_jid, - common.format_gaming_string( - contact.gaming)), 'Gaming') - else: - self.core.information(contact.bare_jid + ' stopped playing.', - 'Gaming') - - def on_mood_event(self, message): - """ - Called when a pep notification for a 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 - xml_node = item.xml.find('{http://jabber.org/protocol/mood}mood') - # list(xml_node) checks whether there are children or not. - if xml_node is not None and list(xml_node): - 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.core.information( - 'Mood from ' + contact.bare_jid + ': ' + contact.mood, - 'Mood') - else: - self.core.information( - contact.bare_jid + ' stopped having their mood.', 'Mood') - - def on_activity_event(self, message): - """ - Called when a pep notification for a 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 - xml_node = item.xml.find('{http://jabber.org/protocol/activity}activity') - # list(xml_node) checks whether there are children or not. - if xml_node is not None and list(xml_node): - 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.core.information( - 'Activity from ' + contact.bare_jid + ': ' + - contact.activity, 'Activity') - else: - self.core.information( - contact.bare_jid + ' stopped doing their activity.', - 'Activity') - - def on_tune_event(self, message): - """ - Called when a pep notification for a 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 - xml_node = item.xml.find('{http://jabber.org/protocol/tune}tune') - # list(xml_node) checks whether there are children or not. - if xml_node is not None and list(xml_node): - 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.core.information( - 'Tune from ' + message['from'].bare + ': ' + - common.format_tune_string(contact.tune), 'Tune') - else: - self.core.information( - contact.bare_jid + ' stopped listening to music.', 'Tune') - def on_groupchat_message(self, message): """ Triggered whenever a message is received from a multi-user chat room. |