From fdf685161eb2d24705f285bce67101b31badee69 Mon Sep 17 00:00:00 2001 From: Ryan Hitchman Date: Thu, 17 Jun 2010 21:55:42 -0600 Subject: [PATCH] add .o/.oblique command running, see http://github.com/nslater/oblique for more information --- plugins/oblique.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 plugins/oblique.py diff --git a/plugins/oblique.py b/plugins/oblique.py new file mode 100644 index 0000000..a39b91f --- /dev/null +++ b/plugins/oblique.py @@ -0,0 +1,57 @@ +import time + +from util import hook, http + + +commands_modtime = 0 +commands = {} + + +def update_commands(force=False): + global commands_modtime, commands + + if force or time.time() - commands_modtime > 60 * 60: # update hourly + h = http.get_html('http://wiki.github.com/nslater/oblique/') + + lines = h.xpath('//li/text()') + commands = {} + for line in lines: + if not line.strip(): + continue + + name, url = line.strip().split(None, 1) + commands[name] = url + + commands_modtime = time.time() + + +@hook.command('o') +@hook.command +def oblique(inp, nick='', chan=''): + '.o/.oblique -- runs using oblique web' + ' services. see http://wiki.github.com/nslater/oblique/' + + update_commands() + + if ' ' in inp: + command, args = inp.split(None, 1) + else: + command = inp + args = '' + + command = command.lower() + + if command == 'refresh': + update_commands(True) + return '%d commands loaded.' % len(commands) + if command in commands: + url = commands[command] + url = url.replace('${nick}', nick) + url = url.replace('${sender}', chan) + url = url.replace('${args}', http.quote(args.encode('utf8'))) + try: + return http.get(url) + except http.HTTPError, e: + return "http error %d" % e.code + else: + return 'no such service'