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)) }
// 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) }