From ae2ce4dd1a84fd2abe26222e6ffa93a11a92111f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 26 May 2020 14:36:41 +0200 Subject: [PATCH 1/3] plugins/marquee: Change space char to nbsp to troll other clients better MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugins/marquee.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/marquee.py b/plugins/marquee.py index 80bfbfeb..14219161 100644 --- a/plugins/marquee.py +++ b/plugins/marquee.py @@ -41,7 +41,7 @@ from poezio.decorators import command_args_parser def move(text, step, spacing): - new_text = text + (" " * spacing) + new_text = text + ("\u00A0" * spacing) return new_text[-(step % len(new_text)):] + new_text[:-( step % len(new_text))] From cf43a36bc63eea6ded716e1103b7aef2e3d1f29b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 26 May 2020 14:41:13 +0200 Subject: [PATCH 2/3] plugins/marquee: Fix LMC, use origin id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugins/marquee.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/marquee.py b/plugins/marquee.py index 14219161..9319a7f6 100644 --- a/plugins/marquee.py +++ b/plugins/marquee.py @@ -85,6 +85,6 @@ class Plugin(BasePlugin): message.send() event = self.api.create_delayed_event( self.config.get("refresh"), self.delayed_event, jid, body, - message["id"], step + 1, duration + self.config.get("refresh"), + msg_id, step + 1, duration + self.config.get("refresh"), is_muctab) self.api.add_timed_event(event) From 8465d7555c27d0e5b5670ed0172a2532052c7bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 26 May 2020 14:44:08 +0200 Subject: [PATCH 3/3] plugins/dice: Fix LMC (use origin id), reorganize things a bit to stop using tab.last_sent_message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugins/dice.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/plugins/dice.py b/plugins/dice.py index f92604e3..3b540cbd 100644 --- a/plugins/dice.py +++ b/plugins/dice.py @@ -29,6 +29,7 @@ Configuration """ import random +from typing import Optional from poezio import tabs from poezio.decorators import command_args_parser @@ -40,17 +41,16 @@ DICE = '\u2680\u2681\u2682\u2683\u2684\u2685' class DiceRoll: __slots__ = [ 'duration', 'total_duration', 'dice_number', 'msgtype', 'jid', - 'last_msgid', 'increments' + 'msgid', 'increments' ] - def __init__(self, total_duration, dice_number, is_muc, jid, msgid, - increments): + def __init__(self, total_duration, dice_number, msgtype, jid, msgid, increments): self.duration = 0 self.total_duration = total_duration self.dice_number = dice_number - self.msgtype = "groupchat" if is_muc else "chat" + self.msgtype = msgtype self.jid = jid - self.last_msgid = msgid + self.msgid = msgid self.increments = increments def reroll(self): @@ -60,8 +60,11 @@ class DiceRoll: return self.duration >= self.total_duration +def roll_dice(num_dice: int) -> str: + return ''.join(random.choice(DICE) for _ in range(num_dice)) + class Plugin(BasePlugin): - default_config = {"dice": {"refresh": 0.5, "default_duration": 5}} + default_config = {"dice": {"refresh": 0.75, "default_duration": 7.5}} def init(self): for tab_t in [tabs.MucTab, tabs.DynamicConversationTab, tabs.StaticConversationTab, tabs.PrivateTab]: @@ -90,13 +93,17 @@ class Plugin(BasePlugin): self.core.command.help("roll") return - firstroll = ''.join(random.choice(DICE) for _ in range(num_dice)) - tab.command_say(firstroll) - is_muctab = isinstance(tab, tabs.MucTab) - msg_id = tab.last_sent_message["id"] + msgtype = 'groupchat' if isinstance(tab, tabs.MucTab) else 'chat' + + message = self.core.xmpp.make_message(tab.jid) + message['type'] = msgtype + message['body'] = roll_dice(num_dice) + message.send() + increment = self.config.get('refresh') - roll = DiceRoll(duration, num_dice, is_muctab, tab.jid, msg_id, - increment) + msgid = message['id'] + + roll = DiceRoll(duration, num_dice, msgtype, tab.jid, msgid, increment) event = self.api.create_delayed_event(increment, self.delayed_event, roll) self.api.add_timed_event(event) @@ -107,11 +114,9 @@ class Plugin(BasePlugin): roll.reroll() message = self.core.xmpp.make_message(roll.jid) message["type"] = roll.msgtype - message["body"] = ''.join( - random.choice(DICE) for _ in range(roll.dice_number)) - message["replace"]["id"] = roll.last_msgid + message["body"] = roll_dice(roll.dice_number) + message["replace"]["id"] = roll.msgid message.send() - roll.last_msgid = message['id'] event = self.api.create_delayed_event(roll.increments, self.delayed_event, roll) self.api.add_timed_event(event)