Beispiel #1
0
func SelfHandler(Conn *xmpp.Conn, Msg *xmpp.ClientMessage) {
	Msg.Body = strings.TrimSpace(Msg.Body)
	Conn.Send(room, "groupchat", Msg.Body)
	if Msg.From == me+"/gsend" {
		return
	}
	Strip(&Msg.Body, &Msg.From)
	if err := exec.Command("bash", "-c", GetCommand("!"+Msg.Body, Msg.From, "./func/")).Run(); err != nil {
		log.Println(err)
		return
	}
}
Beispiel #2
0
func MessageHandler(Conn *xmpp.Conn, Msg *xmpp.ClientMessage) {
	Msg.Body = strings.TrimSpace(Msg.Body)
	f := func(s string, s2 *string) bool {
		ok, _ := regexp.MatchString(s, *s2)
		return ok
	}
	switch {
	case f("^\\!megakick", &Msg.Body):
		Strip(&Msg.Body, &Msg.From)
		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 f("^\\!", &Msg.Body): //any external command
		Strip(&Msg.Body, &Msg.From)
		cmd := exec.Command("bash", "-c", GetCommand(Msg.Body, Msg.From, "./plugins/"))
		stdout, _ := cmd.StdoutPipe()
		stderr, _ := cmd.StderrPipe()
		if err := cmd.Start(); err != nil {
			log.Println(err)
			return
		}
		out, _ := ioutil.ReadAll(stdout)
		outerr, _ := ioutil.ReadAll(stderr)
		if err := cmd.Wait(); err != nil {
			if err.Error() == "exit status 127" {
				Conn.Send(room, "groupchat", fmt.Sprintf("%s: WAT", GetNick(Msg.From)))
				return
			}
		}
		if len(outerr) != 0 && in(admin, Msg.From) {
			Conn.Send(Msg.From, "chat", string(outerr))
		}
		Conn.Send(room, "groupchat", strings.TrimRight(string(out), " \n"))
	case f("^"+name, &Msg.Body): //chat
		Strip(&Msg.Body, &Msg.From)
		r, _ := regexp.Compile("^\\./chat/" + name + "[:,]")
		command := r.ReplaceAllString(GetCommand("!"+Msg.Body, Msg.From, "./chat/"), "./chat/answer")
		out, err := exec.Command("bash", "-c", command).CombinedOutput()
		if err != nil {
			log.Println(err)
			return
		}
		Conn.Send(room, "groupchat", strings.TrimRight(string(out), " \n"))
	}
}