Skip to content

Commit

Permalink
Slightly cleaner oblique.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean B. Palmer committed Jun 7, 2009
1 parent aafac55 commit 77ad158
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions modules/oblique.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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__':
Expand Down

0 comments on commit 77ad158

Please sign in to comment.