zD12 / pircbotx

Automatically exported from code.google.com/p/pircbotx
0 stars 0 forks source link

Changing bot's nick does not update its User object nick #117

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Call bot.changeNick(newNick)
2. Catch the NickChangeEvent in a Listener's onEvent
3. Print the event.

What is the expected output? What do you see instead?
Expected: For the nick in the User object to match newNick. Instead I get this:

NickChangeEvent(oldNick=KRAICFreek, newNick=ballsballsballs, 
user=User(nick=KRAICFreek, realName=Wollapolladollalolla, login=~KRIRC, 
hostmask=cpe-76-183-227-155.tx.res.rr.com, away=false, ircop=false, 
server=nova.esper.net, hops=0, bot=Version{Android IRC Client v0.1.0} 
Connected{true} Server{irc.esper.net} Port{6667} Password{null}, 
uuid=1c29ac18-2694-41a6-8912-07d79fe853dd))

What version of the product are you using? On what operating system?
PircBotX 1.8, Android

Please provide any additional information below.
Possibly due to the following function in PircBotX.java:

protected void setNick(String nick) {
                synchronized (userNickMap) {
                        User user = getUser(this.nick);
                        userNickMap.remove(this.nick);
                        userNickMap.put(nick, user);
                        this.nick = nick;
                }
        }

Should there not be a user.setNick(nick)?

Original issue reported on code.google.com by firefr...@gmail.com on 31 Mar 2013 at 3:42

GoogleCodeExporter commented 9 years ago
Nevermind, found the problem. In the method handleLine() in my pircbotx-1.8.jar 
there's this:

else if (command.equals("NICK")) {
            // Somebody is changing their nick.
            String newNick = target;
            if (sourceNick.equals(getNick()))
                // Update our nick if it was us that changed nick.
                setNick(newNick);
            else getUser(sourceNick).setNick(newNick);

            getListenerManager().dispatchEvent(new NickChangeEvent(this, sourceNick, newNick, source));
}

But in the current source on Google Code there's this:

else if (command.equals("NICK")) {
                        // Somebody is changing their nick.
                        String newNick = target;
                        getUser(sourceNick).setNick(newNick);
                        if (sourceNick.equals(getNick()))
                                // Update our nick if it was us that changed nick.
                                setNick(newNick);
                        getListenerManager().dispatchEvent(new NickChangeEvent(this, sourceNick, newNick, source));
}

It seems the newer source calls setNick on the actual User, even if it's a bot. 
This issue should be closed.

Original comment by firefr...@gmail.com on 31 Mar 2013 at 4:09

GoogleCodeExporter commented 9 years ago
Yes, the bot itself has a user object because its included in the WHO and NAMES 
replies. 

I'm not sure where your pulling the first bit of code from though as since 1.0 
its always set the nick of the user like in the second example:
https://code.google.com/p/pircbotx/source/browse/src/main/java/org/pircbotx/Pirc
BotX.java?name=1.0#1177
Thats the same code in the pircbotx-1.8-sources.zip file I just downloaded to 
check

Original comment by Lord.Qua...@gmail.com on 31 Mar 2013 at 7:57