def on_msg(con, event): if event.target() not in targets: return author, rest = event.source().split('!') if author in authormap: author = authormap[author] line = event.arguments()[0] if line.startswith("!log "): undef, message = line.split(" ", 1) try: adminlog.log(message, author) if author in titlemap: title = titlemap[author] else: title = "Master" server.privmsg(event.target(), "Logged the message, %s" % title) except: print sys.exc_info()
def on_pubmsg(self, con, event): if event.target not in self.config.targets: return author, rest = event.source.split('!') cloak = self.get_cloak(event.source) if author in self.config.author_map: author = self.config.author_map[author] line = event.arguments[0] if (line.startswith(self.config.nick) or line.startswith("!%s" % self.config.nick) or line.lower() == "!log help"): logging.debug("'%s' got '%s'; displaying help message." % (self.name, line)) try: self.connection.privmsg( event.target, "I am a logbot running on %s." % gethostname()) self.connection.privmsg( event.target, "Messages are logged to %s." % self.config.log_url) self.connection.privmsg(event.target, "To log a message, type !log <msg>.") except Exception: self.connection.privmsg(event.target, "To log a message, type !log <msg>.") elif line.lower().startswith("!log "): logging.debug("'%s' got '%s'; Attempting to log." % (self.name, line)) if self.config.check_users: try: cache_filename = '%s/%s-users_json.cache' %\ (self.config.cachedir, self.name) except AttributeError: cache_filename = '/var/lib/adminbot/%s-users_json.cache' %\ self.name cache_stale = self.is_stale(cache_filename) if cache_stale: user_json = '' user_json_cache_file = open(cache_filename, 'w+') if self.config.user_query: user_json = self.get_query(self.config.user_query) elif self.config.user_url: user_json = self.get_json_from_url( self.config.user_url) user_json_cache_file.write(json.dumps(user_json)) else: user_json_cache_file = open(cache_filename, 'r') user_json = user_json_cache_file.read() if user_json: user_json = json.loads(user_json) user_json_cache_file.close() username = self.find_user(author, cloak, user_json) if username: author = "[[" + username + "]]" else: if self.config.required_users_mode == "warn": self.connection.privmsg( event.target, "Not a trusted nick or cloak." " This is just a warning," " for now." " Please add your nick" " or cloak added" " to the trust list" " or your user page.") if self.config.required_users_mode == "error": self.connection.privmsg( event.target, "Not a trusted nick" " or cloak. Not logging." " Please add your nick" " or cloak added" " to the trust list" " or your user page.") return if self.config.enable_projects: arr = line.split(" ", 2) if len(arr) < 2: self.connection.privmsg( event.target, "Project not found, O.o. Try !log" " <project> <message> next time.") return if len(arr) < 3: self.connection.privmsg( event.target, "Message missing. Nothing logged.") return project = arr[1] projects = self.get_projects(event) if project not in projects: self.connection.privmsg( event.target, project + " is not a valid project.") return message = arr[2] else: arr = line.split(" ", 1) if len(arr) < 2: self.connection.privmsg( event.target, "Message missing. Nothing logged.") return project = "" message = arr[1] try: pageurl = adminlog.log(self.config, message, project, author) if author in self.config.title_map: title = self.config.title_map[author] else: title = "Master" self.connection.privmsg( event.target, "Logged the message at {url}, {author}".format( url=pageurl, author=title)) except Exception as e: logging.exception('Failed to log message: %r' % e) try: self.connection.privmsg( event.target(), "An exception was raised while trying to log " "your message, {author}".format(author=title)) except Exception: pass
return message = arr[2] else: arr = line.split(" ", 1) if len(arr) < 2: try: self.connection.privmsg(event.target(), "Message missing. Nothing logged.") except irclib.ServerNotConnectedError, e: logging.debug("Server connection error" " when sending message") return project = "" message = arr[1] try: adminlog.log(self.config, message, project, author) if author in self.config.title_map: title = self.config.title_map[author] else: title = "Master" try: self.connection.privmsg(event.target(), "Logged the message, %s" % title) except irclib.ServerNotConnectedError, e: logging.debug("Server connection error" " when sending message") except Exception: logging.exception('Failed to log message') parser = argparse.ArgumentParser(description='IRC log bot.',
def on_pubmsg(self, con, event): if event.target not in self.config.targets: return author, rest = event.source.split("!") cloak = self.get_cloak(event.source) if author in self.config.author_map: author = self.config.author_map[author] line = event.arguments[0].decode("utf8", "replace") if ( line.startswith(self.config.nick) or line.startswith("!%s" % self.config.nick) or line.lower() == "!log help" ): logging.debug("'%s' got '%s'; displaying help message." % (self.name, line)) try: self.connection.privmsg(event.target, "I am a logbot running on %s." % gethostname()) self.connection.privmsg(event.target, "Messages are logged to %s." % self.config.log_url) self.connection.privmsg(event.target, "To log a message, type !log <msg>.") except Exception: self.connection.privmsg(event.target, "To log a message, type !log <msg>.") elif line.lower().startswith("!log "): logging.debug("'%s' got '%s'; Attempting to log." % (self.name, line)) if self.config.check_users: try: cache_filename = "%s/%s-users_json.cache" % (self.config.cachedir, self.name) except AttributeError: cache_filename = "/var/lib/adminbot/%s-users_json.cache" % self.name cache_stale = self.is_stale(cache_filename) if cache_stale: user_json = "" user_json_cache_file = open(cache_filename, "w+") if self.config.user_query: user_json = self.get_query(self.config.user_query) elif self.config.user_url: user_json = self.get_json_from_url(self.config.user_url) user_json_cache_file.write(json.dumps(user_json)) else: user_json_cache_file = open(cache_filename, "r") user_json = user_json_cache_file.read() if user_json: user_json = json.loads(user_json) user_json_cache_file.close() username = self.find_user(author, cloak, user_json) if username: author = "[[" + username + "]]" else: if self.config.required_users_mode == "warn": self.connection.privmsg( event.target, "Not a trusted nick or cloak." " This is just a warning," " for now." " Please add your nick" " or cloak added" " to the trust list" " or your user page.", ) if self.config.required_users_mode == "error": self.connection.privmsg( event.target, "Not a trusted nick" " or cloak. Not logging." " Please add your nick" " or cloak added" " to the trust list" " or your user page.", ) return if self.config.enable_projects: arr = line.split(" ", 2) if len(arr) < 2: self.connection.privmsg( event.target, "Project not found, O.o. Try !log" " <project> <message> next time." ) return if len(arr) < 3: self.connection.privmsg(event.target, "Message missing. Nothing logged.") return project = arr[1] projects = self.get_projects(event) if project not in projects: self.connection.privmsg(event.target, project + " is not a valid project.") return message = arr[2] else: arr = line.split(" ", 1) if len(arr) < 2: self.connection.privmsg(event.target, "Message missing. Nothing logged.") return project = "" message = arr[1] try: pageurl = adminlog.log(self.config, message, project, author) if author in self.config.title_map: title = self.config.title_map[author] else: title = "Master" self.connection.privmsg( event.target, "Logged the message at {url}, {author}".format(url=pageurl, author=title) ) except Exception as e: logging.exception("Failed to log message: %r" % e) try: self.connection.privmsg( event.target(), "An exception was raised while trying to log " "your message, {author}".format(author=title), ) except Exception: pass
def on_pubmsg(self, con, event): if event.target() not in self.config.targets: return author, rest = event.source().split('!') cloak = self.get_cloak(event.source()) if author in self.config.author_map: author = self.config.author_map[author] line = event.arguments()[0].decode("utf8", "replace") if (line.startswith(self.config.nick) or line.startswith("!%s" % self.config.nick) or line.lower() == "!log help"): logging.debug("'%s' got '%s'; displaying help message." % (self.name, line)) try: self.connection.privmsg(event.target(), "Soy un logbot que corre en %s." % gethostname()) self.connection.privmsg(event.target(), "Los mensajes son registrados en %s." % self.config.log_url) self.connection.privmsg(event.target(), "Para registrar un mensaje coloca !log <msg>.") except Exception: try: self.connection.privmsg(event.target(), "Para registrar un mensaje coloca !log <msg>.") except irclib.ServerNotConnectedError: logging.debug("Server connection error " "when sending message") elif line.lower().startswith("!log "): logging.debug("'%s' got '%s'; Attempting to log." % (self.name, line)) if self.config.check_users: try: cache_filename = '%s/%s-users_json.cache' %\ (self.config.cachedir, self.name) except AttributeError: cache_filename = '/var/lib/adminbot/%s-users_json.cache' %\ self.name cache_stale = self.is_stale(cache_filename) if cache_stale: user_json = '' user_json_cache_file = open(cache_filename, 'w+') if self.config.user_query: user_json = self.get_query(self.config.user_query) elif self.config.user_url: user_json = self.get_json_from_url( self.config.user_url) user_json_cache_file.write(json.dumps(user_json)) else: user_json_cache_file = open(cache_filename, 'r') user_json = user_json_cache_file.read() if user_json: user_json = json.loads(user_json) user_json_cache_file.close() username = self.find_user(author, cloak, user_json) if username: author = "[[" + username + "]]" else: try: if self.config.required_users_mode == "warn": self.connection.privmsg(event.target(), "No es un usuario verificado." "Esto es solo una advertencia," "Por ahora." "Por favor añada su nick" "o su vhost" "a la lista blanca" "o su página de usuario") if self.config.required_users_mode == "error": self.connection.privmsg(event.target(), "No es un usuario" " o vhost verificado. No se registrará." " Por favor añada su nick" " o vhost" " a la lista blanca" " o su página de usuario") return except irclib.ServerNotConnectedError: logging.debug("Server connection error" " when sending message") if self.config.enable_projects: arr = line.split(" ", 2) try: if len(arr) < 2: self.connection.privmsg(event.target(), "Project not found, O.o. Try !log" " <project> <message> next time.") return if len(arr) < 3: self.connection.privmsg(event.target(), "El mensaje falta. No se registrará.") return except irclib.ServerNotConnectedError: logging.debug("Server connection error" " when sending message") project = arr[1] projects = self.get_projects(event) if project not in projects: try: self.connection.privmsg(event.target(), project + " is not a valid project.") except irclib.ServerNotConnectedError: logging.debug("Server connection error" " when sending message") return message = arr[2] else: arr = line.split(" ", 1) if len(arr) < 2: try: self.connection.privmsg(event.target(), "Message missing. Nothing logged.") except irclib.ServerNotConnectedError: logging.debug("Server connection error" " when sending message") return project = "" message = arr[1] try: pageurl = adminlog.log(self.config, message, project, author) if author in self.config.title_map: title = self.config.title_map[author] else: title = "Maestro" try: self.connection.privmsg(event.target(), "Registrado el mensaje en {url}, {author}".format( url=pageurl, author=title ) ) except irclib.ServerNotConnectedError, e: logging.debug("Server connection error" " when sending message: %r" % e) except Exception: logging.exception('Failed to log message')