Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relay nick changes feature #72

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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