added join/part/quit support

This commit is contained in:
blackbeard420 2025-02-27 19:09:31 -05:00
parent 2d89d96d8b
commit 837ee02156
3 changed files with 45 additions and 3 deletions

2
go.mod
View File

@ -2,4 +2,4 @@ module ouch-relay
go 1.23.6 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

4
go.sum
View File

@ -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-20250228000710-2e8d1a50847a h1:bLa800VrICquajubOeRImr3UOer5DPTjrhv4Adf7S4A=
git.thc420.dev/blackbeard420/irc v0.0.0-20250227032148-dbfee4e42d67/go.mod h1:RtacSCxgLYXrVQBbcU9apo9ZvGckdTbn0BKCQ7HDWK0= git.thc420.dev/blackbeard420/irc v0.0.0-20250228000710-2e8d1a50847a/go.mod h1:RtacSCxgLYXrVQBbcU9apo9ZvGckdTbn0BKCQ7HDWK0=

View File

@ -42,6 +42,9 @@ func main() {
n.Connection = *irc.NewConnection(n.Url, n.Nick, n.Nick, nil, []string{n.Channel}) n.Connection = *irc.NewConnection(n.Url, n.Nick, n.Nick, nil, []string{n.Channel})
if !n.RecvOnly { if !n.RecvOnly {
n.Connection.PrivmsgCallbackEx = handleMessage n.Connection.PrivmsgCallbackEx = handleMessage
n.Connection.JoinCallbackEx = handleJoin
n.Connection.PartCallbackEx = handlePart
n.Connection.QuitCallbackEx = handleQuit
} }
wg.Add(1) wg.Add(1)
go runRelay(&n) 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 { func getByConn(c *irc.Connection) string {
for _, n := range netmap { for _, n := range netmap {
if n.Connection.Sock == c.Sock { if n.Connection.Sock == c.Sock {