Handle errors gracefully when pinging previously joined players

This commit is contained in:
nyuszika7h 2015-04-15 23:09:39 +02:00
parent 1de23dafb8
commit 4ab966fc06

View File

@ -209,14 +209,17 @@ def connect_callback(cli):
for nick in to_be_devoiced: for nick in to_be_devoiced:
cmodes.append(("-v", nick)) cmodes.append(("-v", nick))
# If the bot was restarted in the middle of the join phase, ping players that were joined. try:
with sqlite3.connect("data.sqlite3", check_same_thread=False) as conn: # If the bot was restarted in the middle of the join phase, ping players that were joined.
c = conn.cursor() with sqlite3.connect("data.sqlite3", check_same_thread=False) as conn:
c.execute("SELECT players FROM pre_restart_state") c = conn.cursor()
players = c.fetchone()[0] c.execute("SELECT players FROM pre_restart_state")
if players: players = c.fetchone()[0]
cli.msg(botconfig.CHANNEL, "PING! {0}".format(players)) if players:
c.execute("UPDATE pre_restart_state SET players = NULL") cli.msg(botconfig.CHANNEL, "PING! {0}".format(players))
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
decorators.unhook(HOOKS, 295) decorators.unhook(HOOKS, 295)