-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbroadcast.go
38 lines (35 loc) · 835 Bytes
/
broadcast.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"strings"
)
// Configuration of the broadcast module
type BroadcastConfig struct {
Targets map[string][]string // List of servers/channels-users to broadcast
}
// Broadcast listens for private messages and broadcasts them to a list of targets
func Broadcast(chac chan Action, chev chan Event, config BroadcastConfig) {
a := Action{
Type: A_SAY,
Priority: PRIORITY_LOW,
}
for {
e := <-chev
if e.Type == E_PRIVMSG && len(e.Channel) == 0 {
for server, targets := range config.Targets {
a.Server = server
a.Channel = ""
a.User = ""
for _, target := range targets {
if strings.Index(target, "#") == 1 {
a.Channel = target
} else {
a.User = target
}
a.Data = fmt.Sprintf("private> %s: %s", e.User, e.Data)
chac <- a
}
}
}
}
}