def getService(options): # noqa: N802 observer = log.PythonLoggingObserver(loggerName="") observer.start() # Set up the config config._initialize() # Set the default logging level so we can already log messages logging.getLogger("").setLevel(logging.INFO) # Set up logging handler = logging.FileHandler(filename=config._get("base", "log_file"), encoding="utf-8") if options["verbose"] or config._CFG.getboolean("base", "debug"): logging.getLogger("").setLevel(logging.DEBUG) handler.setFormatter(logging.Formatter( "%(asctime)s %(levelname)s %(filename)s: %(funcName)s:%(lineno)d" " %(message)s")) else: handler.setFormatter(logging.Formatter("%(message)s")) logging.getLogger("").addHandler(handler) f = LalaFactory(config._get("base", "channels"), config._get("base", "nick")) return internet.TCPClient(config._get("base", "server"), int(config._get("base", "port")), f)
def __init__(self, channel, nickname): self.channel = channel self.nickname = nickname try: self.nspassword = config._get("base", "nickserv_password") except Exception: self.nspassword = None lala.pluginmanager.setup()
def noticed(self, user, channel, message): """ Same as :py:meth:`lala.bot.Lala.privmsg` for NOTICEs.""" user = user.split("!")[0] try: message = message.decode("utf-8") except Exception: message = message.decode(config._get("base", "fallback_encoding")) logging.info("NOTICE: %s: %s" % (user, message))
def privmsg(self, user, channel, message): """ Handles received messages.""" user = user.split("!")[0] if channel == self.nickname: # This is true if the bot was queried channel = user try: message = message.decode("utf-8") except Exception: message = message.decode(config._get("base", "fallback_encoding")) logging.debug("%s: %s" % (user, message)) lala.pluginmanager._handle_message(user, channel, message)
def __init__(self, channel, nickname, plugins, logger): self.channel = channel self.nickname = nickname self.logger = logger util._PM = pluginmanager.PluginManager("plugins") try: self.nspassword = config._get("base", "nickserv_password") except Exception: self.nspassword = None for plugin in plugins: util._PM.load_plugin(plugin) util._PM.load_plugin("base")
def getService(options): # noqa: N802 observer = log.PythonLoggingObserver(loggerName="") observer.start() # Set up the config cfg = ConfigParser.RawConfigParser(CONFIG_DEFAULTS) try: configfile = os.path.join(os.getenv("XDG_CONFIG_HOME"), "lala", "config") except AttributeError: configfile = os.path.join(os.getenv("HOME"), ".lala", "config") files = cfg.read([configfile, "/etc/lala.config"]) config._CFG = cfg config._FILENAME = files[0] # Set the default logging level so we can already log messages logging.getLogger("").setLevel(logging.INFO) logging.info("Read config files %s", files) logging.info("Using %s to save setting", files[0]) # Set up logging handler = logging.FileHandler(filename=config._get("base", "log_file"), encoding="utf-8") if options["verbose"] or cfg.getboolean("base", "debug"): logging.getLogger("").setLevel(logging.DEBUG) handler.setFormatter(logging.Formatter( "%(asctime)s %(levelname)s %(filename)s: %(funcName)s:%(lineno)d" " %(message)s")) else: handler.setFormatter(logging.Formatter("%(message)s")) logging.getLogger("").addHandler(handler) f = LalaFactory(cfg.get("base", "channels"), cfg.get("base", "nick")) return internet.TCPClient(cfg.get("base", "server"), int(cfg.get("base", "port")), f)
def _list_of_admins(): return config._get("base", "admins").split(config._LIST_SEPARATOR)