Add a separate dispatcher for PRIVMSG
We're going to use that one a lot more than the others…configurable-file-paths
parent
fb8e2d8392
commit
e816e72743
|
@ -2,6 +2,7 @@ package bot
|
|||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/arachnist/gorepost/irc"
|
||||
)
|
||||
|
@ -16,11 +17,27 @@ func RemoveCallback(command string) {
|
|||
delete(Callbacks, command)
|
||||
}
|
||||
|
||||
var MSGCallbacks = make(map[string]func(chan irc.Message, irc.Message))
|
||||
|
||||
func AddMSGCallback(command string, callback func(chan irc.Message, irc.Message)) {
|
||||
MSGCallbacks[command] = callback
|
||||
}
|
||||
|
||||
func RemoveMSGCallback(command string) {
|
||||
delete(MSGCallbacks, command)
|
||||
}
|
||||
|
||||
func Dispatcher(quit chan struct{}, output chan irc.Message, input chan irc.Message) {
|
||||
log.Println("spawned Dispatcher")
|
||||
for {
|
||||
select {
|
||||
case msg := <-input:
|
||||
if msg.Command == "PRIVMSG" {
|
||||
cmd := strings.Split(msg.Trailing, " ")[0]
|
||||
if MSGCallbacks[cmd] != nil {
|
||||
go MSGCallbacks[cmd](output, msg)
|
||||
}
|
||||
}
|
||||
if Callbacks[msg.Command] != nil {
|
||||
go Callbacks[msg.Command](output, msg)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package bot
|
||||
|
||||
import (
|
||||
"github.com/arachnist/gorepost/irc"
|
||||
)
|
||||
|
||||
func papiez(output chan irc.Message, msg irc.Message) {
|
||||
output <- irc.Message{
|
||||
Command: "PRIVMSG",
|
||||
Params: []string{msg.Prefix.Name},
|
||||
Trailing: "pingity pong",
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
AddMSGCallback(":ping", papiez)
|
||||
}
|
Loading…
Reference in New Issue