summaryrefslogtreecommitdiff
path: root/poezio/core/commands.py
diff options
context:
space:
mode:
Diffstat (limited to 'poezio/core/commands.py')
-rw-r--r--poezio/core/commands.py63
1 files changed, 33 insertions, 30 deletions
diff --git a/poezio/core/commands.py b/poezio/core/commands.py
index 915f9d90..fe91ca67 100644
--- a/poezio/core/commands.py
+++ b/poezio/core/commands.py
@@ -8,7 +8,7 @@ from xml.etree import ElementTree as ET
from typing import List, Optional, Tuple
import logging
-from slixmpp import Iq, JID, InvalidJID
+from slixmpp import JID, InvalidJID
from slixmpp.exceptions import XMPPError, IqError, IqTimeout
from slixmpp.xmlstream.xmlstream import NotConnectedError
from slixmpp.xmlstream.stanzabase import StanzaBase
@@ -298,7 +298,7 @@ class CommandCore:
jid = self.core.tabs.current_tab.jid
if jid is None or not jid.domain:
return None
- asyncio.ensure_future(
+ asyncio.create_task(
self._list_async(jid)
)
@@ -446,14 +446,19 @@ class CommandCore:
"""
/bookmark_local [room][/nick] [password]
"""
- if not args and not isinstance(self.core.tabs.current_tab,
- tabs.MucTab):
+ tab = self.core.tabs.current_tab
+ if not args and not isinstance(tab, tabs.MucTab):
return
room, nick = self._parse_join_jid(args[0] if args else '')
password = args[1] if len(args) > 1 else None
- asyncio.ensure_future(
+ if not room:
+ room = tab.jid.bare
+ if password is None and tab.password is not None:
+ password = tab.password
+
+ asyncio.create_task(
self._add_bookmark(
room=room,
nick=nick,
@@ -468,8 +473,8 @@ class CommandCore:
"""
/bookmark [room][/nick] [autojoin] [password]
"""
- if not args and not isinstance(self.core.tabs.current_tab,
- tabs.MucTab):
+ tab = self.core.tabs.current_tab
+ if not args and not isinstance(tab, tabs.MucTab):
return
room, nick = self._parse_join_jid(args[0] if args else '')
password = args[2] if len(args) > 2 else None
@@ -478,13 +483,18 @@ class CommandCore:
autojoin = (method == 'local' or
(len(args) > 1 and args[1].lower() == 'true'))
- asyncio.ensure_future(
+ if not room:
+ room = tab.jid.bare
+ if password is None and tab.password is not None:
+ password = tab.password
+
+ asyncio.create_task(
self._add_bookmark(room, nick, autojoin, password, method)
)
async def _add_bookmark(
self,
- room: Optional[str],
+ room: str,
nick: Optional[str],
autojoin: bool,
password: str,
@@ -503,16 +513,8 @@ class CommandCore:
method: 'local' or 'remote'.
'''
- # No room Jid was specified. A nick may have been specified. Set the
- # room Jid to be bookmarked to the current tab bare jid.
- if not room:
- tab = self.core.tabs.current_tab
- if not isinstance(tab, tabs.MucTab):
- return
- room = tab.jid.bare
- if password is None and tab.password is not None:
- password = tab.password
- elif room == '*':
+
+ if room == '*':
return await self._add_wildcard_bookmarks(method)
# Once we found which room to bookmark, find corresponding tab if it
@@ -524,13 +526,14 @@ class CommandCore:
# Validate / Normalize
try:
- if nick is None:
+ if not nick:
jid = JID(room)
else:
jid = JID('{}/{}'.format(room, nick))
room = jid.bare
nick = jid.resource or None
except InvalidJID:
+ self.core.information(f'Invalid address for bookmark: {room}/{nick}', 'Error')
return
bookmark = self.core.bookmarks[room]
@@ -596,7 +599,7 @@ class CommandCore:
else:
jid = args[0]
- asyncio.ensure_future(
+ asyncio.create_task(
self._remove_bookmark_routine(jid)
)
@@ -981,10 +984,9 @@ class CommandCore:
bare = JID(jid).bare
except InvalidJID:
return self.core.information('Invalid JID for /impromptu: %s' % args[0], 'Error')
- jids.add(bare)
+ jids.add(JID(bare))
- asyncio.ensure_future(self.core.impromptu(jids))
- self.core.information('Invited %s to a random room' % (', '.join(jids)), 'Info')
+ asyncio.create_task(self.core.impromptu(jids))
@command_args_parser.quoted(1, 1, [''])
def decline(self, args):
@@ -1043,7 +1045,7 @@ class CommandCore:
if jid is None:
self.core.information('No specified JID to block', 'Error')
else:
- asyncio.ensure_future(self._block_async(jid))
+ asyncio.create_task(self._block_async(jid))
async def _block_async(self, jid: JID):
"""Block a JID, asynchronously"""
@@ -1096,7 +1098,7 @@ class CommandCore:
jid = JID(current_tab.jid.bare)
if jid is not None:
- asyncio.ensure_future(
+ asyncio.create_task(
self._unblock_async(jid)
)
else:
@@ -1153,7 +1155,7 @@ class CommandCore:
"""
/destroy_room [JID [reason [alternative room JID]]]
"""
- async def do_destroy(room: JID, reason: str, altroom: JID):
+ async def do_destroy(room: JID, reason: str, altroom: Optional[JID]):
try:
await self.core.xmpp['xep_0045'].destroy(room, reason, altroom)
except (IqError, IqTimeout) as e:
@@ -1178,6 +1180,7 @@ class CommandCore:
return
reason = args[1]
+ altroom = None
if args[2]:
try:
altroom = JID(args[2])
@@ -1185,7 +1188,7 @@ class CommandCore:
self.core.information('Invalid alternative room JID: "%s"' % args[2], 'Error')
return
- asyncio.ensure_future(do_destroy(room, reason, altroom))
+ asyncio.create_task(do_destroy(room, reason, altroom))
@command_args_parser.quoted(1, 1, [''])
def bind(self, args):
@@ -1280,7 +1283,7 @@ class CommandCore:
list(self.core.plugin_manager.plugins.keys())), 'Info')
@command_args_parser.quoted(1, 1)
- def message(self, args):
+ async def message(self, args):
"""
/message <jid> [message]
"""
@@ -1310,7 +1313,7 @@ class CommandCore:
else:
self.core.focus_tab(tab)
if len(args) == 2:
- tab.command_say(args[1])
+ await tab.command_say(args[1])
@command_args_parser.ignored
def xml_tab(self):