Esempio n. 1
0
File: echo.go Progetto: mix3/guiniol
func EchoCallback(c context.Context, e *guiniol.EventCtx) {
	e.Reply(fmt.Sprintf(
		"@%s echo %s\n%s",
		e.UserIdToName(e.MessageEvent().User),
		Message(c),
		e.Permalink(),
	))
}
Esempio n. 2
0
func matcher(e *guiniol.EventCtx) (string, string) {
	t := e.MessageEvent().Text
	if m := pattern2.FindStringSubmatch(t); len(m) == 3 {
		return m[1], m[2]
	}
	if m := pattern1.FindStringSubmatch(t); len(m) == 3 {
		return m[1], m[2]
	}
	return "", ""
}
Esempio n. 3
0
func (c *Connection) actionCb(ctx context.Context, eventCtx *guiniol.EventCtx) {
	if eventCtx.MessageEvent().Subtype == "bot_message" {
		return
	}

	name, m := matcher(eventCtx)
	if name != eventCtx.UserName() && name != eventCtx.UserId() {
		return
	}

	e := newEvent(ctx, eventCtx, m)

	if action, ok := c.actionMap[e.Command().Name()]; ok {
		if err := action.fn(e); err != nil {
			e.Reply(err.Error())
		}
	} else {
		e.Reply("???")
	}
}