._ |_  _._   |  
| ||_)_>|_)  |  
        |    |  

over the past week i’ve been setting up a private little IRC server for me and my friends. i’ve got a cool oldnet-sounding domain name for it, and everything. it’s been fun.

one of the things that we’ve been missing in IRC as opposed to our existing chatrooms on Discord, is PluralKit, a bot that lets you appear as a different user by sending a message with a certain pattern. it’s far from perfect, but it’s very useful for, in our case, differentiating between plural systems’ members. so i decided to add some sort of plural system support to our IRC server.

there are many ways i could have done this, but i decided that the easiest, prettiest and least janky way would be to patch it directly into Ergo, my IRCd of choice. this made it possible to add first-class support for plural systems through the use of the new PluralServ service.

tl;dr: the link for the patch is at the bottom of this blog post.

how it works

plural support is disabled by default. to enable it, add the following to your config:

server:
    # ...
    allow-plural: true

tada! PluralServ is now enabled on your server, for authenticated users. the following is a simple example of setting up a member and talking as it:

      > /ps on
     *  PluralServ: Successfully enabled your system
      > /ps add foo foo> text
     *  PluralServ: Successfully added member foo to system
      > /ps latch on
     *  PluralServ: Successfully enabled latch mode
      > meow
  user  meow
      > foo> meow
   foo  meow
      > meow
   foo  meow

run /ps help for complete information about everything it does.

note that you should assume good-will when enabling this setting. while the original account is added on as a tag to the message, many clients don’t show it, and it makes it hard to know who sent what, and who should be kicked in case of spam. i’ve toyed with the idea of adding the sender’s nick as a suffix, but Ergo is restrictive with which characters it allows in nicks, and there weren’t any that looked good.

how it really works

the patch adds a new service called PluralServ, which controls the new System attribute. this attribute includes information about members, latching, and whether PluralServ is enabled for this user.

type SystemInfo struct {
	Enabled      bool
	Members      map[string]string
	LatchEnabled bool
	LastFront    string
}

whenever an authenticated user sends a PRIVMSG, the server looks up that account’s system settings. if they have PluralServ enabled, and their message matches a member tag or they have a latched member, then the nickname is swapped.

if account.System.Enabled && len(account.System.Members) > 0 {
	for member, tag := range account.System.Members {
		// we intentionally support PluralKit's matching, even though it sucks
		tagAsRegex := strings.Replace(regexp.QuoteMeta(tag), "text", "(.*)", 1)
		regex := regexp.MustCompile("^" + tagAsRegex + "$")
		if matches := regex.FindStringSubmatch(message); len(matches) > 1 {
			sendAsMember = member
			message = matches[1]
			server.accounts.SystemSetLastFront(client, sendAsMember)
			break
		}
	}
	if account.System.LatchEnabled && account.System.LastFront != "" {
		sendAsMember = account.System.LastFront
	}
}

that’s it! there’s really nothing else going on under the hood. it’s a lot simpler than PluralKit, of course, but i think the relative simplicity of IRC makes it a lot better at what it does. no double-pings, no deletions, just a good old fashioned spoof.

get it for yourself

the patch is available here. i’ve written it on top of Ergo v2.14.0, but i suppose it should work for any future versions with minimal editing.

it is licensed under MIT, which means i’m probably very happy to help, but it’s not my fault if you fuck up your server.

feel free to email me if you have any questions or requests!