Skip to content

Commit

Permalink
Split outgoing IRC messages by newline character
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Nov 11, 2020
1 parent f1c355b commit 3dbb1f6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions bees/ircbee/ircbee.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ type IrcBee struct {
ssl bool
}

func sendLines(to string, msg string, sendFunc func(string, string)) {
for _, s := range strings.Split(msg, "\n") {
sendFunc(to, s)
}
}

// Action triggers the action passed to it.
func (mod *IrcBee) Action(action bees.Action) []bees.Placeholder {
outs := []bees.Placeholder{}
var sendFunc func(t, msg string)
var sendFunc func(to, msg string)

switch action.Name {
case "notice":
Expand All @@ -76,15 +82,15 @@ func (mod *IrcBee) Action(action bees.Action) []bees.Placeholder {
if recv == "*" {
// special: send to all joined channels
for _, to := range mod.channels {
sendFunc(to, text)
sendLines(to, text, sendFunc)
}
} else {
// needs stripping hostname when sending to user!host
if strings.Index(recv, "!") > 0 {
recv = recv[0:strings.Index(recv, "!")]
}

sendFunc(recv, text)
sendLines(recv, text, sendFunc)
}
}

Expand Down

0 comments on commit 3dbb1f6

Please sign in to comment.