diff options
Diffstat (limited to 'bot')
-rw-r--r-- | bot/ircmeeting/agenda.py | 15 | ||||
-rw-r--r-- | bot/ircmeeting/meeting.py | 2 | ||||
-rw-r--r-- | bot/tests/run_test.py | 10 |
3 files changed, 26 insertions, 1 deletions
diff --git a/bot/ircmeeting/agenda.py b/bot/ircmeeting/agenda.py index 32ddb9f..97bcfcf 100644 --- a/bot/ircmeeting/agenda.py +++ b/bot/ircmeeting/agenda.py @@ -1,9 +1,11 @@ import json import urllib +import re class Agenda(object): # Messages + added_option_msg = "You added new voting option: {}" empty_agenda_msg = "Agenda is empty so I can't help you manage meeting (and voting)." current_item_msg = "Current agenda item is {}." voting_already_open_msg = "Voting is already open. You can end it with #endvote." @@ -11,7 +13,7 @@ class Agenda(object): voting_close_msg = "Voting closed." 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. Only {} can vote" + 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!" vote_confirm_msg = "You voted for #{} - {}" @@ -111,6 +113,17 @@ class Agenda(object): for i in range(n): options += str.format("{}. {}\n", i, options_list[i]) return options + def add_option(self, nick, line): + if not self.conf.manage_agenda: + return('') + if not nick in self._voters: + return str.format(self.can_not_vote_msg, ", ".join(self._voters)) + options_list = self._agenda[self._current_item][1] + option_text = re.match( ' *?add (.*)', line).group(1) + options_list.append(option_text) + return str.format(self.added_option_msg, option_text) + + def post_result(self): if not self.conf.manage_agenda: diff --git a/bot/ircmeeting/meeting.py b/bot/ircmeeting/meeting.py index d8589c4..f9c907b 100644 --- a/bot/ircmeeting/meeting.py +++ b/bot/ircmeeting/meeting.py @@ -343,6 +343,8 @@ class MeetingCommands(object): def do_option(self, nick, time_, line, **kwargs): if re.match( ' *?list', line): result = self.config.agenda.options() + elif re.match( ' *?add .*', line): + result = self.config.agenda.add_option(nick, line) for messageline in result.split('\n'): self.reply(messageline) diff --git a/bot/tests/run_test.py b/bot/tests/run_test.py index c28f1ae..a80e6ec 100644 --- a/bot/tests/run_test.py +++ b/bot/tests/run_test.py @@ -385,6 +385,16 @@ class MeetBotTest(unittest.TestCase): test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\ 'are:\n0. opt1\n1. opt2\n') + def test_agenda_option_adding(self): + test = self.get_simple_agenda_test() + test.process('20:13:50 <x> #nextitem') + test.answer_should_match('20:13:50 <not_allowed> #option add first option', + 'You can not vote or change agenda. Only x, z can.') + test.answer_should_match('20:13:50 <x> #option add first option', + 'You added new voting option: first option') + test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\ + 'are:\n0. first option') + def test_agenda_voting(self): test = self.get_simple_agenda_test() test.answer_should_match('20:13:50 <x> #startvote', 'Voting started\. ' +\ |