added info feature

This commit is contained in:
matnad 2019-02-19 18:30:03 +01:00
parent f2fdecd1cd
commit 32a70bb01d
5 changed files with 78 additions and 13 deletions

View File

@ -1,3 +1,10 @@
# Changelog for Version 2.1
## New features
- React to a poll with ❔ to get personalised info
- Added back the command line feature from version 1. Type *pm!cmd help* to get started
- Multiple choice is no longer a flag, but a number of how many options each voter can choose
# Changelog for Version 2.0
## TL;DR

View File

@ -467,7 +467,7 @@ class Poll:
"**1** - :white_check_mark: :negative_squared_cross_mark:\n"
"**2** - :thumbsup: :zipper_mouth: :thumbsdown:\n"
"**3** - :heart_eyes: :thumbsup: :zipper_mouth: :thumbsdown: :nauseated_face:\n"
"**4** - in favour, against, abstain\n"
"**4** - in favour, against, abstaining\n"
"\n"
"Example for custom options:\n"
"**apple juice, banana ice cream, kiwi slices** ")
@ -510,7 +510,7 @@ class Poll:
if split.__len__() == 1 and split[0] in ['0', 'all', 'everyone']:
return ['@everyone']
if n_roles <= 20:
if n_roles <= 20 and force is None:
if not all([r.isdigit() for r in split]):
raise ExpectedInteger
elif any([int(r) > n_roles for r in split]):
@ -1011,6 +1011,7 @@ class Poll:
msg,
r
)
await self.bot.add_reaction(msg, '')
return msg
else:
for i, r in enumerate(self.options_reaction):
@ -1018,8 +1019,10 @@ class Poll:
msg,
AZ_EMOJIS[i]
)
await self.bot.add_reaction(msg, '')
return msg
elif not await self.is_open():
await self.bot.add_reaction(msg, '')
await self.bot.add_reaction(msg, '📎')
else:
return msg

View File

@ -1,10 +1,12 @@
import argparse
import copy
import datetime
import json
import logging
import shlex
import discord
import pytz
from discord.ext import commands
@ -269,7 +271,7 @@ class PollControls:
parser.add_argument('-multiple_choice', '-mc', default='1')
parser.add_argument('-roles', '-r', default='all')
parser.add_argument('-weights', '-w', default='none')
parser.add_argument('-duration', '-d', default='0')
parser.add_argument('-deadline', '-d', default='0')
parser.add_argument('-anonymous', '-a', action="store_true")
helpstring = parser.format_help()
@ -300,7 +302,7 @@ class PollControls:
await poll.set_multiple_choice(force=args.multiple_choice)
await poll.set_roles(force=args.roles)
await poll.set_weights(force=args.weights)
await poll.set_duration(force=args.duration)
await poll.set_duration(force=args.deadline)
poll = await self.wizard(ctx, route, server)
if poll:
@ -524,8 +526,67 @@ class PollControls:
)
return
# no rights, terminate function
# info
member = server.get_member(user_id)
if emoji == '':
is_open = await p.is_open()
embed = discord.Embed(title=f"Info for the {'CLOSED ' if not is_open else ''}poll \"{p.name}\"",
description='', color=SETTINGS.color)
embed.set_author(name=f" >> {p.short}", icon_url=SETTINGS.author_icon)
# vote rights
vote_rights = await p.has_required_role(member)
embed.add_field(name=f'{"Can you vote?" if is_open else "Could you vote?"}',
value=f'{"" if vote_rights else ""}', inline=False)
# edit rights
edit_rights = False
if str(member.id) == str(p.author):
edit_rights = True
elif member.server_permissions.manage_server:
edit_rights = True
else:
result = await self.bot.db.config.find_one({'_id': str(server.id)})
if result and result.get('admin_role') in [r.name for r in member.roles]:
edit_rights = True
embed.add_field(name='Can you manage the poll?', value=f'{"" if edit_rights else ""}', inline=False)
# choices
choices = 'You have not voted yet.' if vote_rights else 'You can\'t vote in this poll.'
if user.id in p.votes:
if p.votes[user.id]['choices'].__len__() > 0:
choices = ', '.join([p.options_reaction[c] for c in p.votes[user.id]['choices']])
embed.add_field(name=f'{"Your current votes (can be changed as long as the poll is open):" if is_open else "Your final votes:"}',
value=choices, inline=False)
# weight
if vote_rights:
weight = 1
if p.weights_roles.__len__() > 0:
valid_weights = [p.weights_numbers[p.weights_roles.index(r)] for r in
list(set([n.name for n in member.roles]).intersection(set(p.weights_roles)))]
if valid_weights.__len__() > 0:
weight = max(valid_weights)
else:
weight = 'You can\'t vote in this poll.'
embed.add_field(name='Weight of your votes:', value=weight, inline=False)
# time left
deadline = p.get_duration_with_tz()
if not is_open:
time_left = 'This poll is closed.'
elif deadline == 0:
time_left = 'Until manually closed.'
else:
time_left = str(deadline-datetime.datetime.utcnow().replace(tzinfo=pytz.utc)).split('.', 2)[0]
embed.add_field(name='Time left in the poll:', value=time_left, inline=False)
await self.bot.send_message(user, embed=embed)
return
# Assume: User wants to vote with reaction
# no rights, terminate function
if not await p.has_required_role(member):
await self.bot.remove_reaction(message, emoji, user)
await self.bot.send_message(user, f'You are not allowed to vote in this poll. Only users with '

View File

@ -53,13 +53,7 @@ async def on_ready():
bot.db = mongo.pollmaster
bot.session = aiohttp.ClientSession()
print(bot.db)
await bot.change_presence(game=discord.Game(name=f'V2 IS HERE >> pm!help'))
await bot.db.config.update_one(
{'_id': '261914618342014977'},
{'$set': {'prefix': 'd!'}},
upsert=True
)
await bot.change_presence(game=discord.Game(name=f'pm!help - v2.1 is live!'))
# check discord server configs
try:

View File

@ -1,4 +1,4 @@
aiohttp==3.5.4
aiohttp==1.0.5
async-timeout==3.0.1
attrs==18.2.0
beautifulsoup4==4.7.1