80uy79gfiy
This commit is contained in:
parent
5f6c280ba2
commit
1b1d3da823
3 changed files with 7 additions and 4 deletions
|
@ -13,6 +13,7 @@ def clean_name(n):
|
||||||
"""strip all spaces and capitalization"""
|
"""strip all spaces and capitalization"""
|
||||||
return re.sub('[^A-Za-z0-9_]+', '', n.replace(" ", "_"))
|
return re.sub('[^A-Za-z0-9_]+', '', n.replace(" ", "_"))
|
||||||
|
|
||||||
|
|
||||||
def get_logger():
|
def get_logger():
|
||||||
"""create and return a new logger object"""
|
"""create and return a new logger object"""
|
||||||
# create logger
|
# create logger
|
||||||
|
@ -41,7 +42,6 @@ def get_logger():
|
||||||
|
|
||||||
|
|
||||||
class Bot(object):
|
class Bot(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# basic variables
|
# basic variables
|
||||||
self.start_time = time.time()
|
self.start_time = time.time()
|
||||||
|
@ -146,4 +146,3 @@ class Bot(object):
|
||||||
self.logger.debug("Logging engine stopped")
|
self.logger.debug("Logging engine stopped")
|
||||||
logging.shutdown()
|
logging.shutdown()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ class SendThread(threading.Thread):
|
||||||
def run(self):
|
def run(self):
|
||||||
while not self.shutdown:
|
while not self.shutdown:
|
||||||
line = self.output_queue.get().splitlines()[0][:500]
|
line = self.output_queue.get().splitlines()[0][:500]
|
||||||
print u"[{}]: {}".format(self.conn_name, line)
|
print u"{}>>> {}".format(self.conn_name, line)
|
||||||
self.output_buffer += line.encode('utf-8', 'replace') + '\r\n'
|
self.output_buffer += line.encode('utf-8', 'replace') + '\r\n'
|
||||||
while self.output_buffer:
|
while self.output_buffer:
|
||||||
sent = self.socket.send(self.output_buffer)
|
sent = self.socket.send(self.output_buffer)
|
||||||
|
|
|
@ -58,6 +58,7 @@ class PluginLoader(object):
|
||||||
"""loads (or reloads) all valid plugins from a specified file"""
|
"""loads (or reloads) all valid plugins from a specified file"""
|
||||||
filename = os.path.basename(path)
|
filename = os.path.basename(path)
|
||||||
|
|
||||||
|
# compile the file and eval it in a namespace
|
||||||
try:
|
try:
|
||||||
code = compile(open(path, 'U').read(), filename, 'exec')
|
code = compile(open(path, 'U').read(), filename, 'exec')
|
||||||
namespace = {}
|
namespace = {}
|
||||||
|
@ -66,16 +67,19 @@ class PluginLoader(object):
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return
|
return
|
||||||
|
|
||||||
# remove plugins already loaded from this filename
|
# remove plugins already loaded from this file
|
||||||
for name, data in self.bot.plugins.iteritems():
|
for name, data in self.bot.plugins.iteritems():
|
||||||
self.bot.plugins[name] = [x for x in data
|
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.iteritems()):
|
for func, handler in list(self.bot.threads.iteritems()):
|
||||||
if func._filename == filename:
|
if func._filename == filename:
|
||||||
handler.stop()
|
handler.stop()
|
||||||
del self.bot.threads[func]
|
del self.bot.threads[func]
|
||||||
|
|
||||||
|
# find objects with hooks in the plugin namespace
|
||||||
|
# TODO: kill it with fire, kill it all
|
||||||
for obj in namespace.itervalues():
|
for obj in namespace.itervalues():
|
||||||
if hasattr(obj, '_hook'): # check for magic
|
if hasattr(obj, '_hook'): # check for magic
|
||||||
if obj._thread:
|
if obj._thread:
|
||||||
|
|
Reference in a new issue