internal: make command_say async

This commit is contained in:
mathieui 2022-02-15 22:43:10 +01:00 committed by Maxime Buquet
parent d6de6dccfa
commit 6174ca70d9
10 changed files with 32 additions and 28 deletions

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 <jid> [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):

View file

@ -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:

View file

@ -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 <fixed message>
"""
@ -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

View file

@ -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)

View file

@ -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 <message>
Or normal input + enter

View file

@ -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()