meebey / SmartIrc4net

IRC C# Library
http://www.meebey.net/projects/smartirc4net/
Other
126 stars 52 forks source link

OnJoin not reliable? #28

Open bstahly opened 9 years ago

bstahly commented 9 years ago

I'm trying to build a bot that keeps a list of logged in user nicks. I'd like to create an initial list when the room is first entered, then keep the list up to date anytime a new user joins. I tried OnChannelActiveSynced and OnChannelPassiveSynced, but when I call GetChannel, only the bot shows up in the "users" property. I noticed that sometimes when the bot joins, OnJoin will be called for each currently logged in user so I wrote the below code to build the "useList" one nick at a time. Other times though, OnJoin is only called once for the bot and isn't called for each logged in user. Why would the behavior change?

Is it possible the channel I'm connecting to has different sync rules/settings? Maybe my bot is rejoining too quickly so it's not actually resyncing the room correctly? I can't think of what else might be causing this unreliable behavior.

Please let me know if there is a better place to post and thanks for any help!


irc.OnJoin += new JoinEventHandler(OnJoin);

private void OnJoin(object sender, IrcEventArgs e)
{
  if (!irc.IsMe(e.Data.Nick))
  {
    if (!userList.Contains(e.Data.Nick))
    {
      userList.Add(e.Data.Nick);
    }
  }
}
meebey commented 9 years ago

You should turn on the debug logging via log4net, I believe what you see is that JOIN is simply the confirmation of the IRC server that someone joined a channel. It can be your own join or a join of someone else. Using OnChannelActiveSynced should be reliable though, it will only be raised when you join a channel and all users were retrieved, this is close to OnNames, but NAMES has other oddities on IRC :-D like it can be raised multiple times since the message limit of 512 chars.