Improve the ping-if to not ping multiple times the same people.
This commit is contained in:
parent
225fdbc6bb
commit
192b97d593
@ -334,6 +334,8 @@ def reset():
|
|||||||
var.JOINED_THIS_GAME = [] # keeps track of who already joined this game at least once (cloaks)
|
var.JOINED_THIS_GAME = [] # keeps track of who already joined this game at least once (cloaks)
|
||||||
var.JOINED_THIS_GAME_ACCS = [] # same, except accounts
|
var.JOINED_THIS_GAME_ACCS = [] # same, except accounts
|
||||||
var.PING_JOIN_TIMER = 0
|
var.PING_JOIN_TIMER = 0
|
||||||
|
var.PINGED_ALREADY = []
|
||||||
|
var.PINGED_ALREADY_ACCS = []
|
||||||
var.NO_LYNCH = []
|
var.NO_LYNCH = []
|
||||||
var.FGAMED = False
|
var.FGAMED = False
|
||||||
var.CURRENT_GAMEMODE = "default"
|
var.CURRENT_GAMEMODE = "default"
|
||||||
@ -488,8 +490,6 @@ def pinger(cli, nick, chan, rest):
|
|||||||
def do_ping(*args):
|
def do_ping(*args):
|
||||||
if not var.PINGING: return
|
if not var.PINGING: return
|
||||||
|
|
||||||
TO_PING = list(set(TO_PING)) # prevents duplicate entries
|
|
||||||
|
|
||||||
TO_PING.sort(key=lambda x: x.lower())
|
TO_PING.sort(key=lambda x: x.lower())
|
||||||
|
|
||||||
if TO_PING:
|
if TO_PING:
|
||||||
@ -842,7 +842,7 @@ def altpinger(cli, nick, chan, rest):
|
|||||||
else:
|
else:
|
||||||
cli.notice(nick, "Your ping preferences are already set to {0}.".format(rest))
|
cli.notice(nick, "Your ping preferences are already set to {0}.".format(rest))
|
||||||
elif altpinged:
|
elif altpinged:
|
||||||
msg = "Your ping preferences have been changed from {0} to {1}.".format(altpinged, rest)
|
msg = "Your ping preferences have been changed from {0} to {1}.".format(players, rest)
|
||||||
if chan == nick:
|
if chan == nick:
|
||||||
pm(cli, nick, msg)
|
pm(cli, nick, msg)
|
||||||
else:
|
else:
|
||||||
@ -957,40 +957,57 @@ def join_timer_handler(cli):
|
|||||||
to_ping = set() # this ensures we don't have any duplicate
|
to_ping = set() # this ensures we don't have any duplicate
|
||||||
pl = var.list_players()
|
pl = var.list_players()
|
||||||
|
|
||||||
if len(pl) in var.PING_IF_NUMS_ACCS or (not var.ACCOUNTS_ONLY and len(pl) in var.PING_IF_NUMS):
|
var.PINGING_IFS = True
|
||||||
var.PINGING_IFS = True
|
checker = []
|
||||||
checker = []
|
chk_acc = []
|
||||||
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:
|
for num in var.PING_IF_NUMS:
|
||||||
if num <= len(pl):
|
if num <= len(pl):
|
||||||
checker.extend(var.PING_IF_NUMS[num])
|
checker.extend(var.PING_IF_NUMS[num])
|
||||||
|
|
||||||
for num in var.PING_IF_NUMS_ACCS:
|
for acc in chk_acc[:]:
|
||||||
if num <= len(pl):
|
if acc in var.PINGED_ALREADY_ACCS:
|
||||||
chk_acc.extend(var.PING_IF_NUMS_ACCS[num])
|
chk_acc.remove(acc)
|
||||||
|
|
||||||
@hook("whospcrpl", hookid=387)
|
for cloak in checker[:]:
|
||||||
def ping_altpingers(cli, server, nick, ident, cloak, _, user, status, acc):
|
if cloak in var.PINGED_ALREADY:
|
||||||
if ('G' in status or '+' in status or is_user_stasised(user)[0] or
|
checker.remove(cloak)
|
||||||
not var.PINGING_IFS or user == botconfig.NICK):
|
|
||||||
return
|
|
||||||
if acc and acc != "*":
|
|
||||||
if acc in chk_acc and acc in var.PING_PREFS_ACCS and var.PING_PREFS_ACCS[acc] == "all":
|
|
||||||
to_ping.add(user)
|
|
||||||
|
|
||||||
elif not var.ACCOUNTS_ONLY and cloak in checker and cloak in var.PING_PREFS and var.PING_PREFS[cloak] == "all":
|
if not chk_acc and not checker:
|
||||||
|
var.PINGING_IFS = False
|
||||||
|
var.PING_JOIN_TIMER = 0
|
||||||
|
return
|
||||||
|
|
||||||
|
@hook("whospcrpl", hookid=387)
|
||||||
|
def ping_altpingers(cli, server, nick, ident, cloak, _, user, status, acc):
|
||||||
|
if ('G' in status or '+' 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 acc in var.PING_PREFS_ACCS and var.PING_PREFS_ACCS[acc] == "all":
|
||||||
to_ping.add(user)
|
to_ping.add(user)
|
||||||
|
var.PINGED_ALREADY_ACCS.append(acc)
|
||||||
|
|
||||||
@hook("endofwho", hookid=387)
|
elif not var.ACCOUNTS_ONLY and cloak in checker and cloak in var.PING_PREFS and var.PING_PREFS[cloak] == "all":
|
||||||
def fetch_altpingers(*stuff):
|
to_ping.add(user)
|
||||||
var.PINGING_IFS = False
|
var.PINGED_ALREADY.append(cloak)
|
||||||
var.PING_JOIN_TIMER = 0
|
|
||||||
decorators.unhook(HOOKS, 387)
|
|
||||||
if to_ping:
|
|
||||||
cli.msg(botconfig.CHANNEL, "PING! {0} players! {1}".format(len(pl), " ".join(to_ping)))
|
|
||||||
|
|
||||||
cli.who(botconfig.CHANNEL, "%nushaf")
|
@hook("endofwho", hookid=387)
|
||||||
|
def fetch_altpingers(*stuff):
|
||||||
|
var.PINGING_IFS = False
|
||||||
|
var.PING_JOIN_TIMER = 0
|
||||||
|
decorators.unhook(HOOKS, 387)
|
||||||
|
if to_ping:
|
||||||
|
cli.msg(botconfig.CHANNEL, "PING! {0} players! {1}".format(len(pl), " ".join(to_ping)))
|
||||||
|
|
||||||
|
cli.who(botconfig.CHANNEL, "%nushaf")
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
@ -1047,6 +1064,8 @@ def join_player(cli, player, chan, who = None, forced = False):
|
|||||||
var.WAITED = 0
|
var.WAITED = 0
|
||||||
var.GAME_ID = time.time()
|
var.GAME_ID = time.time()
|
||||||
var.PING_JOIN_TIMER = datetime.now()
|
var.PING_JOIN_TIMER = datetime.now()
|
||||||
|
var.PINGED_ALREADY_ACCS = []
|
||||||
|
var.PINGED_ALREADY = []
|
||||||
join_pinger = threading.Thread(None, join_timer_handler, args=(cli,))
|
join_pinger = threading.Thread(None, join_timer_handler, args=(cli,))
|
||||||
join_pinger.daemon = True
|
join_pinger.daemon = True
|
||||||
join_pinger.start()
|
join_pinger.start()
|
||||||
|
Loading…
Reference in New Issue
Block a user