First draft of the !deadchat pref

This commit is contained in:
Vgr E. Barry 2015-10-26 23:39:22 -04:00
parent 8517dff63d
commit 10be2e341f
2 changed files with 24 additions and 0 deletions

View File

@ -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

View File

@ -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."""