def init(config, _db, _ch): global db, ch, spam_scores, blacklist_contact, enable_signing db = _db ch = _ch spam_scores = ScoreKeeper() blacklist_contact = config.get("blacklist_contact", "") enable_signing = config["enable_signing"] # initialize db if empty if db.getSystemConfig() is None: c = SystemConfig() c.defaults() db.setSystemConfig(c)
def main(configpath, importpath): with open(configpath, "r") as f: config = yaml.load(f) logging.basicConfig( format="[%(asctime)s] %(message)s", datefmt="%Y-%m-%d %H:%M", level=logging.INFO ) db = open_db(config) with open(importpath, "r") as f: data = json.load(f) had_ids = set() for j in data["users"]: u = User() u.id = j["id"] u.username = j.get("username", None) u.realname = j.get("realname", "") u.rank = j["rank"] u.joined = safe_time(0) if j.get("left", False) != False: u.left = safe_time(j["left"] // 1000) u.lastActive = u.joined if "banned" in j.keys(): u.cooldownUntil = safe_time(j["banned"] // 1000) if "reason" in j.keys(): u.blacklistReason = j["reason"] u.warnings = j.get("warnings", 0) if u.warnings > 0: u.warnExpiry = safe_time(j["warnUpdated"] // 1000) + timedelta( hours=WARN_EXPIRE_HOURS ) u.karma = j.get("karma", 0) u.hideKarma = j.get("hideKarma", False) u.debugEnabled = j.get("debug", False) if u.id in had_ids: logging.warning("%s is duplicate, dropping the second one", u) else: db.addUser(u) had_ids.add(u.id) c = SystemConfig() c.motd = data["system"]["motd"] db.setSystemConfig(c) logging.info("Success.") db.close()
def init(config, _db, _ch): global db, ch, spam_scores, blacklist_contact, enable_signing, media_limit_period db = _db ch = _ch spam_scores = ScoreKeeper() blacklist_contact = config.get("blacklist_contact", "") enable_signing = config["enable_signing"] if "media_limit_period" in config.keys(): media_limit_period = timedelta(hours=int(config["media_limit_period"])) # initialize db if empty if db.getSystemConfig() is None: c = SystemConfig() c.defaults() db.setSystemConfig(c)
def init(config, _db, _ch): global db, ch, spam_scores, blacklist_contact, enable_signing, allow_remove_command, media_limit_period, sign_interval db = _db ch = _ch spam_scores = ScoreKeeper() blacklist_contact = config.get("blacklist_contact", "") enable_signing = config["enable_signing"] allow_remove_command = config["allow_remove_command"] if "media_limit_period" in config.keys(): media_limit_period = timedelta(hours=int(config["media_limit_period"])) sign_interval = timedelta(seconds=int(config.get("sign_limit_interval", 600))) # initialize db if empty if db.getSystemConfig() is None: c = SystemConfig() c.defaults() db.setSystemConfig(c)