-
Notifications
You must be signed in to change notification settings - Fork 1
/
poll.py
53 lines (40 loc) · 1.84 KB
/
poll.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import discord
from discord.ext import commands
import settings
vote_phase = 0
class Poll(commands.Cog):
client = commands.Bot(command_prefix='.')
def __init__(self, client):
self.client = client
print("Loading Poll...")
@commands.command()
async def poll(self, ctx, question, *options: str):
if question is None:
print("user had no question")
if len(options) <= 1:
await ctx.send('Your poll should be formatted like `.poll question option1, option2, option3,` etc.')
return
if len(options) > 10:
await ctx.send('You cannot make a poll for more than 10 things.\nMake sure your poll is fomatted like '
'`.poll question option1, option2, option3,` etc.')
return
if "?" not in question:
question += "?"
if len(options) == 2 and str(options[0]).upper() == 'yes' and str(options[1]).upper() == 'no':
reactions = ['✅', '❌']
else:
reactions = ['🇦', '🇧', '🇨', '🇩', '🇪', '🇫', '🇬', '🇭', '🇮', '🇯']
description = []
for x, option in enumerate(options):
description += '\n {} {}'.format(reactions[x], str(option).title())
embed = discord.Embed(title=str(question).title(), color=settings.embed_color, description=''.join(description))
embed.set_author(name="Created by " + ctx.message.author.name, icon_url=ctx.message.author.avatar_url)
react_message = await ctx.send(embed=embed)
embed.set_footer(text='Poll ID: {}'.format(react_message.id))
await react_message.edit(embed=embed)
for reaction in reactions[:len(options)]:
await react_message.add_reaction(reaction)
def setup(client):
client.add_cog(Poll(client))