forked from gotd/botapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext.go
More file actions
30 lines (26 loc) · 1.08 KB
/
Copy pathtext.go
File metadata and controls
30 lines (26 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import (
"github.com/gotd/botapi"
)
// registerText wires free-text handlers that aren't commands or button taps:
// a greeting matched by a case-insensitive regex, an echo for any other text,
// and an edited-message notice. Handler registration order matters — the first
// matching handler wins — so the specific predicates come before the catch-all.
func registerText(bot *botapi.Bot) {
// Greet on "hi" / "hello" / "hey".
bot.OnMessage(func(c *botapi.Context) error {
_, err := c.Reply("Hello, " + displayName(c.Sender()) + "! 👋")
return err
}, botapi.Regex(`(?i)^(hi|hello|hey)\b`))
// Echo any other non-command text. Not(HasPrefix("/")) skips commands so they
// fall through to their OnCommand handlers.
bot.OnMessage(func(c *botapi.Context) error {
_, err := c.Reply("You said: " + c.Message().Text)
return err
}, botapi.HasText(), botapi.Not(botapi.HasPrefix("/")))
// Notice when a user edits one of their messages.
bot.OnEditedMessage(func(c *botapi.Context) error {
_, err := c.Reply("👀 I noticed you edited a message.")
return err
})
}