diff --git a/go.mod b/go.mod index 5ca11aa..a509a5c 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module ouch-relay go 1.23.6 -require git.thc420.dev/blackbeard420/irc v0.0.0-20250227032148-dbfee4e42d67 +require git.thc420.dev/blackbeard420/irc v0.0.0-20250228000710-2e8d1a50847a diff --git a/go.sum b/go.sum index 5d6c10f..bbedb22 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -git.thc420.dev/blackbeard420/irc v0.0.0-20250227032148-dbfee4e42d67 h1:JjfZtOe6VaN72YNYrVzLL1LfynF+zbL3hIyTz065U4A= -git.thc420.dev/blackbeard420/irc v0.0.0-20250227032148-dbfee4e42d67/go.mod h1:RtacSCxgLYXrVQBbcU9apo9ZvGckdTbn0BKCQ7HDWK0= +git.thc420.dev/blackbeard420/irc v0.0.0-20250228000710-2e8d1a50847a h1:bLa800VrICquajubOeRImr3UOer5DPTjrhv4Adf7S4A= +git.thc420.dev/blackbeard420/irc v0.0.0-20250228000710-2e8d1a50847a/go.mod h1:RtacSCxgLYXrVQBbcU9apo9ZvGckdTbn0BKCQ7HDWK0= diff --git a/relay.go b/relay.go index 74226d8..e85ee7f 100644 --- a/relay.go +++ b/relay.go @@ -42,6 +42,9 @@ func main() { n.Connection = *irc.NewConnection(n.Url, n.Nick, n.Nick, nil, []string{n.Channel}) if !n.RecvOnly { n.Connection.PrivmsgCallbackEx = handleMessage + n.Connection.JoinCallbackEx = handleJoin + n.Connection.PartCallbackEx = handlePart + n.Connection.QuitCallbackEx = handleQuit } wg.Add(1) go runRelay(&n) @@ -67,6 +70,45 @@ func handleMessage(c *irc.Connection, channel, nick, msg string) { } } +func handleJoin(c *irc.Connection, from, target string) { + netmutex.Lock() + defer netmutex.Unlock() + + us := getByConn(c) + + for _, n := range netmap { + if n.Name != us { + n.Connection.SendPrivmsg(n.Channel, fmt.Sprintf("[%s] {%s} joined %s", netmap[us].Name, irc.GetNick(from), target)) + } + } +} + +func handlePart(c *irc.Connection, from, target, msg string) { + netmutex.Lock() + defer netmutex.Unlock() + + us := getByConn(c) + + for _, n := range netmap { + if n.Name != us { + n.Connection.SendPrivmsg(n.Channel, fmt.Sprintf("[%s] {%s} parted %s %s", netmap[us].Name, irc.GetNick(from), target, msg)) + } + } +} + +func handleQuit(c *irc.Connection, from, msg string) { + netmutex.Lock() + defer netmutex.Unlock() + + us := getByConn(c) + + for _, n := range netmap { + if n.Name != us { + n.Connection.SendPrivmsg(n.Channel, fmt.Sprintf("[%s] {%s} has quit [%s]", netmap[us].Name, irc.GetNick(from), msg)) + } + } +} + func getByConn(c *irc.Connection) string { for _, n := range netmap { if n.Connection.Sock == c.Sock {