diff options
author | Sean B. Palmer <http://inamidst.com/sbp/> | 2009-06-07 10:05:37 +0100 |
---|---|---|
committer | Sean B. Palmer <http://inamidst.com/sbp/> | 2009-06-07 10:05:37 +0100 |
commit | 77ad158b1e2bcd46ffc64b5ce3cfe414c56f4adb (patch) | |
tree | 67b07ecf21d7c5bff28a2f9003786b767417d21b /modules | |
parent | aafac55f7acfb8393e7ecde547f4df03804ae487 (diff) | |
download | bot-77ad158b1e2bcd46ffc64b5ce3cfe414c56f4adb.tar.gz bot-77ad158b1e2bcd46ffc64b5ce3cfe414c56f4adb.tar.bz2 bot-77ad158b1e2bcd46ffc64b5ce3cfe414c56f4adb.zip |
Slightly cleaner oblique.py
Diffstat (limited to 'modules')
-rwxr-xr-x | modules/oblique.py | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/modules/oblique.py b/modules/oblique.py index 56ab638..a378d87 100755 --- a/modules/oblique.py +++ b/modules/oblique.py @@ -28,6 +28,18 @@ def mappings(uri): result[command] = template.replace('&', '&') return result +def service(phenny, input, command, args): + t = o.services[command] + template = t.replace('${args}', urllib.quote(args.encode('utf-8'))) + template = template.replace('${nick}', urllib.quote(input.nick)) + uri = template.replace('${sender}', urllib.quote(input.sender)) + + bytes = web.get(uri) + lines = bytes.splitlines() + if not lines: + return phenny.reply('Sorry, the service is broken.') + phenny.say(lines[0][:350]) + def o(phenny, input): """Call a webservice.""" text = input.group(2) @@ -70,35 +82,13 @@ def o(phenny, input): return phenny.reply('Sorry, %s is not whitelisted' % command) elif (command in commands) and (manifest[0] == '!'): return phenny.reply('Sorry, %s is blacklisted' % command) - - if o.services.has_key(command): - t = o.services[command] - template = t.replace('${args}', urllib.quote(args.encode('utf-8'))) - template = template.replace('${nick}', urllib.quote(input.nick)) - uri = template.replace('${sender}', urllib.quote(input.sender)) - - bytes = web.get(uri) - lines = bytes.splitlines() - if lines: - phenny.say(lines[0][:350]) - else: phenny.reply('Sorry, the service is broken.') + service(phenny, input, command, args) o.commands = ['o'] o.example = '.o servicename arg1 arg2 arg3' o.services = {} def py(phenny, input): - command = 'py' - args = input.group(2) - if o.services.has_key(command): - t = o.services[command] - template = t.replace('${args}', urllib.quote(args.encode('utf-8'))) - template = template.replace('${nick}', urllib.quote(input.nick)) - uri = template.replace('${sender}', urllib.quote(input.sender)) - - bytes = web.get(uri) - lines = bytes.splitlines() - if lines: - phenny.say(lines[0][:350]) + service(phenny, input, 'py', input.group(2)) py.commands = ['py'] if __name__ == '__main__': |