Skip to content

Instantly share code, notes, and snippets.

@belak
Last active March 14, 2023 01:48
Show Gist options
  • Select an option

  • Save belak/09edcc4f5e51056bf5bc728647659d81 to your computer and use it in GitHub Desktop.

Select an option

Save belak/09edcc4f5e51056bf5bc728647659d81 to your computer and use it in GitHub Desktop.
IRC User Mode Tracking

IRC User Mode Tracking

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.

Simple cases

  • 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

Single user cases (anyone other than the connected user)

  • 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.

Bot user cases

  • 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.

Useful notes:

  • When a single user JOINs we don't need to grab modes from anywhere, since they should get MODE called on them after joining.

Annoying notes:

  • 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

CAP notes

If we can request IRCv3 CAPs, the following make this easier.

  • multi-prefix allows us to get all modes on joining a channel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment