Properly handle the bot's host change

This commit is contained in:
Vgr E. Barry 2017-04-07 16:52:35 -04:00
parent e0ea1f00e4
commit 64eb34a61a
2 changed files with 27 additions and 0 deletions

View File

@ -159,6 +159,25 @@ def end_who(cli, bot_server, bot_nick, target, rest):
Event("who_end", {}).dispatch(var, target)
### Host changing handling
@hook("event_hosthidden")
def host_hidden(cli, server, nick, host, message):
"""Properly update the bot's knowledge of itself.
Ordering and meaning of arguments for a host hidden event:
0 - The IRCClient instance (like everywhere else)
1 - The server the bot is on
2 - The user's nick (i.e. the bot's nick)
3 - The new host we are now using
4 - A human-friendly message (e.g. "is now your hidden host")
"""
assert nick == users.Bot.nick
users.Bot = users.Bot.with_host(host)
### Server PING handling
@hook("ping")

View File

@ -594,6 +594,14 @@ class BotUser(User): # TODO: change all the 'if x is Bot' for 'if isinstance(x,
self.modes = set()
return self
def with_host(self, host):
"""Create a new bot instance with a new host."""
new = super().__new__(type(self), self.client, self.nick, self.ident, host, self.realname, self.account)
if new is not self:
new.modes = set(self.modes)
new.channels = {chan: set(modes) for chan, modes in self.channels.items()}
return new
def lower(self):
temp = type(self)(self.client, lower(self.nick))
if temp is not self: