- replace $old => $new, host($userinfo->{host}),
- get_info('server'), lc get_info('channel') if $userinfo;
+ $userinfo = user_info $old unless defined $userinfo;
+ my $userhost = $userinfo->{host};
+ if (defined $userhost and length $userhost) {
+ # If the host isn't defined, the first WHO response hasn't been received yet,
+ # so the old nick isn't even in our database.
+ # Otherwise, the new nick would be added right now, and the old one would be
+ # when the WHO responses arrives (which may still refer to the old nick).
+ replace $old => $new, host($userhost),
+ get_info('server'), lc get_info('channel');
+ }