Fix #3181 (make /marquee work in all chat tabs)
Detecting errors would be a pain though
This commit is contained in:
parent
0d787998df
commit
51566463bd
1 changed files with 17 additions and 6 deletions
|
@ -46,26 +46,37 @@ class Plugin(BasePlugin):
|
|||
default_config = {"marquee": {"refresh": 1.0, "total_duration": 30, "padding": 20}}
|
||||
|
||||
def init(self):
|
||||
self.add_tab_command(tabs.MucTab, 'marquee', self.command_marquee, 'Replicate the <marquee/> behavior in a message')
|
||||
for tab_t in [tabs.MucTab, tabs.ConversationTab, tabs.PrivateTab]:
|
||||
self.add_tab_command(tab_t, 'marquee', self.command_marquee,
|
||||
'Replicate the <marquee/> behavior in a message')
|
||||
|
||||
@command_args_parser.raw
|
||||
def command_marquee(self, args):
|
||||
tab = self.api.current_tab()
|
||||
tab.command_say(args)
|
||||
is_muctab = isinstance(tab, tabs.MucTab)
|
||||
msg_id = tab.last_sent_message["id"]
|
||||
jid = tab.name
|
||||
|
||||
self.api.add_timed_event(self.api.create_delayed_event(self.config.get("refresh"), self.delayed_event, jid, args, msg_id, 0, 0))
|
||||
event = self.api.create_delayed_event(self.config.get("refresh"),
|
||||
self.delayed_event,
|
||||
jid, args, msg_id, 0, 0,
|
||||
is_muctab)
|
||||
self.api.add_timed_event(event)
|
||||
|
||||
def delayed_event(self, jid, body, msg_id, step, duration):
|
||||
def delayed_event(self, jid, body, msg_id, step, duration, is_muctab):
|
||||
if duration >= self.config.get("total_duration"):
|
||||
return
|
||||
message = self.core.xmpp.make_message(jid)
|
||||
message["type"] = "groupchat"
|
||||
message["type"] = "groupchat" if is_muctab else "chat"
|
||||
message["body"] = move(body, step, self.config.get("padding"))
|
||||
message["replace"]["id"] = msg_id
|
||||
message.send()
|
||||
self.api.information("refresh : %s" % self.config.get("refresh"))
|
||||
self.api.add_timed_event(self.api.create_delayed_event(self.config.get("refresh"), self.delayed_event, jid, body, message["id"], step + 1, duration + self.config.get("refresh")))
|
||||
event = self.api.create_delayed_event(self.config.get("refresh"),
|
||||
self.delayed_event, jid, body,
|
||||
message["id"], step + 1,
|
||||
duration + self.config.get("refresh"),
|
||||
is_muctab)
|
||||
self.api.add_timed_event(event)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue