From 0426fb71f9d1efb7bae4b92033d99cd6b68ac5b8 Mon Sep 17 00:00:00 2001 From: llmII <40866124+llmII@users.noreply.github.com> Date: Wed, 3 Mar 2021 18:38:06 -0600 Subject: [PATCH] Initial Relay Nick Changes Feature (#72) This relies on #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. --- bridge/irc_listener.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bridge/irc_listener.go b/bridge/irc_listener.go index 7ed7595..3ce0990 100644 --- a/bridge/irc_listener.go +++ b/bridge/irc_listener.go @@ -1,6 +1,7 @@ package bridge import ( + "fmt" "strings" ircf "github.com/qaisjp/go-discord-irc/irc/format" @@ -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. @@ -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 {