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 fieldsFunc(s victor.State) { var fStr string for _, f := range s.Fields() { fStr += f + "\n" } s.Chat().Send(s.Message().Channel().ID(), fStr) }
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 (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)) } }
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 (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 } }
// 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) }
func defaultFunc(s victor.State) { s.Chat().Send(s.Message().Channel().ID(), "Unrecognized command. Type `help` to see supported commands.") }
func thanksFunc(s victor.State) { msg := fmt.Sprintf("You're welcome %s!", s.Message().User().Name()) s.Chat().Send(s.Message().Channel().ID(), msg) }
func echoFunc(s victor.State) { s.Chat().Send(s.Message().Channel().ID(), s.Message().Text()) }
func byeFunc(s victor.State) { msg := fmt.Sprintf("Bye %s!", s.Message().User().Name()) s.Chat().Send(s.Message().Channel().ID(), msg) }
func fieldsFunc(s victor.State) { for _, f := range s.Fields() { s.Chat().Send(s.Message().Channel().ID(), f) } }