Beispiel #1
0
func (cmd *AuthCommand) Parse(msg msgsystem.Message) bool {
	channel := msg.To
	m := strings.Split(msg.Msg, " ")
	command := m[0]
	params := strings.Join(m[1:], " ")

	switch command {
	case "!auth":
		if len(params) > 0 && !strings.HasPrefix(channel[0], "#") {
			r := msgsystem.Message{
				To: []string{msg.Source},
			}

			if auth.Auth(msg.Source, params) {
				r.Msg = "Auth succeeded!"
			} else {
				r.Msg = "Auth failed!"
			}

			cmd.messagesOut <- r
		} else {
			r := msgsystem.Message{
				To:  channel,
				Msg: "Usage in private query only: !auth password",
			}
			cmd.messagesOut <- r
		}
		return true
	}
	return false
}
Beispiel #2
0
func (cmd *AliasCommand) Parse(msg msgsystem.Message) bool {
	channel := msg.To
	m := strings.Split(msg.Msg, " ")
	command := m[0]
	params := strings.Join(m[1:], " ")

	switch command {
	case "!alias":
		if !msg.Authed {
			r := msgsystem.Message{
				To:  channel,
				Msg: "Security breach. Talk to ircflu admin!",
			}
			cmd.messagesOut <- r
			return true
		}

		a := strings.Split(params, "=")
		if len(a) == 2 {
			a[0] = strings.TrimSpace(a[0])
			a[1] = strings.TrimSpace(a[1])
			cmd.aliases[a[0]] = a[1]
			r := msgsystem.Message{
				To:  channel,
				Msg: "Added new alias '" + a[0] + "' for command '" + a[1] + "'",
			}
			cmd.messagesOut <- r
		} else {
			r := msgsystem.Message{
				To:  channel,
				Msg: "Usage: !alias [new command] = [actual command]",
			}
			cmd.messagesOut <- r

			for k, v := range cmd.aliases {
				r.Msg = "Alias: " + irctools.Colored(k, "red") + " = " + irctools.Colored(v, "teal")
				cmd.messagesOut <- r
			}
		}

		return true

	default:
		v, ok := cmd.aliases[strings.TrimSpace(msg.Msg)[1:]]
		if ok {
			fmt.Println("Alias:", v, strings.TrimSpace(msg.Msg), ok)
			r := msgsystem.Message{
				To:     channel,
				Source: msg.Source,
				Authed: msg.Authed,
				Msg:    "!" + v,
			}
			cmd.messagesIn <- r

			return true
		}
	}

	return false
}
Beispiel #3
0
func (cmd *ExecCommand) Parse(msg msgsystem.Message) bool {
	channel := msg.To
	m := strings.Split(msg.Msg, " ")
	command := m[0]
	params := strings.TrimSpace(strings.Join(m[1:], " "))

	switch command {
	case "!exec":
		if !msg.Authed || strings.Index(params, "rm ") >= 0 || strings.Index(params, "mv ") >= 0 {
			r := msgsystem.Message{
				To:  channel,
				Msg: "Security breach. Talk to ircflu admin!",
			}
			cmd.messagesOut <- r
			return true
		}

		if len(params) > 0 {
			r := msgsystem.Message{
				To:  channel,
				Msg: irctools.Colored("Executing command!", "red"),
			}
			cmd.messagesOut <- r

			c := strings.Split(params, " ")
			e := exec.Command(c[0], c[1:]...)
			out, err := e.CombinedOutput()
			fmt.Println("Output:", string(out))
			fmt.Println("Error:", err)

			r = msgsystem.Message{
				To: []string{msg.Source},
			}
			if err != nil {
				r.Msg = "Command '" + params + "' failed: " + err.Error()
			} else {
				r.Msg = "Command '" + params + "' succeeded!"
			}

			cmd.messagesOut <- r
		} else {
			r := msgsystem.Message{
				To:  channel,
				Msg: "Usage: !exec [command]",
			}
			cmd.messagesOut <- r
		}

		return true
	}

	return false
}