diff --git a/modules/wolfgame.py b/modules/wolfgame.py index 575c7c7..6e6abd4 100644 --- a/modules/wolfgame.py +++ b/modules/wolfgame.py @@ -38,6 +38,7 @@ import subprocess import signal from tools import logger import urllib.request +import sqlite3 debuglog = logger("debug.log", write=False, display=False) # will be True if in debug mode errlog = logger("errors.log") @@ -163,9 +164,19 @@ def connect_callback(cli): @hook("endofwho", hookid=294) def afterwho(*args): + # Devoice all on connect for nick in to_be_devoiced: cmodes.append(("-v", nick)) - # devoice all on connect + + # 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: + c = conn.cursor() + c.execute("SELECT players FROM pre_restart_state") + players = c.fetchone()[0] + if players: + cli.msg(botconfig.CHANNEL, "PING! {0}".format(players)) + c.execute("UPDATE pre_restart_state SET players = NULL") + #bot can be tricked into thinking it's still opped by doing multiple modes at once @hook("mode", hookid=294) @@ -451,6 +462,15 @@ def restart_program(cli, nick, chan, rest): except Exception: notify_error(cli, chan, errlog) + try: + with sqlite3.connect("data.sqlite3", check_same_thread=False) as conn: + c = conn.cursor() + players = var.list_players() + if players: + c.execute("UPDATE pre_restart_state SET players = ?", (" ".join(players),)) + except Exception: + notify_error(cli, chan, errlog) + try: reset() except Exception: diff --git a/settings/wolfgame.py b/settings/wolfgame.py index 1a408bc..d67db14 100644 --- a/settings/wolfgame.py +++ b/settings/wolfgame.py @@ -855,6 +855,13 @@ def init_db(): c.execute('CREATE TABLE IF NOT EXISTS ping_prefs_accs (acc TEXT, pref TEXT)') # ping-if prefs (accounts - primary) + c.execute('PRAGMA table_info(pre_restart_state)') + try: + next(c) + except StopIteration: + c.execute('CREATE TABLE pre_restart_state (players TEXT)') + c.execute('INSERT INTO pre_restart_state (players) VALUES (NULL)') + c.execute('SELECT * FROM away') for row in c: AWAY.append(row[0])