refactor(command|sondage): continue rewrite of sondage" -m "known issues: more than 2 votes and remove are not updates

This commit is contained in:
Romain J 2019-10-07 23:51:06 +02:00
parent 98b241d51b
commit ad4fb2fa89
2 changed files with 11 additions and 10 deletions

View file

@ -84,7 +84,10 @@ class Polls(commands.Cog):
if poll:
if poll.is_anonymous:
try:
await self.remove_reaction(pld)
except discord.errors.Forbidden:
pass
user_id = str(pld.user_id).encode()
@ -94,28 +97,23 @@ class Polls(commands.Cog):
else poll.responses
if not responses.get(str(choice)):
print(97)
user_id_hash = bcrypt.hashpw(user_id, bcrypt.gensalt())
responses \
.get(str(choice)) \
.append(user_id_hash.decode())
else:
print(responses.get(str(choice)))
print(103)
for i, responder in enumerate(responses.get(str(choice))):
print(105)
if bcrypt.checkpw(user_id, responder.encode()):
print(107)
responses \
.get(str(choice)) \
.pop(i)
break
else:
print(112)
user_id_hash = bcrypt.hashpw(user_id, bcrypt.gensalt())
responses \
.get(str(choice)) \
.append(user_id_hash.decode())
print(117)
break
poll.responses = json.dumps(responses)
self.bot.database.session.commit()
@ -137,7 +135,7 @@ class Polls(commands.Cog):
e = discord.Embed(description=f"**{question}**")
e.set_author(
name=ctx.author,
name=self.bot.user if anonymous else ctx.author,
icon_url="https://cdn.gnous.eu/tuxbot/survey1.png"
)
for i, response in enumerate(responses):

View file

@ -1,8 +1,11 @@
{
"280805240977227776": [
"b!"
"b! "
],
"303633056944881686": [
"b! "
],
"336642139381301249": [
"b! "
]
}