2015-08-26 23:39:07 +00:00
|
|
|
"""
|
|
|
|
Marquee plugin: replicate the html <marquee/> tag with message corrections.
|
|
|
|
|
|
|
|
Usage of this plugin is not recommended.
|
|
|
|
|
|
|
|
Commands
|
|
|
|
--------
|
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
|
|
|
|
/marquee <text>
|
|
|
|
Send the following text with <marquee/> behavior
|
|
|
|
|
|
|
|
Configuration
|
|
|
|
-------------
|
|
|
|
|
|
|
|
.. glossary::
|
|
|
|
:sorted:
|
|
|
|
|
|
|
|
refresh
|
|
|
|
**Default:** ``1``
|
|
|
|
|
|
|
|
Interval between each correction (the closest to 0 is the fastest)
|
|
|
|
|
|
|
|
total_duration
|
|
|
|
**Default:** ``30``
|
|
|
|
|
|
|
|
Total duration of the animation.
|
|
|
|
|
|
|
|
padding
|
|
|
|
**Default:** ``20``
|
|
|
|
|
|
|
|
Padding to use to move the text.
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
2016-06-27 23:10:52 +00:00
|
|
|
from poezio.plugin import BasePlugin
|
|
|
|
from poezio import tabs
|
|
|
|
from poezio import xhtml
|
|
|
|
from poezio.decorators import command_args_parser
|
2015-08-26 23:39:07 +00:00
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
|
2015-08-26 23:39:07 +00:00
|
|
|
def move(text, step, spacing):
|
|
|
|
new_text = text + (" " * spacing)
|
2018-08-15 11:13:17 +00:00
|
|
|
return new_text[-(step % len(new_text)):] + new_text[:-(
|
|
|
|
step % len(new_text))]
|
|
|
|
|
2015-08-26 23:39:07 +00:00
|
|
|
|
|
|
|
class Plugin(BasePlugin):
|
2018-08-15 11:13:17 +00:00
|
|
|
default_config = {
|
|
|
|
"marquee": {
|
|
|
|
"refresh": 1.0,
|
|
|
|
"total_duration": 30,
|
|
|
|
"padding": 20
|
|
|
|
}
|
|
|
|
}
|
2015-08-26 23:39:07 +00:00
|
|
|
|
|
|
|
def init(self):
|
2019-07-19 16:55:16 +00:00
|
|
|
for tab_t in [tabs.MucTab, tabs.DynamicConversationTab, tabs.StaticConversationTab, tabs.PrivateTab]:
|
2018-08-15 11:13:17 +00:00
|
|
|
self.add_tab_command(
|
|
|
|
tab_t, 'marquee', self.command_marquee,
|
|
|
|
'Replicate the <marquee/> behavior in a message')
|
2015-08-26 23:39:07 +00:00
|
|
|
|
|
|
|
@command_args_parser.raw
|
|
|
|
def command_marquee(self, args):
|
|
|
|
tab = self.api.current_tab()
|
2016-05-10 19:31:37 +00:00
|
|
|
args = xhtml.clean_text(xhtml.convert_simple_to_full_colors(args))
|
2015-08-26 23:39:07 +00:00
|
|
|
tab.command_say(args)
|
2016-04-01 17:39:39 +00:00
|
|
|
is_muctab = isinstance(tab, tabs.MucTab)
|
2015-08-26 23:39:07 +00:00
|
|
|
msg_id = tab.last_sent_message["id"]
|
2019-04-28 00:02:49 +00:00
|
|
|
jid = tab.jid
|
2015-08-26 23:39:07 +00:00
|
|
|
|
2018-08-15 11:13:17 +00:00
|
|
|
event = self.api.create_delayed_event(
|
|
|
|
self.config.get("refresh"), self.delayed_event, jid, args, msg_id,
|
|
|
|
1, 0, is_muctab)
|
2016-04-01 17:39:39 +00:00
|
|
|
self.api.add_timed_event(event)
|
2015-08-26 23:39:07 +00:00
|
|
|
|
2016-04-01 17:39:39 +00:00
|
|
|
def delayed_event(self, jid, body, msg_id, step, duration, is_muctab):
|
2015-08-26 23:39:07 +00:00
|
|
|
if duration >= self.config.get("total_duration"):
|
|
|
|
return
|
|
|
|
message = self.core.xmpp.make_message(jid)
|
2016-04-01 17:39:39 +00:00
|
|
|
message["type"] = "groupchat" if is_muctab else "chat"
|
2015-08-26 23:48:05 +00:00
|
|
|
message["body"] = move(body, step, self.config.get("padding"))
|
2015-08-26 23:39:07 +00:00
|
|
|
message["replace"]["id"] = msg_id
|
|
|
|
message.send()
|
2018-08-15 11:13:17 +00:00
|
|
|
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)
|
2016-04-01 17:39:39 +00:00
|
|
|
self.api.add_timed_event(event)
|