-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontext_func.go
75 lines (61 loc) · 1.72 KB
/
context_func.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package telebot
import "strings"
func (c *nativeContext) Text() string {
if c.Message() != nil {
text := c.Message().Text
if text != nil {
return *text
}
return ""
}
return ""
}
func (c *nativeContext) ReplyTo(msg Message, text string, options ...any) (Message, error) {
chat, id := msg.MessageSig()
for _, o := range options {
switch o.(type) {
case *ReplyParameters, ReplyParameters:
panic("telebot: cannot use ReplyTo with ReplyParameters")
}
}
options = append(options, &ReplyParameters{
MessageID: id,
ChatID: chat,
})
return c.b.SendMessage(chat, text, options...)
}
func (c *nativeContext) Reply(text string, options ...any) (Message, error) {
return c.ReplyTo(c.Message(), text, options...)
}
func (c *nativeContext) Send(s any, options ...any) (Message, error) {
chat, _ := c.Message().MessageSig()
switch x := s.(type) {
case string:
return c.b.SendMessage(chat, x, options...)
case Sendable:
return x.Send(c.b, chat, options...)
}
panic("telebot: invalid Sendable type")
}
func (c *nativeContext) Edit(text string, options ...any) (Message, error) {
return c.b.EditMessageText(c.Message(), text, options...)
}
func (c *nativeContext) EditOrReply(text string, options ...any) (Message, error) {
if c.Callback() == nil {
return c.Reply(text, options...)
}
return c.Edit(text, options...)
}
func (c *nativeContext) Args() []string {
var args []string
if c.Callback() != nil {
args = append(args, strings.Split(c.Callback().Data, "|")...)
return args
}
if c.Message() != nil {
args = append(args, c.Message().Payload)
args = append(args, strings.Split(strings.ReplaceAll(c.Text(), c.Message().Command+" "+c.Message().Payload, " "), " ")...)
return args
}
return args
}