Revert previous 'fix' and discard any conflicting possibilities.
This commit is contained in:
parent
05e3ecd68f
commit
e691f918c8
@ -993,71 +993,66 @@ def toggle_altpinged_status(nick, value, old=None):
|
|||||||
var.PING_IF_NUMS[old].remove(cloak)
|
var.PING_IF_NUMS[old].remove(cloak)
|
||||||
|
|
||||||
def join_timer_handler(cli):
|
def join_timer_handler(cli):
|
||||||
var.WARNING_LOCK.acquire() # need to do this instead of the context manager
|
with var.WARNING_LOCK:
|
||||||
|
var.PINGING_IFS = True
|
||||||
|
to_ping = []
|
||||||
|
pl = var.list_players()
|
||||||
|
|
||||||
var.PINGING_IFS = True
|
checker = []
|
||||||
to_ping = []
|
chk_acc = []
|
||||||
pl = var.list_players()
|
|
||||||
|
|
||||||
checker = []
|
for num in var.PING_IF_NUMS_ACCS:
|
||||||
chk_acc = []
|
|
||||||
|
|
||||||
for num in var.PING_IF_NUMS_ACCS:
|
|
||||||
if num <= len(pl):
|
|
||||||
chk_acc.extend(var.PING_IF_NUMS_ACCS[num])
|
|
||||||
|
|
||||||
if not var.ACCOUNTS_ONLY:
|
|
||||||
for num in var.PING_IF_NUMS:
|
|
||||||
if num <= len(pl):
|
if num <= len(pl):
|
||||||
checker.extend(var.PING_IF_NUMS[num])
|
chk_acc.extend(var.PING_IF_NUMS_ACCS[num])
|
||||||
|
|
||||||
for acc in chk_acc[:]:
|
if not var.ACCOUNTS_ONLY:
|
||||||
if acc in var.PINGED_ALREADY_ACCS:
|
for num in var.PING_IF_NUMS:
|
||||||
chk_acc.remove(acc)
|
if num <= len(pl):
|
||||||
|
checker.extend(var.PING_IF_NUMS[num])
|
||||||
|
|
||||||
for cloak in checker[:]:
|
for acc in chk_acc[:]:
|
||||||
if cloak in var.PINGED_ALREADY:
|
if acc in var.PINGED_ALREADY_ACCS:
|
||||||
checker.remove(cloak)
|
chk_acc.remove(acc)
|
||||||
|
|
||||||
if not chk_acc and not checker:
|
for cloak in checker[:]:
|
||||||
var.PINGING_IFS = False
|
if cloak in var.PINGED_ALREADY:
|
||||||
var.WARNING_LOCK.release()
|
checker.remove(cloak)
|
||||||
return
|
|
||||||
|
|
||||||
@hook("whospcrpl", hookid=387)
|
|
||||||
def ping_altpingers(cli, server, nick, ident, cloak, _, user, status, acc):
|
|
||||||
if ('G' in status or is_user_stasised(user)[0] or not var.PINGING_IFS or
|
|
||||||
user == botconfig.NICK or user in pl):
|
|
||||||
|
|
||||||
|
if not chk_acc and not checker:
|
||||||
|
var.PINGING_IFS = False
|
||||||
return
|
return
|
||||||
|
|
||||||
if acc and acc != "*":
|
@hook("whospcrpl", hookid=387)
|
||||||
if acc in chk_acc and var.PING_PREFS_ACCS.get(acc) in ("once", "all"):
|
def ping_altpingers(cli, server, nick, ident, cloak, _, user, status, acc):
|
||||||
|
if ('G' in status or is_user_stasised(user)[0] or not var.PINGING_IFS or
|
||||||
|
user == botconfig.NICK or user in pl):
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
if acc and acc != "*":
|
||||||
|
if acc in chk_acc and var.PING_PREFS_ACCS.get(acc) in ("once", "all"):
|
||||||
|
to_ping.append(user)
|
||||||
|
var.PINGED_ALREADY_ACCS.append(acc)
|
||||||
|
|
||||||
|
elif not var.ACCOUNTS_ONLY and cloak in checker and var.PING_PREFS.get(cloak) in ("once", "all"):
|
||||||
to_ping.append(user)
|
to_ping.append(user)
|
||||||
var.PINGED_ALREADY_ACCS.append(acc)
|
var.PINGED_ALREADY.append(cloak)
|
||||||
|
|
||||||
elif not var.ACCOUNTS_ONLY and cloak in checker and var.PING_PREFS.get(cloak) in ("once", "all"):
|
@hook("endofwho", hookid=387)
|
||||||
to_ping.append(user)
|
def fetch_altpingers(*stuff):
|
||||||
var.PINGED_ALREADY.append(cloak)
|
# fun fact: if someone joined 10 seconds after someone else, the bot would break.
|
||||||
|
# effectively, the join would delete join_pinger from var.TIMERS and this function
|
||||||
|
# here would be reached before it was created again, thus erroring and crashing.
|
||||||
|
# this is one of the multiple reasons we need unit testing
|
||||||
|
# I was lucky to catch this in testing, as it requires precise timing
|
||||||
|
# it only failed if a join happened while this outer func had started
|
||||||
|
var.PINGING_IFS = False
|
||||||
|
decorators.unhook(HOOKS, 387)
|
||||||
|
if to_ping:
|
||||||
|
to_ping.sort(key=lambda x: x.lower())
|
||||||
|
cli.msg(botconfig.CHANNEL, "PING! {0} players! {1}".format(len(pl), " ".join(to_ping)))
|
||||||
|
|
||||||
@hook("endofwho", hookid=387)
|
cli.who(botconfig.CHANNEL, "%nushaf")
|
||||||
def fetch_altpingers(*stuff):
|
|
||||||
# fun fact: if someone joined 10 seconds after someone else, the bot would break.
|
|
||||||
# effectively, the join would delete join_pinger from var.TIMERS and this function
|
|
||||||
# here would be reached before it was created again, thus erroring and crashing.
|
|
||||||
# this is one of the multiple reasons we need unit testing
|
|
||||||
# I was lucky to catch this in testing, as it requires precise timing
|
|
||||||
# it only failed if a join happened while this outer func had started
|
|
||||||
# possible underlying bugs were squashed with the proper use of a reentrant lock
|
|
||||||
del var.TIMERS['join_pinger']
|
|
||||||
var.PINGING_IFS = False
|
|
||||||
decorators.unhook(HOOKS, 387)
|
|
||||||
if to_ping:
|
|
||||||
to_ping.sort(key=lambda x: x.lower())
|
|
||||||
cli.msg(botconfig.CHANNEL, "PING! {0} players! {1}".format(len(pl), " ".join(to_ping)))
|
|
||||||
var.WARNING_LOCK.release()
|
|
||||||
|
|
||||||
cli.who(botconfig.CHANNEL, "%nushaf")
|
|
||||||
|
|
||||||
@cmd("join", "j", none=True, join=True)
|
@cmd("join", "j", none=True, join=True)
|
||||||
def join(cli, nick, chan, rest):
|
def join(cli, nick, chan, rest):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user