If the bot was restarted in the join phase, ping the players afterwards
This commit is contained in:
parent
1da0bd1a9e
commit
3985063b60
@ -38,6 +38,7 @@ import subprocess
|
|||||||
import signal
|
import signal
|
||||||
from tools import logger
|
from tools import logger
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
debuglog = logger("debug.log", write=False, display=False) # will be True if in debug mode
|
debuglog = logger("debug.log", write=False, display=False) # will be True if in debug mode
|
||||||
errlog = logger("errors.log")
|
errlog = logger("errors.log")
|
||||||
@ -163,9 +164,19 @@ def connect_callback(cli):
|
|||||||
|
|
||||||
@hook("endofwho", hookid=294)
|
@hook("endofwho", hookid=294)
|
||||||
def afterwho(*args):
|
def afterwho(*args):
|
||||||
|
# Devoice all on connect
|
||||||
for nick in to_be_devoiced:
|
for nick in to_be_devoiced:
|
||||||
cmodes.append(("-v", nick))
|
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
|
#bot can be tricked into thinking it's still opped by doing multiple modes at once
|
||||||
@hook("mode", hookid=294)
|
@hook("mode", hookid=294)
|
||||||
@ -451,6 +462,15 @@ def restart_program(cli, nick, chan, rest):
|
|||||||
except Exception:
|
except Exception:
|
||||||
notify_error(cli, chan, errlog)
|
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:
|
try:
|
||||||
reset()
|
reset()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -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('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')
|
c.execute('SELECT * FROM away')
|
||||||
for row in c:
|
for row in c:
|
||||||
AWAY.append(row[0])
|
AWAY.append(row[0])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user