Browse Source

Poll command

Kirk Trombley 1 year ago
parent
commit
1e502dd850
1 changed files with 31 additions and 0 deletions
  1. 31 0
      commands/commands/poll.py

+ 31 - 0
commands/commands/poll.py

@@ -0,0 +1,31 @@
+from rollbot import as_command, Attachment
+from rollbot.injection import Args, ArgList, SenderName, Origin
+
+# RWKGYBbPO
+EMOJIS = "🟥🟩🟨🟦🟫🟪🟧❤️💚💛💙🤎💜🧡"
+
+@as_command
+def poll(origin: Origin, name: SenderName, args: Args, arg_list: ArgList):
+    if origin != "DISCORD":
+        return "Polls only supported in Discord!"
+
+    for delim in ("|", ";", ","):
+        if delim in args:
+            opts = args.split(delim)
+            break
+    else:
+        opts = arg_list
+
+    if len(opts) > len(EMOJIS):
+        return f"Polls are limited to {len(EMOJIS)} options! Hardware limitation :\\("
+
+    if len(opts) == 0:
+        return "Can't make an empty poll!"
+
+    msg = f"Poll started by {name}\n\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