From 4ffdb13172251e77c727cd64ce7b18da0844e966 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Mon, 9 Mar 2020 16:37:20 +1000 Subject: Implement vote command. The vote command takes a given list of options and generates a simple message and corresponding reactions for each so members can quickly take a vote on a subject during in-server discussions and meetings. --- bot/cogs/utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bot/cogs/utils.py b/bot/cogs/utils.py index 8ea972145..c5eaa547b 100644 --- a/bot/cogs/utils.py +++ b/bot/cogs/utils.py @@ -257,6 +257,24 @@ class Utils(Cog): embed.description = best_match await ctx.send(embed=embed) + @command(aliases=("poll",)) + @with_role(*MODERATION_ROLES) + async def vote(self, ctx: Context, title: str, *options: str) -> None: + """ + Build a quick voting poll with matching reactions with the provided options. + + A maximum of 20 options can be provided, as Discord supports a max of 20 + reactions on a single message. + """ + if len(options) > 20: + raise BadArgument("I can only handle 20 options!") + + options = {chr(i): f"{chr(i)} - {v}" for i, v in enumerate(options, start=127462)} + embed = Embed(title=title, description="\n".join(options.values())) + message = await ctx.send(embed=embed) + for reaction in options: + await message.add_reaction(reaction) + def setup(bot: Bot) -> None: """Load the Utils cog.""" -- cgit v1.2.3