From 10be2e341fa499334ab4b13f89ab6d152eec3a21 Mon Sep 17 00:00:00 2001 From: "Vgr E. Barry" Date: Mon, 26 Oct 2015 23:39:22 -0400 Subject: [PATCH] First draft of the !deadchat pref --- src/settings.py | 20 ++++++++++++++++++++ src/wolfgame.py | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/src/settings.py b/src/settings.py index 05d5e2b..56e2b78 100644 --- a/src/settings.py +++ b/src/settings.py @@ -360,6 +360,9 @@ PING_IF_PREFS_ACCS = {} PING_IF_NUMS = {} PING_IF_NUMS_ACCS = {} +DEADCHAT_PREFS = set() +DEADCHAT_PREFS_ACCS = set() + is_role = lambda plyr, rol: rol in ROLES and plyr in ROLES[rol] def match_hostmask(hostmask, nick, ident, host): @@ -556,6 +559,8 @@ def init_db(): c.execute('CREATE TABLE IF NOT EXISTS pingif_prefs (user TEXT, is_account BOOLEAN, players INTEGER, PRIMARY KEY(user, is_account))') # pingif player count preferences c.execute('CREATE INDEX IF NOT EXISTS ix_ping_prefs_pingif ON pingif_prefs (players ASC)') # index apparently makes it faster + c.execute('CREATE TABLE IF NOT EXISTS deadchat_prefs (user TEXT, is_account BOOLEAN)') # deadcht preferences + c.execute('PRAGMA table_info(pre_restart_state)') try: next(c) @@ -628,6 +633,13 @@ def init_db(): PING_IF_NUMS[row[2]] = set() PING_IF_NUMS[row[2]].add(row[0]) + c.execute('SELECT * FROM deadchat_prefs') + for user, is_acc in c: + if is_acc: + DEADCHAT_PREFS_ACCS.add(user) + else: + DEADCHAT_PREFS.add(user) + # populate the roles table c.execute('DROP TABLE IF EXISTS roles') c.execute('CREATE TABLE roles (id INTEGER PRIMARY KEY AUTOINCREMENT, role TEXT)') @@ -729,6 +741,14 @@ def set_pingif_status(user, is_account, players): if players != 0: c.execute('INSERT OR REPLACE INTO pingif_prefs VALUES (?,?,?)', (user, is_account, players)) +def add_deadchat_pref(user, is_account): + with conn: + c.execute('INSERT OR REPLACE INTO deadchat_prefs VALUES (?,?)', (user, is_account)) + +def remove_deadchat_pref(user, is_account): + with conn: + c.execute('DELETE FROM deadchat_prefs WHERE user=? AND is_account=?' (user, is_account)) + def update_role_stats(acc, role, won, iwon): with conn: wins, iwins, total = 0, 0, 0 diff --git a/src/wolfgame.py b/src/wolfgame.py index 655677a..f2e311e 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -1078,6 +1078,10 @@ def join_timer_handler(cli): else: cli.who(botconfig.CHANNEL) +@cmd("deadchat", pm=True) +def deadchat_pref(cli, nick, chan, rest): + pass # for now + @cmd("join", "j", pm=True) def join(cli, nick, chan, rest): """Either starts a new game of Werewolf or joins an existing game that has not started yet."""