def _collate_irc(s1, s2): # treat hostmasks specially, otherwise call irc_lower on stuff if "@" in s1: hl, hr = s1.split("@", 1) s1 = irc_lower(hl) + "@" + hr.lower() else: s1 = irc_lower(s1) if "@" in s2: hl, hr = s2.split("@", 1) l2 = irc_lower(hl) + "@" + hr.lower() else: s2 = irc_lower(s2) if s1 == s2: return 0 elif s1 < s2: return -1 else: return 1
def _collate_irc(s1, s2): # treat hostmasks specially, otherwise call irc_lower on stuff if "@" in s1: hl, hr = s1.split("@", 1) s1 = irc_lower(hl) + "@" + hr.lower() else: s1 = irc_lower(s1) if "@" in s2: hl, hr = s2.split("@", 1) s2 = irc_lower(hl) + "@" + hr.lower() else: s2 = irc_lower(s2) if s1 == s2: return 0 elif s1 < s2: return -1 else: return 1
def init_vars(): with var.GRAVEYARD_LOCK: conn = _conn() c = conn.cursor() c.execute("""SELECT pl.account, pl.hostmask, pe.notice, pe.simple, pe.deadchat, pe.pingif, pe.stasis_amount, pe.stasis_expires, COALESCE(at.flags, a.flags) FROM person pe JOIN player pl ON pl.person = pe.id LEFT JOIN access a ON a.person = pe.id LEFT JOIN access_template at ON at.id = a.template WHERE pl.active = 1""") var.SIMPLE_NOTIFY = set( ) # cloaks of people who !simple, who don't want detailed instructions var.SIMPLE_NOTIFY_ACCS = set( ) # same as above, except accounts. takes precedence var.PREFER_NOTICE = set( ) # cloaks of people who !notice, who want everything /notice'd var.PREFER_NOTICE_ACCS = set( ) # Same as above, except accounts. takes precedence var.STASISED = defaultdict(int) var.STASISED_ACCS = defaultdict(int) var.PING_IF_PREFS = {} var.PING_IF_PREFS_ACCS = {} var.PING_IF_NUMS = defaultdict(set) var.PING_IF_NUMS_ACCS = defaultdict(set) var.DEADCHAT_PREFS = set() var.DEADCHAT_PREFS_ACCS = set() var.FLAGS = defaultdict(str) var.FLAGS_ACCS = defaultdict(str) var.DENY = defaultdict(set) var.DENY_ACCS = defaultdict(set) for acc, host, notice, simple, dc, pi, stasis, stasisexp, flags in c: if acc is not None: acc = irc_lower(acc) if simple == 1: var.SIMPLE_NOTIFY_ACCS.add(acc) if notice == 1: var.PREFER_NOTICE_ACCS.add(acc) if stasis > 0: var.STASISED_ACCS[acc] = stasis if pi is not None and pi > 0: var.PING_IF_PREFS_ACCS[acc] = pi var.PING_IF_NUMS_ACCS[pi].add(acc) if dc == 1: var.DEADCHAT_PREFS_ACCS.add(acc) if flags: var.FLAGS_ACCS[acc] = flags elif host is not None: # nick!ident lowercased per irc conventions, host uses normal casing try: hl, hr = host.split("@", 1) host = irc_lower(hl) + "@" + hr.lower() except ValueError: host = host.lower() if simple == 1: var.SIMPLE_NOTIFY.add(host) if notice == 1: var.PREFER_NOTICE.add(host) if stasis > 0: var.STASISED[host] = stasis if pi is not None and pi > 0: var.PING_IF_PREFS[host] = pi var.PING_IF_NUMS[pi].add(host) if dc == 1: var.DEADCHAT_PREFS.add(host) if flags: var.FLAGS[host] = flags c.execute("""SELECT pl.account, pl.hostmask, ws.data FROM warning w JOIN warning_sanction ws ON ws.warning = w.id JOIN person pe ON pe.id = w.target JOIN player pl ON pl.person = pe.id WHERE ws.sanction = 'deny command' AND w.deleted = 0 AND ( w.expires IS NULL OR w.expires > datetime('now') )""") for acc, host, command in c: if acc is not None: acc = irc_lower(acc) var.DENY_ACCS[acc].add(command) if host is not None: host = irc_lower(host) var.DENY[host].add(command)
def init_vars(): with var.GRAVEYARD_LOCK: conn = _conn() c = conn.cursor() c.execute("""SELECT pl.account, pl.hostmask, pe.notice, pe.simple, pe.deadchat, pe.pingif, pe.stasis_amount, pe.stasis_expires, COALESCE(at.flags, a.flags) FROM person pe JOIN player pl ON pl.person = pe.id LEFT JOIN access a ON a.person = pe.id LEFT JOIN access_template at ON at.id = a.template WHERE pl.active = 1""") var.SIMPLE_NOTIFY = set() # cloaks of people who !simple, who don't want detailed instructions var.SIMPLE_NOTIFY_ACCS = set() # same as above, except accounts. takes precedence var.PREFER_NOTICE = set() # cloaks of people who !notice, who want everything /notice'd var.PREFER_NOTICE_ACCS = set() # Same as above, except accounts. takes precedence var.STASISED = defaultdict(int) var.STASISED_ACCS = defaultdict(int) var.PING_IF_PREFS = {} var.PING_IF_PREFS_ACCS = {} var.PING_IF_NUMS = defaultdict(set) var.PING_IF_NUMS_ACCS = defaultdict(set) var.DEADCHAT_PREFS = set() var.DEADCHAT_PREFS_ACCS = set() var.FLAGS = defaultdict(str) var.FLAGS_ACCS = defaultdict(str) var.DENY = defaultdict(set) var.DENY_ACCS = defaultdict(set) for acc, host, notice, simple, dc, pi, stasis, stasisexp, flags in c: if acc is not None: acc = irc_lower(acc) if simple == 1: var.SIMPLE_NOTIFY_ACCS.add(acc) if notice == 1: var.PREFER_NOTICE_ACCS.add(acc) if stasis > 0: var.STASISED_ACCS[acc] = stasis if pi is not None and pi > 0: var.PING_IF_PREFS_ACCS[acc] = pi var.PING_IF_NUMS_ACCS[pi].add(acc) if dc == 1: var.DEADCHAT_PREFS_ACCS.add(acc) if flags: var.FLAGS_ACCS[acc] = flags elif host is not None: # nick!ident lowercased per irc conventions, host uses normal casing try: hl, hr = host.split("@", 1) host = irc_lower(hl) + "@" + hr.lower() except ValueError: host = host.lower() if simple == 1: var.SIMPLE_NOTIFY.add(host) if notice == 1: var.PREFER_NOTICE.add(host) if stasis > 0: var.STASISED[host] = stasis if pi is not None and pi > 0: var.PING_IF_PREFS[host] = pi var.PING_IF_NUMS[pi].add(host) if dc == 1: var.DEADCHAT_PREFS.add(host) if flags: var.FLAGS[host] = flags c.execute("""SELECT pl.account, pl.hostmask, ws.data FROM warning w JOIN warning_sanction ws ON ws.warning = w.id JOIN person pe ON pe.id = w.target JOIN player pl ON pl.person = pe.id WHERE ws.sanction = 'deny command' AND w.deleted = 0 AND ( w.expires IS NULL OR w.expires > datetime('now') )""") for acc, host, command in c: if acc is not None: acc = irc_lower(acc) var.DENY_ACCS[acc].add(command) if host is not None: host = irc_lower(host) var.DENY[host].add(command)