From 42424e49df547b94b88dca827e580cb77695aa37 Mon Sep 17 00:00:00 2001 From: Em Barry Date: Wed, 18 Apr 2018 14:16:01 -0400 Subject: [PATCH] Add support for CHGHOST (#318) Add proper support for CHGHOST, and also get rid of some misguided assumptions in the hooks. --- src/handler.py | 4 ++-- src/hooks.py | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/handler.py b/src/handler.py index 3041825..0b3ef44 100644 --- a/src/handler.py +++ b/src/handler.py @@ -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") diff --git a/src/hooks.py b/src/hooks.py index da44adb..222d390 100644 --- a/src/hooks.py +++ b/src/hooks.py @@ -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: