summaryrefslogtreecommitdiffstats
path: root/bot.py
diff options
context:
space:
mode:
authorSean B. Palmer <http://inamidst.com/sbp/>2008-02-23 12:16:43 +0000
committerSean B. Palmer <http://inamidst.com/sbp/>2008-02-23 12:16:43 +0000
commit2fb00589439a4efb3906d4e681e7ed815dcd180a (patch)
tree0a6b0ff1a4b5697fc7c3cb0aa3dc934246fcb874 /bot.py
parent7931fab14599b739c18c8f1ebcc24b75688dbc09 (diff)
downloadbot-2fb00589439a4efb3906d4e681e7ed815dcd180a.tar.gz
bot-2fb00589439a4efb3906d4e681e7ed815dcd180a.tar.bz2
bot-2fb00589439a4efb3906d4e681e7ed815dcd180a.zip
Lots of fixes, changes, and new goodies.
Diffstat (limited to 'bot.py')
-rwxr-xr-xbot.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/bot.py b/bot.py
index d84a635..4c27b7d 100755
--- a/bot.py
+++ b/bot.py
@@ -7,7 +7,7 @@ Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
"""
-import sys, os, re, time, threading, optparse
+import sys, os, re, threading, imp
import irc
home = os.getcwd()
@@ -31,20 +31,29 @@ class Phenny(irc.Bot):
def setup(self):
self.variables = {}
+ filenames = []
if not hasattr(self.config, 'enable'):
- load = [('modules', filename[:-3])
- for filename in os.listdir(os.path.join(home, 'modules'))
- if filename.endswith('.py') and
- not filename.startswith('_') and
- not filename[:-3] in self.config.disable]
- else: load = [('modules', e) for e in self.config.enable]
-
- if hasattr(self.config, 'opt'):
- load += [('opt', o) for o in self.config.opt]
+ for fn in os.listdir(os.path.join(home, 'modules')):
+ if fn.endswith('.py') and not fn.startswith('_'):
+ filenames.append(os.path.join(home, 'modules', fn))
+ else:
+ for fn in self.config.enable:
+ filenames.append(os.path.join(home, 'modules', fn + '.py'))
+ # @@ exclude
+
+ if hasattr(self.config, 'extra'):
+ for fn in self.config.extra:
+ if os.path.isfile(fn):
+ filenames.append(fn)
+ elif os.path.isdir(fn):
+ for n in os.listdir(fn):
+ if n.endswith('.py') and not n.startswith('_'):
+ filenames.append(os.path.join(fn, n))
modules = []
- for package, name in load:
- try: module = getattr(__import__(package + '.' + name), name)
+ for filename in filenames:
+ name = os.path.basename(filename)[:-3]
+ try: module = imp.load_source(name, filename)
except Exception, e:
print >> sys.stderr, "Error loading %s: %s" % (name, e)
else: