master
commit
20a8d88b86
3
bot.py
3
bot.py
|
@ -40,7 +40,6 @@ class Phenny(irc.Bot):
|
||||||
else:
|
else:
|
||||||
for fn in self.config.enable:
|
for fn in self.config.enable:
|
||||||
filenames.append(os.path.join(home, 'modules', fn + '.py'))
|
filenames.append(os.path.join(home, 'modules', fn + '.py'))
|
||||||
# @@ exclude
|
|
||||||
|
|
||||||
if hasattr(self.config, 'extra'):
|
if hasattr(self.config, 'extra'):
|
||||||
for fn in self.config.extra:
|
for fn in self.config.extra:
|
||||||
|
@ -52,8 +51,10 @@ class Phenny(irc.Bot):
|
||||||
filenames.append(os.path.join(fn, n))
|
filenames.append(os.path.join(fn, n))
|
||||||
|
|
||||||
modules = []
|
modules = []
|
||||||
|
excluded_modules = getattr(self.config, 'exclude', [])
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
name = os.path.basename(filename)[:-3]
|
name = os.path.basename(filename)[:-3]
|
||||||
|
if name in excluded_modules: continue
|
||||||
try: module = imp.load_source(name, filename)
|
try: module = imp.load_source(name, filename)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print >> sys.stderr, "Error loading %s: %s (in bot.py)" % (name, e)
|
print >> sys.stderr, "Error loading %s: %s (in bot.py)" % (name, e)
|
||||||
|
|
|
@ -47,6 +47,7 @@ def f_reload(phenny, input):
|
||||||
f_reload.name = 'reload'
|
f_reload.name = 'reload'
|
||||||
f_reload.rule = ('$nick', ['reload'], r'(\S+)?')
|
f_reload.rule = ('$nick', ['reload'], r'(\S+)?')
|
||||||
f_reload.priority = 'low'
|
f_reload.priority = 'low'
|
||||||
|
f_reload.thread = False
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print __doc__.strip()
|
print __doc__.strip()
|
||||||
|
|
|
@ -86,5 +86,31 @@ def gcs(phenny, input):
|
||||||
phenny.say(reply)
|
phenny.say(reply)
|
||||||
gcs.commands = ['gcs', 'comp']
|
gcs.commands = ['gcs', 'comp']
|
||||||
|
|
||||||
|
r_bing = re.compile(r'<h3><a href="([^"]+)"')
|
||||||
|
|
||||||
|
def bing(phenny, input):
|
||||||
|
"""Queries Bing for the specified input."""
|
||||||
|
query = input.group(2)
|
||||||
|
if query.startswith(':'):
|
||||||
|
lang, query = query.split(' ', 1)
|
||||||
|
lang = lang[1:]
|
||||||
|
else: lang = 'en-GB'
|
||||||
|
if not query:
|
||||||
|
return phenny.reply('.bing what?')
|
||||||
|
|
||||||
|
query = web.urllib.quote(query.encode('utf-8'))
|
||||||
|
base = 'http://www.bing.com/search?mkt=%s&q=' % lang
|
||||||
|
bytes = web.get(base + query)
|
||||||
|
m = r_bing.search(bytes)
|
||||||
|
if m:
|
||||||
|
uri = m.group(1)
|
||||||
|
phenny.reply(uri)
|
||||||
|
if not hasattr(phenny.bot, 'last_seen_uri'):
|
||||||
|
phenny.bot.last_seen_uri = {}
|
||||||
|
phenny.bot.last_seen_uri[input.sender] = uri
|
||||||
|
else: phenny.reply("No results found for '%s'." % query)
|
||||||
|
bing.commands = ['bing']
|
||||||
|
bing.example = '.bing swhack'
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print __doc__.strip()
|
print __doc__.strip()
|
||||||
|
|
2
phenny
2
phenny
|
@ -50,7 +50,7 @@ def create_default_config(fn):
|
||||||
external = {
|
external = {
|
||||||
'#liberal': ['!'], # allow all
|
'#liberal': ['!'], # allow all
|
||||||
'#conservative': [], # allow none
|
'#conservative': [], # allow none
|
||||||
'*': ['py', 'whois', 'glyph'] # default whitelist
|
'*': ['!'] # default whitelist, allow all
|
||||||
}
|
}
|
||||||
|
|
||||||
# EOF
|
# EOF
|
||||||
|
|
Loading…
Reference in New Issue