func SelfHandler(Conn *xmpp.Conn, Msg *xmpp.ClientMessage) { Msg.Body = strings.TrimSpace(Msg.Body) if !strings.HasPrefix(Msg.Body, "!") { Conn.Send(room, "groupchat", Msg.Body) return } command, err := GetCommand(Msg.Body, Msg.From, "./plugins/") if err != nil { Conn.Send(Msg.From, "chat", err.Error()) return } out, err := command.CombinedOutput() if err != nil { log.Println(err) Conn.Send(Msg.From, "chat", err.Error()) return } Conn.Send(Msg.From, "chat", strings.TrimRight(string(out), " \t\n")) }
func MessageHandler(Conn *xmpp.Conn, Msg *xmpp.ClientMessage) { switch { case strings.HasPrefix(Msg.Body, "!megakick "): s := strings.Split(Msg.Body, "!megakick ") if in(admin, Msg.From) { Conn.ModUse(room, s[1], "none", "") } else { Conn.Send(room, "groupchat", fmt.Sprintf("%s: GTFO", GetNick(Msg.From))) } case strings.HasPrefix(Msg.Body, "!"): //any external command cmd, err := GetCommand(Msg.Body, Msg.From, "./plugins/") if err != nil { Conn.Send(room, "groupchat", fmt.Sprintf("%s: WAT", GetNick(Msg.From))) if in(admin, Msg.From) { Conn.Send(Msg.From, "chat", err.Error()) } return } stdout, _ := cmd.StdoutPipe() stderr, _ := cmd.StderrPipe() if err := cmd.Start(); err != nil { log.Println(err) Conn.Send(room, "groupchat", fmt.Sprintf("%s: WAT", GetNick(Msg.From))) if in(admin, Msg.From) { Conn.Send(Msg.From, "chat", err.Error()) } return } out, _ := ioutil.ReadAll(stdout) outerr, _ := ioutil.ReadAll(stderr) cmd.Wait() if len(outerr) != 0 && in(admin, Msg.From) { Conn.Send(Msg.From, "chat", strings.TrimRight(string(outerr), " \t\n")) } Conn.Send(room, "groupchat", strings.TrimRight(string(out), " \t\n")) case call.MatchString(Msg.Body): //chat command, err := GetCommand(call.ReplaceAllString(Msg.Body, "!answer"), Msg.From, "./chat/") if err != nil { log.Println(err) return } out, err := command.CombinedOutput() if err != nil { log.Println(err) if in(admin, Msg.From) { Conn.Send(Msg.From, "chat", err.Error()) } return } Conn.Send(room, "groupchat", strings.TrimRight(string(out), " \t\n")) } }