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('&', '&') result[command] = template.replace('&', '&')
return result 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): def o(phenny, input):
"""Call a webservice.""" """Call a webservice."""
text = input.group(2) text = input.group(2)
@ -70,35 +82,13 @@ def o(phenny, input):
return phenny.reply('Sorry, %s is not whitelisted' % command) return phenny.reply('Sorry, %s is not whitelisted' % command)
elif (command in commands) and (manifest[0] == '!'): elif (command in commands) and (manifest[0] == '!'):
return phenny.reply('Sorry, %s is blacklisted' % command) return phenny.reply('Sorry, %s is blacklisted' % command)
service(phenny, input, command, args)
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.')
o.commands = ['o'] o.commands = ['o']
o.example = '.o servicename arg1 arg2 arg3' o.example = '.o servicename arg1 arg2 arg3'
o.services = {} o.services = {}
def py(phenny, input): def py(phenny, input):
command = 'py' service(phenny, input, 'py', input.group(2))
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])
py.commands = ['py'] py.commands = ['py']
if __name__ == '__main__': if __name__ == '__main__':