Exemplo n.º 1
0
func fieldsFunc(s victor.State) {
	var fStr string
	for _, f := range s.Fields() {
		fStr += f + "\n"
	}
	s.Chat().Send(s.Message().Channel().ID(), fStr)
}
Exemplo n.º 2
0
func (a Veracross) scheduleFunc(s victor.State) {
	name := s.Fields()
	if len(name) < 2 {
		msg := "You must enter a first and last name as arguments"
		s.Chat().Send(s.Message().Channel().ID(), msg)
		return
	}

	schedules, err := a.getSchedule()
	if err != nil {
		log.Println(err)
		return
	}
	for _, schedule := range *schedules {
		if schedule.First != name[0] {
			continue
		}
		if schedule.Last != name[1] {
			continue
		}
		s.Chat().Send(s.Message().Channel().ID(), schedule.First+" "+schedule.Last+":\n"+schedule.ScheduleView)
		return
	}
}
Exemplo n.º 3
0
func (c Phone) phoneLineReply(s victor.State, name string, line bool) {
	subscribers, err := c.phones()
	if err != nil {
		s.Chat().Send(s.Message().Channel().ID(), fmt.Sprintf("ERROR: `%s`", err))
		log.Println(err)
	}

	phones := subscribers.Find(name)
	for _, phone := range phones {
		var msg string
		if line {
			msg = fmt.Sprintf("%v %v", phone.Name.Name, phone.DirectoryNumber.Line)
		} else {
			msg = fmt.Sprintf("%v %v", phone.Name.Name, phone.IntercomDialingCode.Extension)
		}
		s.Chat().Send(s.Message().Channel().ID(), fmt.Sprintf("%v", msg))
	}
}
Exemplo n.º 4
0
func (a Autopkg) autopkgFunc(s victor.State) {
	autopkgCmd := exec.Command(a.Path)
	for _, arg := range s.Fields() {
		autopkgCmd.Args = append(autopkgCmd.Args, arg)
	}
	var out bytes.Buffer
	autopkgCmd.Stdout = &out
	err := autopkgCmd.Run()
	if err != nil {
		log.Println(err)
	}
	s.Chat().Send(s.Message().Channel().ID(), out.String())
}
Exemplo n.º 5
0
func (c Phone) phoneLine(s victor.State) {
	var line bool
	phoneFlagSet := flag.NewFlagSet("phone", flag.ExitOnError)
	phoneFlagSet.BoolVar(&line, "line", false, "")
	phoneFlagSet.Parse(s.Fields())
	args := phoneFlagSet.Args()
	name := strings.Join(args, " ")
	if len(args) == 0 {
		msg := "You must add a name after the `phone` command."
		s.Chat().Send(s.Message().Channel().ID(), msg)
		return
	}
	c.phoneLineReply(s, name, line)

}
Exemplo n.º 6
0
func (a VeracrossAPI) rotationFunc(s victor.State) {
	var date time.Time
	var err error
	input := strings.Join(s.Fields(), " ")
	switch input {
	case "today":
		date = time.Now()
	case "tomorrow":
		date = time.Now().Add(24 * time.Hour)
	default:
		date, err = time.Parse(vcapi.VCTimeFormat, input)
		if err != nil {
			log.Println(err)
		}
	}
	rotation, err := a.getRotation(&date)
	if err != nil {
		log.Println(err)
	}
	s.Chat().Send(s.Message().Channel().ID(), rotation.Description)
}
Exemplo n.º 7
0
func (p rpcPlugin) handleFunc(s victor.State) {
	// args is the argument sent to the plugin.
	type Args struct {
		// Chat user calling the plugin.
		User string
		// The arguments a user passes to the bot.
		Fields []string
	}
	args := &Args{User: s.Message().User().Name(), Fields: s.Fields()}

	var msg string
	// start a new client.
	err := p.newClient()
	if err != nil {
		log.Fatal(err)
	}
	defer p.client.Close()
	err = p.client.Call(fmt.Sprintf("%v.Handle", p.name), args, &msg)
	if err != nil {
		log.Println(err)
		msg = fmt.Sprintf("Plugin encountered an error, %v", err)
	}
	s.Reply(string(msg))
}
Exemplo n.º 8
0
// another handler for the hello plugin
func (h Hello) byeFunc(s victor.State) {
	msg := fmt.Sprintf("Bye %s!", s.Message().User().Name())
	s.Reply(msg)
}
Exemplo n.º 9
0
// Bot Handler
// write your plugin logic here.
func (h Hello) helloFunc(s victor.State) {
	msg := fmt.Sprintf("Hello %s!", s.Message().User().Name())
	s.Chat().Send(s.Message().Channel().ID(), msg)
}
Exemplo n.º 10
0
func defaultFunc(s victor.State) {
	s.Chat().Send(s.Message().Channel().ID(),
		"Unrecognized command. Type `help` to see supported commands.")
}
Exemplo n.º 11
0
func thanksFunc(s victor.State) {
	msg := fmt.Sprintf("You're welcome %s!", s.Message().User().Name())
	s.Chat().Send(s.Message().Channel().ID(), msg)
}
Exemplo n.º 12
0
func echoFunc(s victor.State) {
	s.Chat().Send(s.Message().Channel().ID(), s.Message().Text())
}
Exemplo n.º 13
0
func byeFunc(s victor.State) {
	msg := fmt.Sprintf("Bye %s!", s.Message().User().Name())
	s.Chat().Send(s.Message().Channel().ID(), msg)
}
Exemplo n.º 14
0
func (w Warranty) warrantyFunc(s victor.State) {
	warrantyCmd := exec.Command(w.Path, "--quit-on-error")

	// only accept 1 serial number in chat
	if len(s.Fields()) > 1 {
		msg := "Please only input one serial number at a time."
		s.Chat().Send(s.Message().Channel().ID(), msg)
		return
	}

	for _, arg := range s.Fields() {
		warrantyCmd.Args = append(warrantyCmd.Args, arg)
	}

	var stdout bytes.Buffer
	var stderr bytes.Buffer
	warrantyCmd.Stdout = &stdout
	warrantyCmd.Stderr = &stderr
	err := warrantyCmd.Run()
	if err != nil {
		log.Println(err)
	}

	// Combine output and wrap stdout in code tags.
	output := fmt.Sprintf("```%s```\n%s", stdout.String(), stderr.String())

	// Send output and stderr to chat.
	s.Chat().Send(s.Message().Channel().ID(), output)
}
Exemplo n.º 15
0
func fieldsFunc(s victor.State) {
	for _, f := range s.Fields() {
		s.Chat().Send(s.Message().Channel().ID(), f)
	}
}