本文整理匯總了Golang中github.com/FogCreek/victor.State類的典型用法代碼示例。如果您正苦於以下問題:Golang State類的具體用法?Golang State怎麽用?Golang State使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了State類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: fieldsFunc
func fieldsFunc(s victor.State) {
var fStr string
for _, f := range s.Fields() {
fStr += f + "\n"
}
s.Chat().Send(s.Message().Channel().ID(), fStr)
}
示例2: scheduleFunc
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
}
}
示例3: phoneLineReply
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))
}
}
示例4: autopkgFunc
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())
}
示例5: phoneLine
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)
}
示例6: rotationFunc
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)
}
示例7: handleFunc
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))
}
示例8: byeFunc
// 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)
}
示例9: helloFunc
// 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)
}
示例10: defaultFunc
func defaultFunc(s victor.State) {
s.Chat().Send(s.Message().Channel().ID(),
"Unrecognized command. Type `help` to see supported commands.")
}
示例11: thanksFunc
func thanksFunc(s victor.State) {
msg := fmt.Sprintf("You're welcome %s!", s.Message().User().Name())
s.Chat().Send(s.Message().Channel().ID(), msg)
}
示例12: echoFunc
func echoFunc(s victor.State) {
s.Chat().Send(s.Message().Channel().ID(), s.Message().Text())
}
示例13: byeFunc
func byeFunc(s victor.State) {
msg := fmt.Sprintf("Bye %s!", s.Message().User().Name())
s.Chat().Send(s.Message().Channel().ID(), msg)
}
示例14: warrantyFunc
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)
}
示例15: fieldsFunc
func fieldsFunc(s victor.State) {
for _, f := range s.Fields() {
s.Chat().Send(s.Message().Channel().ID(), f)
}
}