Make stasis persist through restarts by saving it in the DB
Fixes lykoss/lykos#28.
This commit is contained in:
parent
9b9f35487b
commit
41b8740eb1
@ -25,7 +25,6 @@ import botconfig
|
||||
from tools.wolfgamelogger import WolfgameLogger
|
||||
from tools import decorators
|
||||
from datetime import datetime, timedelta
|
||||
from collections import defaultdict
|
||||
import threading
|
||||
import copy
|
||||
import time
|
||||
@ -87,8 +86,6 @@ var.STARTED_DAY_PLAYERS = 0
|
||||
|
||||
var.DISCONNECTED = {} # players who got disconnected
|
||||
|
||||
var.STASISED = defaultdict(int)
|
||||
|
||||
var.LOGGER = WolfgameLogger(var.LOG_FILENAME, var.BARE_LOG_FILENAME)
|
||||
|
||||
var.JOINED_THIS_GAME = [] # keeps track of who already joined this game at least once (cloaks)
|
||||
@ -221,8 +218,10 @@ def make_stasis(nick, penalty):
|
||||
if cloak is not None:
|
||||
if penalty == 0:
|
||||
del var.STASISED[cloak]
|
||||
var.set_stasised(cloak, 0)
|
||||
else:
|
||||
var.STASISED[cloak] += penalty
|
||||
var.set_stasis(cloak, var.STASISED[cloak])
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
@ -4999,6 +4998,7 @@ def start(cli, nick, chann_, rest):
|
||||
|
||||
for cloak in list(var.STASISED.keys()):
|
||||
var.STASISED[cloak] -= 1
|
||||
var.set_stasis(cloak, var.STASISED[cloak])
|
||||
if var.STASISED[cloak] <= 0:
|
||||
del var.STASISED[cloak]
|
||||
|
||||
@ -5047,10 +5047,12 @@ def fstasis(cli, nick, chan, rest):
|
||||
|
||||
if amt > 0:
|
||||
var.STASISED[cloak] = amt
|
||||
var.set_stasis(cloak, amt)
|
||||
msg = "{0} ({1}) is now in stasis for {2} games.".format(data[0], cloak, amt)
|
||||
else:
|
||||
if cloak in var.STASISED:
|
||||
del var.STASISED[cloak]
|
||||
var.set_stasis(cloak, 0)
|
||||
msg = "{0} ({1}) is no longer in stasis.".format(data[0], cloak)
|
||||
else:
|
||||
msg = "{0} ({1}) is not in stasis.".format(data[0], cloak)
|
||||
|
@ -1,3 +1,5 @@
|
||||
from collections import defaultdict
|
||||
|
||||
PING_WAIT = 300 # Seconds
|
||||
PING_MIN_WAIT = 30 # How long !start has to wait after a !ping
|
||||
MINIMUM_WAIT = 60
|
||||
@ -101,6 +103,8 @@ AWAY = ['services.', 'services.int'] # cloaks of people who are away.
|
||||
SIMPLE_NOTIFY = [] # cloaks of people who !simple, who don't want detailed instructions
|
||||
PREFER_NOTICE = [] # cloaks of people who !notice, who want everything /notice'd
|
||||
|
||||
STASISED = defaultdict(int)
|
||||
|
||||
# TODO: move this to a game mode called "fixed" once we implement a way to randomize roles (and have that game mode be called "random")
|
||||
DEFAULT_ROLE = "villager"
|
||||
ROLE_INDEX = ( 4 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 15 , 16 , 18 , 20 , 21 , 23 , 24 )
|
||||
@ -453,6 +457,8 @@ with conn:
|
||||
|
||||
c.execute('CREATE TABLE IF NOT EXISTS prefer_notice (cloak TEXT)') # people who prefer /notice
|
||||
|
||||
c.execute('CREATE TABLE IF NOT EXISTS stasised (cloak TEXT, games INTEGER, UNIQUE(cloak))') # stasised people
|
||||
|
||||
c.execute('SELECT * FROM away')
|
||||
for row in c:
|
||||
AWAY.append(row[0])
|
||||
@ -465,6 +471,10 @@ with conn:
|
||||
for row in c:
|
||||
PREFER_NOTICE.append(row[0])
|
||||
|
||||
c.execute('SELECT * FROM stasised')
|
||||
for row in c:
|
||||
STASISED[row[0]] = row[1]
|
||||
|
||||
# populate the roles table
|
||||
c.execute('DROP TABLE IF EXISTS roles')
|
||||
c.execute('CREATE TABLE roles (id INTEGER PRIMARY KEY AUTOINCREMENT, role TEXT)')
|
||||
@ -522,6 +532,13 @@ def add_ping(clk):
|
||||
with conn:
|
||||
c.execute('INSERT into ping VALUES (?)', (clk,))
|
||||
|
||||
def set_stasis(clk, games):
|
||||
with conn:
|
||||
if games <= 0:
|
||||
c.execute('DELETE FROM stasised WHERE cloak=?', (clk,))
|
||||
else:
|
||||
c.execute('INSERT OR REPLACE INTO stasised VALUES (?,?)', (clk, games))
|
||||
|
||||
|
||||
def update_role_stats(acc, role, won, iwon):
|
||||
with conn:
|
||||
|
Loading…
Reference in New Issue
Block a user