|
@@ -1,9 +1,14 @@
|
|
|
+import re
|
|
|
+
|
|
|
from rollbot import as_command, Attachment
|
|
|
from rollbot.injection import Args, ArgList, SenderName, Origin
|
|
|
|
|
|
# RGYBbPO
|
|
|
EMOJIS = ["🟥", "🟩", "🟨", "🟦", "🟫", "🟪", "🟧", "❤️", "💚", "💛", "💙", "🤎", "💜", "🧡"]
|
|
|
|
|
|
+# Title best effort search
|
|
|
+TITLE_PAT = re.compile(r"\s*[tT]itle:\s*(.+)")
|
|
|
+
|
|
|
|
|
|
@as_command
|
|
|
def poll(origin: Origin, name: SenderName, args: Args, arg_list: ArgList):
|
|
@@ -17,6 +22,13 @@ def poll(origin: Origin, name: SenderName, args: Args, arg_list: ArgList):
|
|
|
else:
|
|
|
opts = arg_list
|
|
|
|
|
|
+ i, title = next(
|
|
|
+ ((i, m.group(1)) for i, o in enumerate(opts) if (m := TITLE_PAT.match(o))),
|
|
|
+ (-1, None),
|
|
|
+ )
|
|
|
+ if title:
|
|
|
+ del opts[i]
|
|
|
+
|
|
|
if len(opts) > len(EMOJIS):
|
|
|
return f"Polls are limited to {len(EMOJIS)} options! Hardware limitation :\\("
|
|
|
|
|
@@ -24,9 +36,11 @@ def poll(origin: Origin, name: SenderName, args: Args, arg_list: ArgList):
|
|
|
return "Can't make an empty poll!"
|
|
|
|
|
|
msg = f"Poll started by {name}\n\n"
|
|
|
+ if title:
|
|
|
+ msg += f"**{title}**\n"
|
|
|
atts = []
|
|
|
for e, o in zip(EMOJIS, opts):
|
|
|
msg += f"> {e} - **{o.strip()}**\n"
|
|
|
atts.append(Attachment(name="react", body=e))
|
|
|
msg += "\nPlease participate in democracy by picking the emojis corresponding to your choices!"
|
|
|
- return msg, *atts
|
|
|
+ return msg, *atts, Attachment(name="pin", body=None)
|