Skip to content
This repository has been archived by the owner on Jul 31, 2018. It is now read-only.

Added the rpoll command #167

Merged
merged 3 commits into from
Nov 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions cogs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,64 @@ async def update(self, ctx):
else:
return await ctx.send('This command is disabled as the user have not starred <https://github.com/verixx/selfbot.py>')

@commands.command(pass_context=True)
async def rpoll(self, ctx, *, args):
"""Create a poll using reactions. {p}help rpoll for more information.
{p}rpoll <question> | <answer> | <answer> - Create a poll. You may use as many answers as you want, placing a pipe | symbol in between them.
Example:
{p}rpoll What is your favorite anime? | Steins;Gate | Naruto | Attack on Titan | Shrek
You can also use the "time" flag to set the amount of time in seconds the poll will last for.
Example:
{p}rpoll What time is it? | HAMMER TIME! | SHOWTIME! | time=10
"""
await ctx.message.delete()
options = args.split(" | ")
time = [x for x in options if x.startswith("time=")]
if time:
time = time[0]
if time:
options.remove(time)
if len(options) <= 1:
raise commands.errors.MissingRequiredArgument
if len(options) >= 11:
return await ctx.send(self.bot.bot_prefix + "You must have 9 options or less.")
if time:
time = int(time.strip("time="))
else:
time = 30
emoji = ['1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣', '7⃣', '8⃣', '9⃣']
to_react = []
confirmation_msg = "**{}?**:\n\n".format(options[0].rstrip("?"))
for idx, option in enumerate(options[1:]):
confirmation_msg += "{} - {}\n".format(emoji[idx], option)
to_react.append(emoji[idx])
confirmation_msg += "\n\nYou have {} seconds to vote!".format(time)
poll_msg = await ctx.send(confirmation_msg)
for emote in to_react:
await poll_msg.add_reaction(emote)
await asyncio.sleep(time)
async for message in ctx.message.channel.history():
if message.id == poll_msg.id:
poll_msg = message
results = {}
for reaction in poll_msg.reactions:
if reaction.emoji in to_react:
results[reaction.emoji] = reaction.count - 1
end_msg = "The poll is over. The results:\n\n"
for result in results:
end_msg += "{} {} - {} votes\n".format(result, options[emoji.index(result)+1], results[result])
top_result = max(results, key=lambda key: results[key])
if len([x for x in results if results[x] == results[top_result]]) > 1:
top_results = []
for key, value in results.items():
if value == results[top_result]:
top_results.append(options[emoji.index(key)+1])
end_msg += "\nThe victory is tied between: {}".format(", ".join(top_results))
else:
top_result = options[emoji.index(top_result)+1]
end_msg += "\n{} is the winner!".format(top_result)
await ctx.send(end_msg)

@commands.command()
async def cc(self, ctx, option, name='None', content=None):
git = self.bot.get_cog('Git')
Expand Down