Skip to content

Commit

Permalink
Initial Relay Nick Changes Feature (qaisjp#72)
Browse files Browse the repository at this point in the history
This relies on qaisjp#69 

It allows Nick changes in IRC to be shown in Discord. This can be a source of annoyance but some people do want to see that level of info in Discord. This level of info also would be helpful in the future when I add a way for Discord to ignore IRC nicks (can see join/quit/part/nick change and build up a proper hostmask for addition to the config).

Right now this piggybacks on the `show_joinquit` feature and config setting. I think we may want to either rename that config variable to something along the lines of `show_metainfo` or make the relayed stuff fully configurable like

```
irc_relay_cmds:
  - PRIVMSG
  - JOIN
  - QUIT
  - PART
  - NICK
  - CTCP_ACTION
  - NOTICE
 ```

That said if the latter is preferred I'd think using the `show_metainfo` idea as a stop-gap until the latter is implemented a good idea. I'm not sure if it is worth the trouble to implement it that granularly.
  • Loading branch information
llmII authored Mar 4, 2021
1 parent e120d9a commit 0426fb7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions bridge/irc_listener.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bridge

import (
"fmt"
"strings"

ircf "github.com/qaisjp/go-discord-irc/irc/format"
Expand Down Expand Up @@ -58,6 +59,33 @@ func (i *ircListener) nickTrackNick(event *irc.Event) {
}
}

func (i *ircListener) OnNickRelayToDiscord(event *irc.Event) {
// ignored hostmasks, or we're a puppet? no relay
if i.bridge.ircManager.isIgnoredHostmask(event.Source) ||
i.isPuppetNick(event.Nick) ||
i.isPuppetNick(event.Message()) {
return
}

oldNick := event.Nick
newNick := event.Message()

msg := IRCMessage{
Username: "",
Message: fmt.Sprintf("_%s changed their nick to %s_", oldNick, newNick),
}

for _, m := range i.bridge.mappings {
channel := m.IRCChannel
if channelObj, ok := i.Connection.GetChannel(channel); ok {
if _, ok := channelObj.GetUser(newNick); ok {
msg.IRCChannel = channel
i.bridge.discordMessagesChan <- msg
}
}
}
}

func (i *ircListener) nickTrackPuppetQuit(e *irc.Event) {
// Protect against HostServ changing nicks or ircd's with CHGHOST/CHGIDENT or similar
// sending us a QUIT for a puppet nick only for it to rejoin right after.
Expand All @@ -78,6 +106,8 @@ func (i *ircListener) OnJoinQuitSettingChange() {
// we're either going to track quits, or track and relay said, so swap out the callback
// based on which is in effect.
if i.bridge.Config.ShowJoinQuit {
i.listenerCallbackIDs["STNICK"] = i.AddCallback("STNICK", i.OnNickRelayToDiscord)

// KICK is not state tracked!
callbacks := []string{"STJOIN", "STPART", "STQUIT", "KICK"}
for _, cb := range callbacks {
Expand Down

0 comments on commit 0426fb7

Please sign in to comment.