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

View file

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