aboutsummaryrefslogtreecommitdiff
path: root/bot
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-06-17 14:06:25 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-06-17 14:06:25 +0200
commitd7fcb9289fb9403db1c646b4205117d1ba66acfe (patch)
treee8a233cc1f7f7b70bb55f0f8365ea859b974ab14 /bot
parentAdd '#option add' command to MeetBot (diff)
downloadcouncil-webapp-d7fcb9289fb9403db1c646b4205117d1ba66acfe.tar.gz
council-webapp-d7fcb9289fb9403db1c646b4205117d1ba66acfe.tar.bz2
council-webapp-d7fcb9289fb9403db1c646b4205117d1ba66acfe.zip
Add '#option remove' command to MeetBot
Diffstat (limited to 'bot')
-rw-r--r--bot/ircmeeting/agenda.py31
-rw-r--r--bot/ircmeeting/meeting.py2
-rw-r--r--bot/tests/run_test.py9
3 files changed, 36 insertions, 6 deletions
diff --git a/bot/ircmeeting/agenda.py b/bot/ircmeeting/agenda.py
index 97bcfcf..928ff5f 100644
--- a/bot/ircmeeting/agenda.py
+++ b/bot/ircmeeting/agenda.py
@@ -8,6 +8,7 @@ class Agenda(object):
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 {}."
+ removed_option_msg = "You removed voting option {}: {}"
voting_already_open_msg = "Voting is already open. You can end it with #endvote."
voting_open_msg = "Voting started. {}Vote #vote <option number>.\nEnd voting with #endvote."
voting_close_msg = "Voting closed."
@@ -86,13 +87,10 @@ class Agenda(object):
return('')
if not nick in self._voters:
return str.format(self.can_not_vote_msg, ", ".join(self._voters))
- 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]):
- return self.out_of_range_msg
+ opt = self._to_voting_option_number(line)
+ if opt.__class__ is not int:
+ 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])
@@ -103,6 +101,14 @@ class Agenda(object):
result = json.loads(str)
return result
+ def _to_voting_option_number(self, line):
+ 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]):
+ return self.out_of_range_msg
+ return(opt)
+
def options(self):
options_list = self._agenda[self._current_item][1]
n = len(options_list)
@@ -113,6 +119,7 @@ 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('')
@@ -123,7 +130,19 @@ class Agenda(object):
options_list.append(option_text)
return str.format(self.added_option_msg, option_text)
+ def remove_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))
+
+ opt_str = re.match( ' *?remove (.*)', line).group(1)
+ opt = self._to_voting_option_number(opt_str)
+ if opt.__class__ is not int:
+ return(opt)
+ option = self._agenda[self._current_item][1].pop(opt)
+ return str.format(self.removed_option_msg, str(opt), option)
def post_result(self):
if not self.conf.manage_agenda:
diff --git a/bot/ircmeeting/meeting.py b/bot/ircmeeting/meeting.py
index f9c907b..84949ed 100644
--- a/bot/ircmeeting/meeting.py
+++ b/bot/ircmeeting/meeting.py
@@ -345,6 +345,8 @@ class MeetingCommands(object):
result = self.config.agenda.options()
elif re.match( ' *?add .*', line):
result = self.config.agenda.add_option(nick, line)
+ elif re.match( ' *?remove .*', line):
+ result = self.config.agenda.remove_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 a80e6ec..9808ee6 100644
--- a/bot/tests/run_test.py
+++ b/bot/tests/run_test.py
@@ -395,6 +395,15 @@ class MeetBotTest(unittest.TestCase):
test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
'are:\n0. first option')
+ def test_agenda_option_removing(self):
+ test = self.get_simple_agenda_test()
+ test.answer_should_match('20:13:50 <not_allowed> #option remove 1',
+ 'You can not vote or change agenda. Only x, z can.')
+ test.answer_should_match('20:13:50 <x> #option remove 1',
+ 'You removed voting option 1: opt2')
+ test.answer_should_match('20:13:50 <x> #option list', 'Available voting options ' +\
+ 'are:\n0. opt1')
+
def test_agenda_voting(self):
test = self.get_simple_agenda_test()
test.answer_should_match('20:13:50 <x> #startvote', 'Voting started\. ' +\