예제 #1
0
def loadPlugin(name):
    global ircc
    package = "plugins.%s.main" % name
    if name in loadedPlugins:
        return "This plugin is already loaded!"
    elif os.path.exists("plugins/%s/main.py" % name):
        try:
            __import__(package)  # Loading to the memory the requested plugin

            loadedPlugins.append(name)
            if hasattr(sys.modules[package], "priv_%s" % name):
                coha.priv_insert(name)
            if hasattr(sys.modules[package], "pub_%s" % name):
                coha.pub_insert(name)
            if hasattr(sys.modules[package], "pubhandler_%s" % name):
                func = getattr(sys.modules[package], "pubhandler_%s" % name)
                coha.pubhandler_insert(func)
            if hasattr(sys.modules[package], "privhandler_%s" % name):
                funcp = getattr(sys.modules[package], "privhandler_%s" % name)
                coha.pubhandler_insert(funcp)
            if hasattr(sys.modules[package], "joinhandler_%s" % name):
                funcj = getattr(sys.modules[package], "joinhandler_%s" % name)
                ircc.add_global_handler("join", funcj)
            if hasattr(sys.modules[package], "pubadmin_%s" % name):
                ad.insertPubAdmin(name)
            if hasattr(sys.modules[package], "privadmin_%s" % name):
                ad.insertPrvAdmin(name)
            return "Done!"
        except Exception:  # Catching exceptions to avoid crashes...
            exc_type, exc_value, exc_traceback = sys.exc_info()
            traceback.print_exception(
                exc_type, exc_value, exc_traceback, file=sys.stdout
            )  # printing the exceptions without exit the program
            return "An error occurred please check the errors.log on logs directory"
    else:
        return "Cant find this plugin"
예제 #2
0
def add_help(cmd, wh):
    if wh == "pm":
        coha.priv_insert(cmd)
    if wh == "pub":
        coha.pub_insert(cmd)