tidy cloudbot3/refresh code!

This commit is contained in:
Luke Rogers 2014-03-06 14:15:04 +13:00
parent f81cf21b57
commit 99e363cc99
12 changed files with 66 additions and 53 deletions

View file

@ -21,6 +21,7 @@ class Config(dict):
# start watcher
self.watcher()
def load_config(self):
"""(re)loads the bot config from the config file"""
if not os.path.exists(self.path):
@ -41,13 +42,11 @@ class Config(dict):
for conn in self.bot.connections:
conn.permissions.reload()
def save_config(self):
"""saves the contents of the config dict to the config file"""
json.dump(self, open(self.path, 'w'), sort_keys=True, indent=2)
self.logger.info("Config saved to file.")
def watcher(self):
"""starts the watchdog to automatically reload the config when it changes on disk"""
self.observer = Observer()

View file

@ -73,7 +73,7 @@ class PluginLoader(object):
# remove plugins already loaded from this file
for name, data in self.bot.plugins.items():
self.bot.plugins[name] = [x for x in data
if x[0]._filename != filename]
if x[0]._filename != filename]
# stop all currently running instances of the plugins from this file
for func, handler in list(self.bot.threads.items()):
@ -88,16 +88,15 @@ class PluginLoader(object):
if obj._thread:
self.bot.threads[obj] = main.Handler(self.bot, obj)
for type, data in obj._hook:
for plug_type, data in obj._hook:
# add plugin to the plugin list
self.bot.plugins[type] += [data]
self.bot.logger.info("Loaded plugin: {} ({})".format(format_plug(data), type))
self.bot.plugins[plug_type] += [data]
self.bot.logger.info("Loaded plugin: {} ({})".format(format_plug(data), plug_type))
# do a rebuild, unless the bot is loading all plugins (rebuild happens after load_all)
if not rebuild:
self.rebuild()
def unload_file(self, path):
"""unloads all loaded plugins from a specified file"""
filename = os.path.basename(path)

View file

@ -126,7 +126,7 @@ class Handler(object):
if uses_db:
# self.bot.logger.debug("Opened ST DB session for: {}".format(self.func._filename))
input.db = input.bot.db_session()
input.db = input.bot.db_session()
try:
run(self.bot, self.func, input)

View file

@ -1,5 +1,6 @@
from fnmatch import fnmatch
class PermissionManager(object):
def __init__(self, bot, conn):
@ -13,7 +14,6 @@ class PermissionManager(object):
self.conn = conn
self.config = conn.config
self.group_perms = {}
self.group_users = {}
self.perm_users = {}