func (ag *Routing) Do(ctx coa.Context) error { mctx := ctx.(*ctxs.MsgContext) msg := ag.GetMsg() for ptn, agSource := range commandPatterns { if ptn.Match([]byte(msg.Text)) { log.ActionGRP("==> ", reflect.TypeOf(agSource)) newMctx := ctxs.NewMsgContext(agSource, msg, mctx.RTM, mctx.Client) return newMctx.Exec() } } log.ActionGRP("==> send registered msg") newMctx := ctxs.NewMsgContext(ags.SendRegisteredMsg{}, msg, mctx.RTM, mctx.Client) return newMctx.Exec() }
func HandleMsg( ev *slack.MessageEvent, rtm *slack.RTM, client *slack.Client, ) { msg := msg.NewMsg(ev) mctx := ctxs.NewMsgContext(Routing{}, msg, rtm, client) mctx.Exec() }
func Init(rtm *slack.RTM, client *slack.Client) { c := cron.New() for _, agSource := range crons { s := agSource.(HasSchedule).Schedule() if s != "" { _agSource := agSource c.AddFunc(s, func() { log.ActionGRP(reflect.TypeOf(_agSource).Name) ctxs.NewMsgContext(_agSource, nil, rtm, client).Exec() }) } } c.Start() for { select {} } }