summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2015-08-27 01:39:07 +0200
committermathieui <mathieui@mathieui.net>2015-08-27 01:39:07 +0200
commite7c780d5a03b004e7d5e10d5a1659cb9d02b6138 (patch)
tree8d8b85a8f1d86b24bed2e01a8b77aa052ccdf82d
parent11c69343a4172d83e1af9a0dc013ca0570eff955 (diff)
downloadpoezio-e7c780d5a03b004e7d5e10d5a1659cb9d02b6138.tar.gz
poezio-e7c780d5a03b004e7d5e10d5a1659cb9d02b6138.tar.bz2
poezio-e7c780d5a03b004e7d5e10d5a1659cb9d02b6138.tar.xz
poezio-e7c780d5a03b004e7d5e10d5a1659cb9d02b6138.zip
Add a marquee plugin
Using the power of last message corrections
-rw-r--r--plugins/marquee.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/plugins/marquee.py b/plugins/marquee.py
new file mode 100644
index 00000000..6fcf4631
--- /dev/null
+++ b/plugins/marquee.py
@@ -0,0 +1,70 @@
+"""
+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.
+
+
+"""
+from plugin import BasePlugin
+import tabs
+from decorators import command_args_parser
+
+def move(text, step, spacing):
+ new_text = text + (" " * spacing)
+ return new_text[-(step % len(new_text)):] + new_text[:-(step % len(new_text))]
+
+class Plugin(BasePlugin):
+ default_config = {"marquee": {"refresh": 1, "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')
+
+ @command_args_parser.raw
+ def command_marquee(self, args):
+ tab = self.api.current_tab()
+ tab.command_say(args)
+ 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))
+
+ def delayed_event(self, jid, body, msg_id, duration):
+ if duration >= self.config.get("total_duration"):
+ return
+ message = self.core.xmpp.make_message(jid)
+ message["type"] = "groupchat"
+ message["body"] = move(body, duration, self.config.get("padding"))
+ message["replace"]["id"] = msg_id
+ message.send()
+ self.api.add_timed_event(self.api.create_delayed_event(self.config.get("refresh"), self.delayed_event, jid, body, message["id"], duration + 1))
+
+