Skip to content

Commit a970126

Browse files
committed
Initial Relay Nick Changes Feature
Allows for nick changes in IRC to be shown in Discord
1 parent d24c08c commit a970126

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

bridge/irc_listener.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package bridge
22

33
import (
4+
"fmt"
45
"strings"
56

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

62+
func (i *ircListener) OnNickRelayToDiscord(event *irc.Event) {
63+
// ignored hostmasks, or we're a puppet? no relay
64+
if i.bridge.ircManager.isIgnoredHostmask(event.Source) ||
65+
i.isPuppetNick(event.Nick) ||
66+
i.isPuppetNick(event.Message()) {
67+
return
68+
}
69+
70+
oldNick := event.Nick
71+
newNick := event.Message()
72+
73+
msg := IRCMessage{
74+
Username: "",
75+
Message: fmt.Sprintf("_%s changed their nick to %s_", oldNick, newNick),
76+
}
77+
78+
for _, m := range i.bridge.mappings {
79+
channel := m.IRCChannel
80+
if channelObj, ok := i.Connection.GetChannel(channel); ok {
81+
if _, ok := channelObj.GetUser(newNick); ok {
82+
msg.IRCChannel = channel
83+
i.bridge.discordMessagesChan <- msg
84+
}
85+
}
86+
}
87+
}
88+
6189
func (i *ircListener) nickTrackPuppetQuit(e *irc.Event) {
6290
// Protect against HostServ changing nicks or ircd's with CHGHOST/CHGIDENT or similar
6391
// sending us a QUIT for a puppet nick only for it to rejoin right after.
@@ -78,6 +106,8 @@ func (i *ircListener) OnJoinQuitSettingChange() {
78106
// we're either going to track quits, or track and relay said, so swap out the callback
79107
// based on which is in effect.
80108
if i.bridge.Config.ShowJoinQuit {
109+
i.listenerCallbackIDs["STNICK"] = i.AddCallback("STNICK", i.OnNickRelayToDiscord)
110+
81111
// KICK is not state tracked!
82112
callbacks := []string{"STJOIN", "STPART", "STQUIT", "KICK"}
83113
for _, cb := range callbacks {

0 commit comments

Comments
 (0)