Move automatic mode syncing to hooks.py

This commit is contained in:
Vgr E. Barry 2018-04-13 16:54:34 -04:00
parent 28f26e181b
commit 7154a7d092
2 changed files with 14 additions and 7 deletions

View File

@ -320,7 +320,16 @@ def mode_change(cli, rawnick, chan, mode, *targets):
users.Bot.modes.update(mode)
return
actor = users._add(cli, nick=rawnick) # FIXME
if "!" not in rawnick:
# Only sync modes if a server changed modes because
# 1) human ops probably know better
# 2) other bots might start a fight over modes
# 3) recursion; we see our own mode changes.
evt = Event("sync_modes", {})
evt.dispatch(var)
return
actor = users._get(rawnick) # FIXME
target = channels.add(chan, cli)
target.queue("mode_change", {"mode": mode, "targets": targets}, (var, actor, target))

View File

@ -269,12 +269,6 @@ def check_for_modes(cli, rnick, chan, modeaction, *target):
var.USERS[trgt]["moded"].remove(change)
elif change in var.USERS[trgt]["modes"]:
var.USERS[trgt]["modes"].remove(change)
# Only sync modes if a server changed modes because
# 1) human ops probably know better
# 2) other bots might start a fight over modes
# 3) recursion; we see our own mode changes.
if "!" not in rnick:
sync_modes(var)
def reset_settings():
var.CURRENT_GAMEMODE.teardown()
@ -348,6 +342,10 @@ def fsync(var, wrapper, message):
"""Makes the bot apply the currently appropriate channel modes."""
sync_modes(var)
@event_listener("sync_modes")
def on_sync_modes(evt, var):
sync_modes(var)
def sync_modes(var):
voices = [None]
mode = hooks.Features["PREFIX"]["+"]