summaryrefslogtreecommitdiffstats
path: root/modules/oblique.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/oblique.py')
-rwxr-xr-xmodules/oblique.py38
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__':