Exemple #1
0
func main() {
	config, err := pit.Get("guiniol")
	if err != nil {
		log.Fatal(err)
	}

	conn := guiniol.NewConnection(config["slack.token"])
	conn.RegisterCb(Wrap(EchoCallback))
	conn.Loop()
}
Exemple #2
0
func New(token string) *Connection {
	conn := &Connection{
		connection: guiniol.NewConnection(token),
		actionMap:  map[string]action{},
	}
	conn.AddAction("help", "this message", func(e *Event) error {
		args := e.Command().Args()
		if 0 < len(args) {
			var doc bytes.Buffer
			if v, ok := conn.actionMap[args[0]]; ok {
				if err := v.help.Execute(&doc, e); err != nil {
					return err
				}
				m := "```\n"
				m += fmt.Sprintf("%s --- %s\n", args[0], doc.String())
				m += "```"
				e.Reply(m)
			} else {
				e.Reply(fmt.Sprintf("command not found: %s", args[0]))
			}
			return nil
		}

		m := "command list\n```"
		for k, v := range conn.actionMap {
			var doc bytes.Buffer
			if err := v.help.Execute(&doc, e); err != nil {
				return err
			}
			m += fmt.Sprintf("    %s --- %s\n", k, doc.String())
		}
		m += "```"
		e.Reply(m)
		return nil
	})
	return conn
}