diff --git a/plugins/amsg.py b/plugins/amsg.py index 4cd6c055..3b81085a 100644 --- a/plugins/amsg.py +++ b/plugins/amsg.py @@ -29,7 +29,7 @@ class Plugin(BasePlugin): short='Broadcast a message', help='Broadcast the message to all the joined rooms.') - def command_amsg(self, args): + async def command_amsg(self, args): for room in self.core.tabs: if isinstance(room, MucTab) and room.joined: - room.command_say(args) + await room.command_say(args) diff --git a/plugins/marquee.py b/plugins/marquee.py index 9319a7f6..2fea3ed6 100644 --- a/plugins/marquee.py +++ b/plugins/marquee.py @@ -34,6 +34,7 @@ Configuration """ +import asyncio from poezio.plugin import BasePlugin from poezio import tabs from poezio import xhtml @@ -65,7 +66,7 @@ class Plugin(BasePlugin): def command_marquee(self, args): tab = self.api.current_tab() args = xhtml.clean_text(xhtml.convert_simple_to_full_colors(args)) - tab.command_say(args) + asyncio.ensure_future(tab.command_say(args)) is_muctab = isinstance(tab, tabs.MucTab) msg_id = tab.last_sent_message["id"] jid = tab.jid diff --git a/plugins/send_delayed.py b/plugins/send_delayed.py index e8b00027..92ed97c1 100644 --- a/plugins/send_delayed.py +++ b/plugins/send_delayed.py @@ -18,6 +18,7 @@ This plugin adds a command to the chat tabs. """ +import asyncio from poezio.plugin import BasePlugin from poezio.core.structs import Completion from poezio.decorators import command_args_parser @@ -74,6 +75,6 @@ class Plugin(BasePlugin): tab = args[0] # anything could happen to the tab during the interval try: - tab.command_say(args[1]) + asyncio.ensure_future(tab.command_say(args[1])) except: pass diff --git a/plugins/tell.py b/plugins/tell.py index 614c1ef5..cd72a9e5 100644 --- a/plugins/tell.py +++ b/plugins/tell.py @@ -25,6 +25,7 @@ This plugin defines two new commands for chatroom tabs: List all queued messages for the current chatroom. """ +import asyncio from poezio.plugin import BasePlugin from poezio.core.structs import Completion from poezio.decorators import command_args_parser @@ -66,7 +67,7 @@ class Plugin(BasePlugin): if nick not in self.tabs[tab]: return for i in self.tabs[tab][nick]: - tab.command_say("%s: %s" % (nick, i)) + asyncio.ensure_future(tab.command_say("%s: %s" % (nick, i))) del self.tabs[tab][nick] @command_args_parser.ignored diff --git a/poezio/core/commands.py b/poezio/core/commands.py index 9ad5a78c..f4662021 100644 --- a/poezio/core/commands.py +++ b/poezio/core/commands.py @@ -1283,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 [message] """ @@ -1313,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): diff --git a/poezio/core/core.py b/poezio/core/core.py index bc57024c..0c71b566 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -906,7 +906,9 @@ class Core: """ if not isinstance(self.tabs.current_tab, ChatTab): return False - self.tabs.current_tab.command_say(msg) + asyncio.ensure_future( + self.tabs.current_tab.command_say(msg) + ) return True async def invite(self, jid: JID, room: JID, reason: Optional[str] = None, force_mediated: bool = False) -> bool: diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index 431acf17..c88a8a10 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -669,7 +669,9 @@ class ChatTab(Tab): if not self.execute_command(txt): if txt.startswith('//'): txt = txt[1:] - self.command_say(xhtml.convert_simple_to_full_colors(txt)) + asyncio.ensure_future( + self.command_say(xhtml.convert_simple_to_full_colors(txt)) + ) self.cancel_paused_delay() @command_args_parser.raw @@ -794,7 +796,7 @@ class ChatTab(Tab): self.last_sent_message = msg @command_args_parser.raw - def command_correct(self, line: str) -> None: + async def command_correct(self, line: str) -> None: """ /correct """ @@ -804,7 +806,7 @@ class ChatTab(Tab): if not self.last_sent_message: self.core.information('There is no message to correct.', 'Error') return - self.command_say(line, correct=True) + await self.command_say(line, correct=True) def completion_correct(self, the_input): if self.last_sent_message and the_input.get_argument_position() == 1: @@ -838,7 +840,7 @@ class ChatTab(Tab): self.state = 'scrolled' @command_args_parser.raw - def command_say(self, line: str, attention: bool = False, correct: bool = False): + async def command_say(self, line: str, attention: bool = False, correct: bool = False): pass def goto_build_lines(self, new_date): @@ -1110,10 +1112,10 @@ class OneToOneTab(ChatTab): self.refresh() @command_args_parser.raw - def command_attention(self, message): + async def command_attention(self, message): """/attention [message]""" if message != '': - self.command_say(message, attention=True) + await self.command_say(message, attention=True) else: msg = self.core.xmpp.make_message(self.get_dest_jid()) msg['type'] = 'chat' @@ -1121,7 +1123,7 @@ class OneToOneTab(ChatTab): msg.send() @command_args_parser.raw - def command_say(self, line: str, attention: bool = False, correct: bool = False): + async def command_say(self, line: str, attention: bool = False, correct: bool = False): pass @command_args_parser.ignored diff --git a/poezio/tabs/conversationtab.py b/poezio/tabs/conversationtab.py index 9cf68d75..76c86d70 100644 --- a/poezio/tabs/conversationtab.py +++ b/poezio/tabs/conversationtab.py @@ -172,7 +172,7 @@ class ConversationTab(OneToOneTab): @refresh_wrapper.always @command_args_parser.raw - def command_say(self, line: str, attention: bool = False, correct: bool = False): + async def command_say(self, line: str, attention: bool = False, correct: bool = False): msg: SMessage = self.core.xmpp.make_message( mto=self.get_dest_jid(), mfrom=self.core.xmpp.boundjid @@ -189,7 +189,6 @@ class ConversationTab(OneToOneTab): self.core.events.trigger('conversation_say', msg, self) if not msg['body']: return - replaced = False if correct or msg['replace']['id']: msg['replace']['id'] = self.last_sent_message['id'] # type: ignore else: @@ -209,12 +208,10 @@ class ConversationTab(OneToOneTab): if not msg['body']: return self.set_last_sent_message(msg, correct=correct) - asyncio.ensure_future( - self.core.handler.on_normal_message(msg) - ) - # Our receipts slixmpp hack msg._add_receipt = True # type: ignore msg.send() + await self.core.handler.on_normal_message(msg) + # Our receipts slixmpp hack self.cancel_paused_delay() @command_args_parser.quoted(0, 1) diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 654b990a..e2c27ab1 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -1682,8 +1682,10 @@ class MucTab(ChatTab): r = self.core.open_private_window(self.jid.bare, user.nick) if r and len(args) == 2: msg = args[1] - r.command_say( - xhtml.convert_simple_to_full_colors(msg) + asyncio.ensure_future( + r.command_say( + xhtml.convert_simple_to_full_colors(msg) + ) ) if not r: self.core.information("Cannot find user: %s" % nick, 'Error') @@ -1856,7 +1858,7 @@ class MucTab(ChatTab): return None @command_args_parser.raw - def command_say(self, line: str, attention: bool = False, correct: bool = False): + async def command_say(self, line: str, attention: bool = False, correct: bool = False): """ /say Or normal input + enter diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py index fc126b66..9ed968b7 100644 --- a/poezio/tabs/privatetab.py +++ b/poezio/tabs/privatetab.py @@ -202,7 +202,7 @@ class PrivateTab(OneToOneTab): @refresh_wrapper.always @command_args_parser.raw - def command_say(self, line: str, attention: bool = False, correct: bool = False) -> None: + async def command_say(self, line: str, attention: bool = False, correct: bool = False) -> None: if not self.on: return our_jid = JID(self.jid.bare) @@ -240,9 +240,7 @@ class PrivateTab(OneToOneTab): if not msg['body']: return self.set_last_sent_message(msg, correct=correct) - asyncio.ensure_future( - self.core.handler.on_groupchat_private_message(msg, sent=True) - ) + await self.core.handler.on_groupchat_private_message(msg, sent=True) # Our receipts slixmpp hack msg._add_receipt = True # type: ignore msg.send()