summaryrefslogtreecommitdiff
path: root/src/core/commands.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/commands.py')
-rw-r--r--src/core/commands.py78
1 files changed, 38 insertions, 40 deletions
diff --git a/src/core/commands.py b/src/core/commands.py
index 7c0f56fa..c27263e2 100644
--- a/src/core/commands.py
+++ b/src/core/commands.py
@@ -6,14 +6,15 @@ import logging
log = logging.getLogger(__name__)
+import functools
import sys
from datetime import datetime
from gettext import gettext as _
from xml.etree import cElementTree as ET
-from sleekxmpp.xmlstream.stanzabase import StanzaBase
-from sleekxmpp.xmlstream.handler import Callback
-from sleekxmpp.xmlstream.matcher import StanzaPath
+from slixmpp.xmlstream.stanzabase import StanzaBase
+from slixmpp.xmlstream.handler import Callback
+from slixmpp.xmlstream.matcher import StanzaPath
import bookmark
import common
@@ -274,7 +275,6 @@ def command_list(self, arg):
self.add_tab(list_tab, True)
cb = list_tab.on_muc_list_item_received
self.xmpp.plugin['xep_0030'].get_items(jid=server,
- block=False,
callback=cb)
def command_version(self, arg):
@@ -440,7 +440,7 @@ def command_bookmark_local(self, arg=''):
new_bookmarks.extend(bookmark.bookmarks)
bookmark.bookmarks = new_bookmarks
bookmark.save_local()
- bookmark.save_remote(self.xmpp)
+ bookmark.save_remote(self.xmpp, None)
self.information('Bookmarks added and saved.', 'Info')
return
else:
@@ -508,12 +508,13 @@ def command_bookmark(self, arg=''):
new_bookmarks.append(b)
new_bookmarks.extend(bookmark.bookmarks)
bookmark.bookmarks = new_bookmarks
-
- if bookmark.save_remote(self.xmpp):
- bookmark.save_local()
- self.information("Bookmarks added.", "Info")
- else:
- self.information("Could not add the bookmarks.", "Info")
+ def _cb(self, iq):
+ if iq["type"] != "error":
+ bookmark.save_local()
+ self.information("Bookmarks added.", "Info")
+ else:
+ self.information("Could not add the bookmarks.", "Info")
+ bookmark.save_remote(self.xmpp, functools.partial(_cb, self))
return
else:
info = safeJID(args[0])
@@ -542,14 +543,16 @@ def command_bookmark(self, arg=''):
if password:
bm.password = password
bm.autojoin = autojoin
- if bookmark.save_remote(self.xmpp):
- self.information('Bookmark added.', 'Info')
+ def _cb(self, iq):
+ if iq["type"] != "error":
+ self.information('Bookmark added.', 'Info')
+ else:
+ self.information("Could not add the bookmarks.", "Info")
+ bookmark.save_remote(self.xmpp, functools.partial(_cb, self))
remote = []
for each in bookmark.bookmarks:
if each.method in ('pep', 'privatexml'):
remote.append(each)
- self.information(_('Your remote bookmarks are now: %s') % remote,
- _('Info'))
def command_bookmarks(self, arg=''):
"""/bookmarks"""
@@ -691,7 +694,6 @@ def command_last_activity(self, arg):
if jid == '':
return self.command_help('last_activity')
self.xmpp.plugin['xep_0012'].get_last_activity(jid,
- block=False,
callback=callback)
def command_mood(self, arg):
@@ -700,7 +702,8 @@ def command_mood(self, arg):
"""
args = common.shell_split(arg)
if not args:
- return self.xmpp.plugin['xep_0107'].stop(block=False)
+ self.xmpp.plugin['xep_0107'].stop()
+ return
mood = args[0]
if mood not in pep.MOODS:
return self.information(_('%s is not a correct value for a mood.')
@@ -710,10 +713,8 @@ def command_mood(self, arg):
text = args[1]
else:
text = None
- self.xmpp.plugin['xep_0107'].publish_mood(mood,
- text,
- callback=dumb_callback,
- block=False)
+ self.xmpp.plugin['xep_0107'].publish_mood(mood, text,
+ callback=dumb_callback)
def command_activity(self, arg):
"""
@@ -722,7 +723,8 @@ def command_activity(self, arg):
args = common.shell_split(arg)
length = len(args)
if not length:
- return self.xmpp.plugin['xep_0108'].stop(block=False)
+ self.xmpp.plugin['xep_0108'].stop()
+ return
general = args[0]
if general not in pep.ACTIVITIES:
return self.information(_('%s is not a correct value for an activity')
@@ -742,11 +744,8 @@ def command_activity(self, arg):
return self.information(_('%s is not a correct value '
'for an activity') % specific,
_('Error'))
- self.xmpp.plugin['xep_0108'].publish_activity(general,
- specific,
- text,
- callback=dumb_callback,
- block=False)
+ self.xmpp.plugin['xep_0108'].publish_activity(general, specific, text,
+ callback=dumb_callback)
def command_gaming(self, arg):
"""
@@ -754,7 +753,8 @@ def command_gaming(self, arg):
"""
args = common.shell_split(arg)
if not args:
- return self.xmpp.plugin['xep_0196'].stop(block=False)
+ self.xmpp.plugin['xep_0196'].stop()
+ return
name = args[0]
if len(args) > 1:
address = args[1]
@@ -762,8 +762,7 @@ def command_gaming(self, arg):
address = None
return self.xmpp.plugin['xep_0196'].publish_gaming(name=name,
server_address=address,
- callback=dumb_callback,
- block=False)
+ callback=dumb_callback)
def command_invite(self, arg):
"""/invite <to> <room> [reason]"""
@@ -807,22 +806,23 @@ def command_quit(self, arg=''):
"""
/quit
"""
+ if not self.xmpp.is_connected():
+ self.exit()
+ return
if len(arg.strip()) != 0:
msg = arg
else:
msg = None
if config.get('enable_user_mood', True):
- self.xmpp.plugin['xep_0107'].stop(block=False)
+ self.xmpp.plugin['xep_0107'].stop()
if config.get('enable_user_activity', True):
- self.xmpp.plugin['xep_0108'].stop(block=False)
+ self.xmpp.plugin['xep_0108'].stop()
if config.get('enable_user_gaming', True):
- self.xmpp.plugin['xep_0196'].stop(block=False)
+ self.xmpp.plugin['xep_0196'].stop()
self.save_config()
self.plugin_manager.disable_plugins()
self.disconnect(msg)
- self.running = False
- self.reset_curses()
- sys.exit()
+ self.xmpp.add_event_handler("disconnected", self.exit, disposable=True)
def command_destroy_room(self, arg=''):
"""
@@ -945,15 +945,13 @@ def command_adhoc(self, arg):
if len(arg) > 1:
return self.command_help('ad-hoc')
elif arg:
- jid = safeJID(arg[0]).server
+ jid = safeJID(arg[0])
else:
return self.information('Please provide a jid', 'Error')
list_tab = tabs.AdhocCommandsListTab(jid)
self.add_tab(list_tab, True)
cb = list_tab.on_list_received
- self.xmpp.plugin['xep_0050'].get_commands(jid=jid,
- local=False,
- block=False,
+ self.xmpp.plugin['xep_0050'].get_commands(jid=jid, local=False,
callback=cb)
def command_self(self, arg=None):