aboutsummaryrefslogtreecommitdiff
path: root/bot
diff options
context:
space:
mode:
Diffstat (limited to 'bot')
-rw-r--r--bot/ircmeeting/agenda.py35
-rw-r--r--bot/ircmeeting/meeting.py3
-rw-r--r--bot/tests/run_test.py31
3 files changed, 58 insertions, 11 deletions
diff --git a/bot/ircmeeting/agenda.py b/bot/ircmeeting/agenda.py
index 101c73c..8b9650c 100644
--- a/bot/ircmeeting/agenda.py
+++ b/bot/ircmeeting/agenda.py
@@ -23,8 +23,8 @@ class Agenda(object):
voting_already_closed_msg = "Voting is already closed. You can start it with #startvote."
voting_open_so_item_not_changed_msg = "Voting is currently open so I didn't change item. Please #endvote first"
can_not_vote_msg = "You can not vote or change agenda. Only {} can."
- not_a_number_msg = "Your vote was not recognized as a number. Please retry."
- out_of_range_msg = "Your vote was out of range!"
+ not_a_number_msg = "Your choice was not recognized as a number. Please retry."
+ out_of_range_msg = "Your choice was out of range!"
vote_confirm_msg = "You voted for #{} - {}"
timelimit_added_msg = 'Added "{}" reminder in {}:{}'
timelimit_list_msg = 'Set reminders: "{}"'
@@ -104,6 +104,7 @@ class Agenda(object):
self._voters = self._get_json(self.conf.voters_url)
self._agenda = self._get_json(self.conf.agenda_url)
self._votes = { }
+ self._voters.sort()
for i in self._agenda:
self._votes[i[0]] = { }
@@ -118,7 +119,14 @@ class Agenda(object):
return(opt)
self._votes[self._agenda[self._current_item][0]][nick] = self._agenda[self._current_item][1][opt]
- return str.format(self.vote_confirm_msg, opt, self._agenda[self._current_item][1][opt])
+
+ users_who_voted = self._votes[self._agenda[self._current_item][0]].keys()
+ users_who_voted.sort()
+
+ reply = str.format(self.vote_confirm_msg, opt, self._agenda[self._current_item][1][opt])
+ if users_who_voted == self._voters:
+ reply += '. ' + self.end_vote()
+ return(reply)
def _get_json(self, url):
str = urllib.urlopen(url).read()
@@ -126,14 +134,20 @@ class Agenda(object):
result = json.loads(str)
return result
- def _to_voting_option_number(self, line):
+ def _to_number(self, line, upper_limit):
if not line.isdigit():
return self.not_a_number_msg
opt = int(line)
- if opt < 0 or opt >= len(self._agenda[self._current_item][1]):
+ if opt < 0 or opt >= upper_limit:
return self.out_of_range_msg
return(opt)
+ def _to_voting_option_number(self, line):
+ return(self._to_number(line, len(self._agenda[self._current_item][1])))
+
+ def _to_agenda_item_number(self, line):
+ return(self._to_number(line, len(self._agenda)))
+
def options(self):
options_list = self._agenda[self._current_item][1]
n = len(options_list)
@@ -155,6 +169,17 @@ class Agenda(object):
options_list.append(option_text)
return str.format(self.added_option_msg, option_text)
+ def change_agenda_item(self, line):
+ if not self.conf.manage_agenda:
+ return('')
+ if self._vote_open:
+ return self.voting_open_so_item_not_changed_msg
+ opt = self._to_agenda_item_number(line)
+ if opt.__class__ is not int:
+ return(opt)
+ self._current_item = opt
+ return(self.get_agenda_item())
+
def remove_option(self, nick, line):
if not self.conf.manage_agenda:
return('')
diff --git a/bot/ircmeeting/meeting.py b/bot/ircmeeting/meeting.py
index e3cf38d..a86c782 100644
--- a/bot/ircmeeting/meeting.py
+++ b/bot/ircmeeting/meeting.py
@@ -343,6 +343,9 @@ class MeetingCommands(object):
reply = self.config.agenda.remove_timelimit(match.group(1))
self.reply(reply)
+ def do_changeitem(self, nick, time_, line, **kwargs):
+ self.reply(self.config.agenda.change_agenda_item(line))
+
def do_startvote(self, nick, time_, line, **kwargs):
for messageline in self.config.agenda.start_vote().split('\n'):
self.reply(messageline)
diff --git a/bot/tests/run_test.py b/bot/tests/run_test.py
index e22516b..bd116ff 100644
--- a/bot/tests/run_test.py
+++ b/bot/tests/run_test.py
@@ -344,7 +344,7 @@ class MeetBotTest(unittest.TestCase):
def get_simple_agenda_test(self):
test = test_meeting.TestMeeting()
test.set_voters(['x', 'z'])
- test.set_agenda([['first item', ['opt1', 'opt2'], ''], ['second item', [], '']])
+ test.set_agenda([['first item', ['opt1', 'opt2'], ''], ['second item', [], ''], ['third item', [], '']])
test.M.config.manage_agenda = False
test.answer_should_match("20:13:50 <x> #startmeeting",
@@ -358,9 +358,16 @@ class MeetBotTest(unittest.TestCase):
# Test changing item before vote
test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is second item.')
- test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is second item.')
+ test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is third item.')
+ test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is third item.')
+ test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is second item.')
test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is first item.')
test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is first item.')
+ test.answer_should_match('20:13:50 <x> #changeitem 2', 'Current agenda item is third item.')
+ test.answer_should_match('20:13:50 <x> #changeitem 1', 'Current agenda item is second item.')
+ test.answer_should_match('20:13:50 <x> #changeitem 0', 'Current agenda item is first item.')
+ test.answer_should_match('20:13:50 <x> #changeitem 10', 'Your choice was out of range!')
+ test.answer_should_match('20:13:50 <x> #changeitem puppy', 'Your choice was not recognized as a number. Please retry.')
# Test changing item during vote
test.process('20:13:50 <x> #startvote')
@@ -368,13 +375,14 @@ class MeetBotTest(unittest.TestCase):
'open so I didn\'t change item. Please #endvote first')
test.answer_should_match('20:13:50 <x> #previtem', 'Voting is currently ' +\
'open so I didn\'t change item. Please #endvote first')
+ test.answer_should_match('20:13:50 <x> #changeitem 2', 'Voting is currently ' +\
+ 'open so I didn\'t change item. Please #endvote first')
# Test changing item after vote
test.process('20:13:50 <x> #endvote')
test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is second item.')
- test.answer_should_match('20:13:50 <x> #nextitem', 'Current agenda item is second item.')
- test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is first item.')
test.answer_should_match('20:13:50 <x> #previtem', 'Current agenda item is first item.')
+ test.answer_should_match('20:13:50 <x> #changeitem 2', 'Current agenda item is third item.')
def test_agenda_option_listing(self):
test = self.get_simple_agenda_test()
@@ -408,12 +416,13 @@ class MeetBotTest(unittest.TestCase):
def test_agenda_voting(self):
test = self.get_simple_agenda_test()
+ test.M.config.agenda._voters.append('t')
test.answer_should_match('20:13:50 <x> #startvote', 'Voting started\. ' +\
'Available voting options are:\n0. opt1\n1. opt2\nVote ' +\
'#vote <option number>.\nEnd voting with #endvote.')
test.answer_should_match('20:13:50 <x> #startvote', 'Voting is already open. ' +\
'You can end it with #endvote.')
- test.answer_should_match('20:13:50 <x> #vote 10', 'Your vote was out of range\!')
+ test.answer_should_match('20:13:50 <x> #vote 10', 'Your choice was out of range\!')
test.answer_should_match('20:13:50 <x> #vote 0', 'You voted for #0 - opt1')
test.answer_should_match('20:13:50 <x> #vote 1', 'You voted for #1 - opt2')
test.answer_should_match('20:13:50 <z> #vote 0', 'You voted for #0 - opt1')
@@ -427,7 +436,17 @@ class MeetBotTest(unittest.TestCase):
test.answer_should_match('20:13:50 <x> #endmeeting', 'Meeting ended ' +\
'.*\nMinutes:.*\nMinutes \(text\):.*\nLog:.*')
- assert(test.votes() == {'first item': {u'x': 'opt2', u'z': 'opt1'}, 'second item': {}})
+ assert(test.votes() == {'first item': {u'x': 'opt2', u'z': 'opt1'}, 'second item': {}, 'third item': {}})
+
+ def test_agenda_close_voting_after_last_vote(self):
+ test = self.get_simple_agenda_test()
+ test.answer_should_match('20:13:50 <x> #startvote', 'Voting started\. ' +\
+ 'Available voting options are:\n0. opt1\n1. opt2\nVote ' +\
+ '#vote <option number>.\nEnd voting with #endvote.')
+ test.answer_should_match('20:13:50 <x> #startvote', 'Voting is already open. ' +\
+ 'You can end it with #endvote.')
+ test.answer_should_match('20:13:50 <x> #vote 0', 'You voted for #0 - opt1')
+ test.answer_should_match('20:13:50 <z> #vote 0', 'You voted for #0 - opt1. Voting closed.')
def test_agenda_time_limit_adding(self):
test = self.get_simple_agenda_test()