mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 04:02:46 +01:00
Poll: Make answers case-insensitive
This commit is contained in:
parent
200acdfa93
commit
bc3a441888
@ -131,7 +131,7 @@ class Poll_(callbacks.Plugin):
|
||||
|
||||
poll_id = max(self._polls[(irc.network, channel)], default=0) + 1
|
||||
|
||||
answers = [(answer.split()[0], answer) for answer in answers]
|
||||
answers = [(answer.split()[0].casefold(), answer) for answer in answers]
|
||||
|
||||
answer_id_counts = collections.Counter(
|
||||
id_ for (id_, _) in answers
|
||||
@ -194,6 +194,8 @@ class Poll_(callbacks.Plugin):
|
||||
if msg.nick in poll.votes:
|
||||
irc.error(_("You already voted on this poll."), Raise=True)
|
||||
|
||||
answer_id = answer_id.casefold()
|
||||
|
||||
if answer_id not in poll.answers:
|
||||
irc.error(
|
||||
format(
|
||||
@ -221,7 +223,7 @@ class Poll_(callbacks.Plugin):
|
||||
counts.update({answer_id: 0 for answer_id in poll.answers})
|
||||
|
||||
results = [
|
||||
format(_("%n for %s"), (v, _("vote")), k)
|
||||
format(_("%n for %s"), (v, _("vote")), poll.answers[k].split()[0])
|
||||
for (k, v) in counts.most_common()
|
||||
]
|
||||
|
||||
|
@ -131,12 +131,27 @@ class PollTestCase(ChannelPluginTestCase):
|
||||
def testDuplicateId(self):
|
||||
self.assertResponse(
|
||||
'poll add "Is this a test?" "Yes" "Yes" "Maybe"',
|
||||
"Error: Duplicate answer identifier(s): Yes",
|
||||
"Error: Duplicate answer identifier(s): yes",
|
||||
)
|
||||
|
||||
self.assertResponse(
|
||||
'poll add "Is this a test?" "Yes totally" "Yes and no" "Maybe"',
|
||||
"Error: Duplicate answer identifier(s): Yes",
|
||||
"Error: Duplicate answer identifier(s): yes",
|
||||
)
|
||||
|
||||
def testCaseInsensitive(self):
|
||||
self.assertResponse(
|
||||
'poll add "Is this a test?" "Yeß" "No" "Maybe"',
|
||||
"The operation succeeded. Poll # 1 created.",
|
||||
)
|
||||
|
||||
self.assertNotError("vote 1 Yeß", frm="voter1!foo@bar")
|
||||
self.assertNotError("vote 1 yESS", frm="voter2!foo@bar")
|
||||
self.assertNotError("vote 1 no", frm="voter3!foo@bar")
|
||||
|
||||
self.assertResponse(
|
||||
"results 1",
|
||||
"2 votes for Yeß, 1 vote for No, and 0 votes for Maybe",
|
||||
)
|
||||
|
||||
def testList(self):
|
||||
|
Loading…
Reference in New Issue
Block a user