Slightly cleaner oblique.py

master
Sean B. Palmer 2009-06-07 10:05:37 +01:00
parent aafac55f7a
commit 77ad158b1e
1 changed files with 14 additions and 24 deletions

View File

@ -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__':