This doc includes some random notes on implementing mode/presence tracking in IRC. Note that this implementation assumes we don't have access to any IRCv3 caps.
There is a rough implementation for go-irc here.
- MODE - look up the user and channel and modify this mode
- NICK - rename a user
- RPL_NAMREPLY (353) - add user to channel and set modes
- JOIN - add the user to the channel, creating the user if they aren't tracked yet.
- PART/KICK - remove the user from a channel, then if they aren't in any other tracked channels, remove them.
- QUIT - remove the user from all channels.
- JOIN - Add the bot to the channel and wait for the RPL_NAMREPLY response
- PART/KICK - Remove all users from the given channel and run cleanup as needed.
- QUIT - Pretty much a fatal error.
- When a single user JOINs we don't need to grab modes from anywhere, since they should get MODE called on them after joining.
- Without the multi-prefix CAP, in order to properly track a mode change we need to run a NAMES lookup every time a mode changes on a user.
- There are a number of race conditions, all over the place, mostly around private messages.
- A user must be in at least one channel common to the bot, or they will not be tracked. This means they can only use privmsg tracking if they are in at least one common channel.
- Modes need to be grabbed from ISUPPORT (005) messages - RFC2812 defines 005 as something else, but this is not how it is used in practice.
- We don't really know the bot's NICK until the 001 welcome message
If we can request IRCv3 CAPs, the following make this easier.
- multi-prefix allows us to get all modes on joining a channel