Add support for CHGHOST (#318)

Add proper support for CHGHOST, and also get rid of some misguided assumptions in the hooks.
This commit is contained in:
Em Barry 2018-04-18 14:16:01 -04:00 committed by Ryan Schmidt
parent 35f3fd67cc
commit 42424e49df
2 changed files with 33 additions and 7 deletions

View File

@ -10,7 +10,7 @@ import functools
import botconfig
import src.settings as var
from src import decorators, wolfgame, events, context, channels, hooks, users, errlog as log, stream_handler as alog
from src import decorators, wolfgame, events, channels, hooks, users, errlog as log, stream_handler as alog
from src.messages import messages
from src.utilities import reply
from src.functions import get_participants, get_all_roles
@ -232,7 +232,7 @@ def connect_callback(cli):
hook("unavailresource", hookid=240)(mustrelease)
hook("nicknameinuse", hookid=241)(mustregain)
request_caps = {"account-notify", "extended-join", "multi-prefix"}
request_caps = {"account-notify", "extended-join", "multi-prefix", "chghost"}
if botconfig.SASL_AUTHENTICATION:
request_caps.add("sasl")

View File

@ -528,7 +528,7 @@ def on_account_change(cli, rawnick, account):
"""
user = users._add(cli, nick=rawnick) # FIXME
user = users._get(rawnick) # FIXME
user.account = account # We don't pass it to add(), since we want to grab the existing one (if any)
Event("account_change", {}).dispatch(var, user)
@ -595,7 +595,7 @@ def part_chan(cli, rawnick, chan, reason=""):
"""
ch = channels.add(chan, cli)
user = users._add(cli, nick=rawnick) # FIXME
user = users._get(rawnick) # FIXME
Event("chan_part", {}).dispatch(var, ch, user, reason)
if user is users.Bot: # oh snap! we're no longer in the channel!
@ -620,8 +620,8 @@ def kicked_from_chan(cli, rawnick, chan, target, reason):
"""
ch = channels.add(chan, cli)
actor = users._add(cli, nick=rawnick) # FIXME
user = users._add(cli, nick=target) # FIXME
actor = users._get(rawnick, allow_none=True) # FIXME
user = users._get(target) # FIXME
Event("chan_kick", {}).dispatch(var, ch, actor, user, reason)
if user is users.Bot:
@ -655,7 +655,7 @@ def on_quit(cli, rawnick, reason):
"""
user = users._add(cli, nick=rawnick) # FIXME
user = users._get(rawnick) # FIXME
Event("server_quit", {}).dispatch(var, user, reason)
for chan in set(user.channels):
@ -664,4 +664,30 @@ def on_quit(cli, rawnick, reason):
else:
chan.remove_user(user)
### CHGHOST Handling
@hook("chghost")
def on_chghost(cli, rawnick, ident, host):
"""Handle a user changing host without a quit.
Ordering and meaning of arguments for CHGHOST:
0 - The IRCClient instance (like everywhere else)
1 - The raw nick (nick!ident@host) of the user switching
2 - The new ident for the user (or same if unchanged)
3 - The new host for the user (or same if unchanged)
"""
user = users._get(rawnick) # FIXME
new = users._add(cli, nick=user.nick, ident=ident, host=host, realname=user.realname, account=user.account) # FIXME
if user is not new:
new.channels = user.channels.copy()
new.timestamp = user.timestamp # We lie, but it's ok
for chan in set(user.channels):
chan.remove_user(user)
chan.users.add(new)
user.swap(new)
# vim: set sw=4 expandtab: