50 lines
808 B
Go
50 lines
808 B
Go
// vim:ts=4:sts=4:sw=4:noet:tw=72
|
|
|
|
package modules
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"log"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/sorcix/irc"
|
|
)
|
|
|
|
func init() {
|
|
MsgHandlers["fortune"] = fortuneHandleMessage
|
|
log.Println("Initializing fortune module")
|
|
}
|
|
|
|
func fortuneHandleMessage(m *irc.Message) {
|
|
tok := strings.Split(m.Trailing, " ")
|
|
if len(tok) < 1 {
|
|
return
|
|
}
|
|
switch tok[0] {
|
|
case "!fortune":
|
|
fortune()
|
|
default:
|
|
}
|
|
}
|
|
|
|
func fortune() {
|
|
cmd := exec.Command("/usr/games/fortune", "/flokatirc/fortunes/")
|
|
var out bytes.Buffer
|
|
cmd.Stdout = &out
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
println(err)
|
|
return
|
|
}
|
|
s := out.String()
|
|
s = strings.Replace(s, "\r", "", -1)
|
|
s = strings.Replace(s, "\t", " ", -1)
|
|
for _, l := range strings.Split(s, "\n") {
|
|
if l != "" {
|
|
SayCh <- fmt.Sprintf("*\n%s", l)
|
|
}
|
|
}
|
|
}
|