diff options
author | kongr45gpen <kongr45gpen@helit.org> | 2013-07-24 17:38:20 +0300 |
---|---|---|
committer | kongr45gpen <kongr45gpen@helit.org> | 2013-07-24 17:38:20 +0300 |
commit | 9f6be16bd5ec2e15c8bab3d3b567d9ca90d88975 (patch) | |
tree | 238f07506c1c404e54eff820136fd624e201e1b2 /plugin.py | |
parent | d3fcff8289f75e0c8751fa472c6755e128991e51 (diff) | |
download | supybot_github-9f6be16bd5ec2e15c8bab3d3b567d9ca90d88975.tar.gz supybot_github-9f6be16bd5ec2e15c8bab3d3b567d9ca90d88975.tar.bz2 supybot_github-9f6be16bd5ec2e15c8bab3d3b567d9ca90d88975.zip |
Make the plugin useful
Show information about commits on IRC
Apply fix so that github hooks are supported
Diffstat (limited to 'plugin.py')
-rw-r--r-- | plugin.py | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -28,6 +28,7 @@ import random import json import time +import urlparse import threading import BaseHTTPServer @@ -46,7 +47,8 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): """Respond to a POST request.""" length = int(s.headers['Content-Length']) - data = json.loads(s.rfile.read(length).decode('utf-8')) + post_data = urlparse.parse_qs(s.rfile.read(length).decode('utf-8')) + data = json.loads(post_data['payload'][0]) s.send_response(200) s.send_header('Content-type', 'text/html') @@ -58,8 +60,12 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): s.wfile.write(vars(s)) # print json.dumps(data, sort_keys=True, indent=4, separators=(',', ': ')) for irc in world.ircs: - msg = ircmsgs.privmsg("#main", "Someone committed something, check it out") - irc.queueMsg(msg) + msgs = [] + #TODO: Plural + msgs.append( ircmsgs.privmsg("#main", "%s pushed %i %s, check them out" % (data['pusher']['name'], len(data['commits']), "commits")) ) + msgs.append( ircmsgs.privmsg("#main", "%s" % (data['compare'])) ) + for msg in msgs: + irc.queueMsg(msg) class Github(callbacks.Plugin): @@ -69,7 +75,7 @@ class Github(callbacks.Plugin): threaded = True pass - def ServerStart(self, httpd, irc): + def ServerStart(self, httpd): try: print time.asctime(), 'Server Starts - %s:%s' % ('', 8093) httpd.serve_forever() @@ -83,7 +89,7 @@ class Github(callbacks.Plugin): self.rng.seed() # automatically seeds with current time server_class = BaseHTTPServer.HTTPServer self.httpd = server_class(('', 8093), GithubHandler) - t = threading.Thread(target=self.ServerStart, args=(self.httpd)) + t = threading.Thread(target=self.ServerStart, args=(self.httpd,)) t.daemon = False t.start() |