raisedragon / pircbotx

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

Getting channel users in onJoin returns only bot itself #74

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
@Override
    public void onJoin(JoinEvent<Bot> e) throws Exception
    {
        super.onJoin(e);
        System.out.println(e.getChannel().getUsers());
    }

This returns

[User(nick=FreekBot, realName=, login=~FreekBot, 
hostmask=cpe-76-183-231-35.tx.res.rr.com, away=false, ircop=false, server=, 
identified=true, hops=0, bot=Version{PircBotX~Vivio v0.5} Connected{true} 
Server{irc.esper.net} Port{6667} Password{}, 
uuid=62d18057-0131-4567-b848-23dd70dd553a)]

It should return all the users in the channel instead.

Original issue reported on code.google.com by firefr...@gmail.com on 27 May 2012 at 2:19

GoogleCodeExporter commented 9 years ago
Did the bot just join the channel? If so, then I'm pretty sure the server 
hasn't sent the names list or responded to the WHO query of the users in the 
channel. 

I'll do some checking

Original comment by Lord.Qua...@gmail.com on 27 May 2012 at 6:39

GoogleCodeExporter commented 9 years ago
Yes, this is when the bot joins the channel, sorry. If this isn't the right way 
to get the users when entering the channel, what is?

Original comment by firefr...@gmail.com on 27 May 2012 at 7:31

GoogleCodeExporter commented 9 years ago
Sorry for the delay. 

Some testing shows that this is usually correct

*said join on connect
1338743089042 <<<:PircBotX!~LQ@74-138-42-125.dhcp.insightbb.com JOIN #pircbotx
1338743089043 >>>WHO #pircbotx  <--- Ask for users
[User(nick=PircBotX, realName=, login=~LQ,  ....... <--- We did just join, so 
get user list
1338743089244 <<<:zelazny.freenode.net 352 PircBotX #pircbotx ~LQ 
74-138-42-125.dhcp.insightbb.com zelazny.freenode.net PircBotX H :0 PircBotX 
1.7, a fork of PircBot, the Java IRC bot 
1338743089244 <<<:zelazny.freenode.net 352 PircBotX #pircbotx ~lordquack 
74-138-42-125.dhcp.insightbb.com niven.freenode.net Guest98364 H :0 
lordquackstar <-- Here I am, after we joined
1338743089244 <<<:zelazny.freenode.net 315 PircBotX #pircbotx :End of /WHO list.

The easiest way to do it is to wait for the UserListEvent (dispatched every 
time there's a who query):

@Override
public void onJoin(JoinEvent event) throws Exception {
    event.getBot().waitFor(UserListEvent.class);
    System.out.println(event.getChannel().getUsers());
}

Gives you

1338743603611 <<<:PircBotX!~LQ@74-138-42-125.dhcp.insightbb.com JOIN #pircbotx
1338743603613 >>>WHO #pircbotx
1338743604181 <<<:holmes.freenode.net 352 PircBotX #pircbotx ~LQ 
74-138-42-125.dhcp.insightbb.com holmes.freenode.net PircBotX H :0 PircBotX 
1.7, a fork of PircBot, the Java IRC bot 
1338743604182 <<<:holmes.freenode.net 352 PircBotX #pircbotx ~lordquack 
74-138-42-125.dhcp.insightbb.com niven.freenode.net Guest98364 H :0 
lordquackstar
1338743604182 <<<:holmes.freenode.net 315 PircBotX #pircbotx :End of /WHO list.
[User(nick=PircBotX, realName=PircBotX 1.7, a fork of PircBot, the Java IRC bot 
, login=~LQ, hostmask=74-138-42-125.dhcp.insightbb.com, away=false, 
ircop=false, server=holmes.freenode.net, identified=false, hops=0, 
bot=Version{PircBotX 1.7, a fork of PircBot, the Java IRC bot - 
pircbotx.googlecode.com} Connected{true} Server{irc.freenode.org} Port{6667} 
Password{null}, uuid=42d32b51-fe62-4e5d-b227-e6d91e70addd), 
User(nick=Guest98364, realName=lordquackstar, login=~lordquack, 
hostmask=74-138-42-125.dhcp.insightbb.com, away=false, ircop=false, 
server=niven.freenode.net, identified=false, hops=0, bot=Version{PircBotX 1.7, 
a fork of PircBot, the Java IRC bot - pircbotx.googlecode.com} Connected{true} 
Server{irc.freenode.org} Port{6667} Password{null}, 
uuid=25c347ea-33db-4f6d-ad00-2072056e13ad)] <-- There I am

Hope this helps

Original comment by Lord.Qua...@gmail.com on 3 Jun 2012 at 5:14