Permalink
Browse files

initial import

  • Loading branch information...
0 parents commit df02500c5d155eda8473507ef94cdec79aeb28e7 @richo richo committed Sep 24, 2011
Showing with 2,120 additions and 0 deletions.
  1. +17 −0 TODO
  2. +53 −0 auth.py
  3. +70 −0 config.py
  4. +579 −0 ircSocket.py
  5. +17 −0 lib.py
  6. +44 −0 logging.py
  7. +5 −0 module_config.py
  8. +202 −0 modules.d/000_core.py
  9. +228 −0 modules.d/core_modules.py
  10. +8 −0 modules.d/debug.py
  11. +107 −0 modules.d/extras.py
  12. +15 −0 modules.d/join.py
  13. +5 −0 modules.d/mode.py
  14. +7 −0 modules.d/prod.py
  15. 0 modules.local.d/.gitinclude
  16. +457 −0 mpd.py
  17. +56 −0 ourgit.py
  18. +10 −0 pyBawt.conf.sample
  19. +91 −0 pyBawt.py
  20. +16 −0 pyBawt.sh
  21. +37 −0 regen_modules.py
  22. +7 −0 start.sh
  23. +10 −0 test/radio.py
  24. +27 −0 test/unit/helpers.py
  25. +24 −0 test/unit/test_lib.py
  26. +3 −0 update_radio.sh
  27. +25 −0 webutils.py
@@ -0,0 +1,17 @@
+This code will become the new trunk soon.
+
+I see no reason to maintain the legacy crap.
+
+TODO
+----
+
+Flesh out the API to let it do everything
+
+More verbose admin commands
+
+Handler for adding modules to other channels
+
+Handler for telling the bot what to do
+
+BUG: python2.6 won't create an args module which breaks the auto restart code
+
@@ -0,0 +1,53 @@
+import hashlib
+import pickle
+import atexit
+import logging
+from lib import *
+
+AUTH_FILE_NAME="authen.db"
+
+class Authenticator(object):
+ """\
+An object that statefully keeps track of all authentication
+It is managed by AuthModule which tracks the server messages
+ """
+ def __init__(self, auth_hash='', valid_host=''):
+ self.auth_hash = auth_hash
+ self.valid_host = valid_host
+ self.authenticated = LowerList()
+ self.load()
+ atexit.register(self.save)
+
+ def try_auth(self, msg, password):
+ if msg.nick in self.authenticated:
+ return True
+ # Max kludge per user password
+ if hashlib.md5(password).hexdigest() == self.auth_hash:
+ self.authenticated.append(msg.nick)
+ return True
+ return False
+
+ def revoke_auth(self, nick):
+ count = 0
+ try:
+ while True:
+ self.authenticated.remove(nick)
+ count+=1
+ except ValueError:
+ return count > 0
+
+ def authed(self, msg):
+ return msg.nick in self.authenticated
+
+ def save(self):
+ pickle.dump(self.auth_data, open(AUTH_FILE_NAME, 'w'))
+ def load(self):
+ try:
+ fh = open(AUTH_FILE_NAME, 'r')
+ self.auth_data = pickle.load(fh)
+ except IOError:
+ self.auth_data = {}
+
+ # TODO
+ # Authentication decorator
+
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+"""A module wrapper around the config files for pyBawt"""
+__all__ = []
+
+# This is tremendous hax, just a piece of scaffold to avoid breaking the old
+# API
+# Also, bail the fuck out if the config is incomplete
+
+import logging
+import os
+
+class InvalidConfig(Exception):
+ pass
+class NoConfigFile(Exception):
+ pass
+
+
+CONFIG_FILE = 'pyBawt.conf'
+logging.info("Commencing config read from %s" % (os.path.join(os.getcwd(), CONFIG_FILE)))
+config = {}
+boolvalues = { 'true' : True,
+ '1' : True,
+ 'yes' : True,
+ 'false': False,
+ '0' : False,
+ 'no' : False }
+def to_bool(val):
+ return boolvalues[val.lower()]
+def to_list(val):
+ return list(map(lambda x: x.strip(), val.split(',')))
+def passthru(val):
+ return val
+# A tuple of tuples with a key and an transformer
+keys = (('host', passthru),
+ ('ssl' , to_bool),
+ ('nick', passthru),
+ ('port', int),
+ ('auth_host', passthru),
+ ('auth_hash', passthru),
+ ('channels' , to_list),
+ ('nickserv_nick', passthru),
+ ('nickserv_pass', passthru)
+ )
+
+with open(CONFIG_FILE) as fh:
+ for line in fh:
+ line = line.strip()
+ if line.startswith("#"):
+ # Ignore comments
+ continue
+ if not line:
+ continue
+ try:
+ key, value = map(lambda x: x.strip(),line.split('=', 1))
+ config[key] = value
+ except ValueError:
+ raise InvalidConfig, "Invalid key value pair at (FIXME Lineno)"
+if not config:
+ logging.error("Couldn't open config file")
+ raise NoConfigFile
+ # FIXME distinguish between not there and inaccessible
+for name, transformer in keys:
+ __all__.append(name)
+ try:
+ # This is fucked XXX FIXME
+ #__dict__[name] = transformer(config[name])
+ exec('%s = %s' % (name, repr(transformer(config[name]))))
+
+ except ValueError: #Probably port didn't translate
+ raise InvalidConfig
Oops, something went wrong.

0 comments on commit df02500

Please sign in to comment.