From: "Petteri Räty" <betelgeuse@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/council-webapp:master commit in: bot/tests/, bot/ircmeeting/
Date: Sat, 18 Jun 2011 15:46:13 +0000 (UTC) [thread overview]
Message-ID: <d7fcb9289fb9403db1c646b4205117d1ba66acfe.betelgeuse@gentoo> (raw)
commit: d7fcb9289fb9403db1c646b4205117d1ba66acfe
Author: Joachim Filip Ignacy Bartosik <jbartosik <AT> gmail <DOT> com>
AuthorDate: Fri Jun 17 12:06:25 2011 +0000
Commit: Petteri Räty <betelgeuse <AT> gentoo <DOT> org>
CommitDate: Fri Jun 17 12:06:25 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/council-webapp.git;a=commit;h=d7fcb928
Add '#option remove' command to MeetBot
---
bot/ircmeeting/agenda.py | 31 +++++++++++++++++++++++++------
bot/ircmeeting/meeting.py | 2 ++
bot/tests/run_test.py | 9 +++++++++
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\. ' +\
next reply other threads:[~2011-06-18 15:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-18 15:46 Petteri Räty [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-07-18 7:41 [gentoo-commits] proj/council-webapp:master commit in: bot/tests/, bot/ircmeeting/ Petteri Räty
2011-06-25 11:55 Petteri Räty
2011-06-25 11:55 Petteri Räty
2011-06-22 7:59 Petteri Räty
2011-06-22 7:59 Petteri Räty
2011-06-18 15:46 Petteri Räty
2011-06-18 15:46 Petteri Räty
2011-06-18 15:46 Petteri Räty
2011-06-18 15:46 Petteri Räty
2011-06-18 15:46 Petteri Räty
2011-06-05 20:37 Petteri Räty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d7fcb9289fb9403db1c646b4205117d1ba66acfe.betelgeuse@gentoo \
--to=betelgeuse@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox