From a42348f4cac5ad97fccc9aaaf08243ff426ec546 Mon Sep 17 00:00:00 2001 From: kongr45gpen Date: Wed, 24 Jul 2013 17:58:38 +0300 Subject: Add support for plural forms --- plugin.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index 9a665b5..264c5d2 100644 --- a/plugin.py +++ b/plugin.py @@ -40,6 +40,10 @@ import supybot.ircmsgs as ircmsgs import supybot.ircutils as ircutils import supybot.callbacks as callbacks +def plural(number, s, p): + if number != 1: + return p + return s class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): @@ -61,8 +65,13 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): # print json.dumps(data, sort_keys=True, indent=4, separators=(',', ': ')) for irc in world.ircs: msgs = [] - #TODO: Plural - msgs.append( ircmsgs.privmsg("#main", "%s pushed %i %s, check them out" % (data['pusher']['name'], len(data['commits']), "commits")) ) + + commitno = len(data['commits']) + msgs.append( ircmsgs.privmsg("#main", "%s pushed %i %s, check them out" % + (data['pusher']['name'], + commitno, + plural(commitno, "commit", "commits"))) ) + msgs.append( ircmsgs.privmsg("#main", "%s" % (data['compare'])) ) for msg in msgs: irc.queueMsg(msg) -- cgit v1.2.3