Remove old db calls
This commit is contained in:
parent
0c0268e1b7
commit
e47a348f22
23
src/db.py
23
src/db.py
@ -691,6 +691,29 @@ def acknowledge_warning(warning):
|
|||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
c.execute("UPDATE warning SET acknowledged = 1 WHERE id = ?", (warning,))
|
c.execute("UPDATE warning SET acknowledged = 1 WHERE id = ?", (warning,))
|
||||||
|
|
||||||
|
def get_pre_restart_state():
|
||||||
|
conn = _conn()
|
||||||
|
with conn:
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("SELECT players FROM pre_restart_state")
|
||||||
|
players = c.fetchone()
|
||||||
|
if players is None:
|
||||||
|
# missing state row
|
||||||
|
c.execute("INSERT INTO pre_restart_state (players) VALUES (NULL)")
|
||||||
|
players = []
|
||||||
|
else:
|
||||||
|
c.execute("UPDATE pre_restart_state SET players=NULL")
|
||||||
|
players = players.split()
|
||||||
|
return players
|
||||||
|
|
||||||
|
def set_pre_restart_state(players):
|
||||||
|
if not players:
|
||||||
|
return
|
||||||
|
conn = _conn()
|
||||||
|
with conn:
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("UPDATE pre_restart_state SET players = ?", (" ".join(players),))
|
||||||
|
|
||||||
def _upgrade(oldversion):
|
def _upgrade(oldversion):
|
||||||
# try to make a backup copy of the database
|
# try to make a backup copy of the database
|
||||||
print ("Performing schema upgrades, this may take a while.", file=sys.stderr)
|
print ("Performing schema upgrades, this may take a while.", file=sys.stderr)
|
||||||
|
@ -215,18 +215,11 @@ def connect_callback(cli):
|
|||||||
for nick in to_be_devoiced:
|
for nick in to_be_devoiced:
|
||||||
cmodes.append(("-v", nick))
|
cmodes.append(("-v", nick))
|
||||||
|
|
||||||
try:
|
|
||||||
# If the bot was restarted in the middle of the join phase, ping players that were joined.
|
# If the bot was restarted in the middle of the join phase, ping players that were joined.
|
||||||
with sqlite3.connect("data.sqlite3", check_same_thread=False) as conn:
|
players = db.get_pre_restart_state()
|
||||||
c = conn.cursor()
|
|
||||||
c.execute("SELECT players FROM pre_restart_state")
|
|
||||||
players = c.fetchone()[0]
|
|
||||||
if players:
|
if players:
|
||||||
msg = "PING! " + break_long_message(players.split()).replace("\n", "\nPING! ")
|
msg = "PING! " + break_long_message(players.split()).replace("\n", "\nPING! ")
|
||||||
cli.msg(botconfig.CHANNEL, msg)
|
cli.msg(botconfig.CHANNEL, msg)
|
||||||
c.execute("UPDATE pre_restart_state SET players = NULL")
|
|
||||||
except Exception:
|
|
||||||
notify_error(cli, botconfig.CHANNEL, errlog)
|
|
||||||
|
|
||||||
# Unhook the WHO hooks
|
# Unhook the WHO hooks
|
||||||
hook.unhook(295)
|
hook.unhook(295)
|
||||||
@ -528,33 +521,14 @@ def restart_program(cli, nick, chan, rest):
|
|||||||
|
|
||||||
if var.PHASE in var.GAME_PHASES:
|
if var.PHASE in var.GAME_PHASES:
|
||||||
if var.PHASE == "join" or force:
|
if var.PHASE == "join" or force:
|
||||||
try:
|
|
||||||
stop_game(cli)
|
stop_game(cli)
|
||||||
except Exception:
|
|
||||||
traceback.print_exc()
|
|
||||||
else:
|
else:
|
||||||
reply(cli, nick, chan, messages["stop_bot_ingame_safeguard"].format(
|
reply(cli, nick, chan, messages["stop_bot_ingame_safeguard"].format(
|
||||||
what="restart", cmd="frestart", prefix=botconfig.CMD_CHAR), private=True)
|
what="restart", cmd="frestart", prefix=botconfig.CMD_CHAR), private=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
|
||||||
reset_modes_timers(cli)
|
reset_modes_timers(cli)
|
||||||
except Exception:
|
db.set_pre_restart_state(list_players())
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
try:
|
|
||||||
with sqlite3.connect("data.sqlite3", check_same_thread=False) as conn:
|
|
||||||
c = conn.cursor()
|
|
||||||
players = list_players()
|
|
||||||
if players:
|
|
||||||
c.execute("UPDATE pre_restart_state SET players = ?", (" ".join(players),))
|
|
||||||
except Exception:
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
try:
|
|
||||||
reset()
|
|
||||||
except Exception:
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
msg = "{0} restart from {1}".format(
|
msg = "{0} restart from {1}".format(
|
||||||
"Scheduled" if restart_program.aftergame else "Forced", nick)
|
"Scheduled" if restart_program.aftergame else "Forced", nick)
|
||||||
@ -583,10 +557,7 @@ def restart_program(cli, nick, chan, rest):
|
|||||||
if rest:
|
if rest:
|
||||||
msg += " ({0})".format(rest)
|
msg += " ({0})".format(rest)
|
||||||
|
|
||||||
try:
|
|
||||||
cli.quit(msg.format(nick, rest.strip()))
|
cli.quit(msg.format(nick, rest.strip()))
|
||||||
except Exception:
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
@hook("quit")
|
@hook("quit")
|
||||||
def restart_buffer(cli, raw_nick, reason):
|
def restart_buffer(cli, raw_nick, reason):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user