summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorSean B. Palmer <http://inamidst.com/sbp/>2009-06-07 09:57:41 +0100
committerSean B. Palmer <http://inamidst.com/sbp/>2009-06-07 09:57:41 +0100
commitaafac55f7acfb8393e7ecde547f4df03804ae487 (patch)
treeadecc5db7235b62965177b2b8df40ce30c57937b /modules
parenta06ea9e4ba89db0163fa344754fad44eccc993ee (diff)
downloadbot-aafac55f7acfb8393e7ecde547f4df03804ae487.tar.gz
bot-aafac55f7acfb8393e7ecde547f4df03804ae487.tar.bz2
bot-aafac55f7acfb8393e7ecde547f4df03804ae487.zip
Added config option for specifying services to use.
Diffstat (limited to 'modules')
-rwxr-xr-xmodules/dict.py68
-rwxr-xr-xmodules/etymology.py12
-rwxr-xr-xmodules/oblique.py30
-rwxr-xr-xmodules/wiktionary.py2
4 files changed, 35 insertions, 77 deletions
diff --git a/modules/dict.py b/modules/dict.py
index df9025d..ac29a2e 100755
--- a/modules/dict.py
+++ b/modules/dict.py
@@ -11,79 +11,11 @@ import re, urllib
import web
from tools import deprecated
-formuri = 'http://wordnet.princeton.edu/perl/webwn?s='
-
r_li = re.compile(r'(?ims)<li>.*?</li>')
r_tag = re.compile(r'<[^>]+>')
r_parens = re.compile(r'(?<=\()(?:[^()]+|\([^)]+\))*(?=\))')
r_word = re.compile(r'^[A-Za-z0-9\' -]+$')
-@deprecated
-def f_wordnet(self, origin, match, args):
- """Gives the definition of a word using Wordnet."""
- command = 'w'
- term = match.group(2)
- term = term.encode('utf-8')
-
- if origin.sender != '#inamidst':
- if not r_word.match(term):
- msg = "Words must match the regexp %s" % r'^[A-Za-z0-9\' -]+$'
- return self.msg(origin.sender, origin.nick + ": " + msg)
- if ('--' in term) or ("''" in term) or (' ' in term):
- self.msg(origin.sender, origin.nick + ": That's not in WordNet.")
- return
-
- bytes = web.get(formuri + web.urllib.quote(term)) # @@ ugh!
- items = r_li.findall(bytes)
-
- nouns, verbs, adjectives = [], [], []
- for item in items:
- item = r_tag.sub('', item)
- chunks = r_parens.findall(item)
- # self.msg(origin.sender, item)
- if len(chunks) < 2: continue
-
- kind, defn = chunks[0], chunks[1]
- if command != 'wordnet':
- defn = defn.split(';')[0]
- if not defn: continue
- defn = defn[0].upper() + defn[1:]
-
- if kind == 'n':
- nouns.append(defn)
- elif kind == 'v':
- verbs.append(defn)
- elif kind == 'adj':
- adjectives.append(defn)
-
- if not (nouns or verbs or adjectives):
- self.msg(origin.sender, "I couldn't find '%s' in WordNet." % term)
- return
-
- while len(nouns + verbs + adjectives) > 3:
- if len(nouns) >= len(verbs) and len(nouns) >= len(adjectives):
- nouns.pop()
- elif len(verbs) >= len(nouns) and len(verbs) >= len(adjectives):
- verbs.pop()
- elif len(adjectives) >= len(nouns) and len(adjectives) >= len(verbs):
- adjectives.pop()
-
- if adjectives:
- adjectives[-1] = adjectives[-1] + '.'
- elif verbs:
- verbs[-1] = verbs[-1] + '.'
- elif nouns:
- nouns[-1] = nouns[-1] + '.'
-
- for (i, defn) in enumerate(nouns):
- self.msg(origin.sender, '%s n. %r: %s' % (term, i+1, defn))
- for (i, defn) in enumerate(verbs):
- self.msg(origin.sender, '%s v. %r: %s' % (term, i+1, defn))
- for (i, defn) in enumerate(adjectives):
- self.msg(origin.sender, '%s a. %r: %s' % (term, i+1, defn))
-f_wordnet.commands = ['wordnet']
-f_wordnet.priority = 'low'
-
uri = 'http://encarta.msn.com/dictionary_/%s.html'
r_info = re.compile(
r'(?:ResultBody"><br /><br />(.*?)&nbsp;)|(?:<b>(.*?)</b>)'
diff --git a/modules/etymology.py b/modules/etymology.py
index 12da548..30257f2 100755
--- a/modules/etymology.py
+++ b/modules/etymology.py
@@ -22,7 +22,7 @@ abbrs = [
'cf', 'lit', 'etc', 'Ger', 'Du', 'Skt', 'Rus', 'Eng', 'Amer.Eng', 'Sp',
'Fr', 'N', 'E', 'S', 'W', 'L', 'Gen', 'J.C', 'dial', 'Gk',
'19c', '18c', '17c', '16c', 'St', 'Capt', 'obs', 'Jan', 'Feb', 'Mar',
- 'Apr', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'c', 'tr'
+ 'Apr', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'c', 'tr', 'e', 'g'
]
t_sentence = r'^.*?(?<!%s)(?:\.(?= [A-Z0-9]|\Z)|\Z)'
r_sentence = re.compile(t_sentence % ')(?<!'.join(abbrs))
@@ -82,19 +82,17 @@ def f_etymology(self, origin, match, args):
msg = "Can't connect to etymonline.com (%s)" % (etyuri % word)
self.msg(origin.sender, msg)
return
+ except AttributeError:
+ result = None
if result is not None:
- if (origin.sender == '#esp') and (origin.nick == 'nsh'):
- self.msg(origin.nick, result)
- note = 'nsh: see privmsg (yes, this only happens for you)'
- self.msg(origin.sender, note)
- else: self.msg(origin.sender, result)
+ self.msg(origin.sender, result)
else:
uri = etysearch % word
msg = 'Can\'t find the etymology for "%s". Try %s' % (word, uri)
self.msg(origin.sender, msg)
# @@ Cf. http://swhack.com/logs/2006-01-04#T01-50-22
-f_etymology.rule = (['ety'], r"([A-Za-z0-9' .-]+)")
+f_etymology.rule = (['ety'], r"([A-Za-z0-9' .-]+)$")
f_etymology.thread = True
f_etymology.priority = 'high'
diff --git a/modules/oblique.py b/modules/oblique.py
index da07d7b..56ab638 100755
--- a/modules/oblique.py
+++ b/modules/oblique.py
@@ -23,6 +23,7 @@ def mappings(uri):
if not ' ' in item: continue
command, template = item.split(' ', 1)
+ if not command.isalpha(): continue
if not template.startswith('http://'): continue
result[command] = template.replace('&amp;', '&')
return result
@@ -57,6 +58,19 @@ def o(phenny, input):
msg = o.services.get(args, 'No such service!')
return phenny.reply(msg)
+ if not o.services.has_key(command):
+ return phenny.reply('Sorry, no such service. See %s' % services)
+
+ if hasattr(phenny.config, 'external'):
+ default = phenny.config.external.get('*')
+ manifest = phenny.config.external.get(input.sender, default)
+ if manifest:
+ commands = set(manifest)
+ if (command not in commands) and (manifest[0] != '!'):
+ 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')))
@@ -68,10 +82,24 @@ def o(phenny, input):
if lines:
phenny.say(lines[0][:350])
else: phenny.reply('Sorry, the service is broken.')
- else: phenny.reply('Sorry, no such service. See %s' % services)
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])
+py.commands = ['py']
+
if __name__ == '__main__':
print __doc__.strip()
diff --git a/modules/wiktionary.py b/modules/wiktionary.py
index ede60d0..c8f665e 100755
--- a/modules/wiktionary.py
+++ b/modules/wiktionary.py
@@ -23,7 +23,7 @@ def text(html):
return text
def wiktionary(word):
- bytes = web.get(uri % word)
+ bytes = web.get(uri % web.urllib.quote(word.encode('utf-8')))
bytes = r_ul.sub('', bytes)
mode = None