func fieldsFunc(s victor.State) { var fStr string for _, f := range s.Fields() { fStr += f + "\n" } s.Chat().Send(s.Message().Channel().ID(), fStr) }
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) }
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()) }
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) }
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) }
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)) }
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 } }
func fieldsFunc(s victor.State) { for _, f := range s.Fields() { s.Chat().Send(s.Message().Channel().ID(), f) } }