-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (34 loc) · 974 Bytes
/
Copy pathmain.go
File metadata and controls
44 lines (34 loc) · 974 Bytes
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
package main
//go:generate go run github.com/AshokShau/gotdbot/scripts/tools
import (
"log"
"strconv"
"github.com/AshokShau/gotdbot"
)
func main() {
apiID, err := strconv.Atoi(ApiId)
if err != nil {
log.Fatalln(err)
}
bot, err := gotdbot.NewClient(int32(apiID), ApiHash, Token, &gotdbot.ClientOpts{
LibraryPath: "./libtdjson.so.1.8.66",
})
if err != nil {
log.Fatalf("Failed to create bot client: %v", err)
}
bot.OnCommand("eval", evalCommandHandler)
bot.OnCommand("debug", debugCommandHandler)
bot.AddHandler(&catchAllHandler{fn: printJsonHandler})
err = bot.Start()
if err != nil {
log.Fatalf("Failed to start bot: %v", err)
}
bot.Idle()
}
type catchAllHandler struct {
fn func(*gotdbot.Client, gotdbot.TlObject) error
}
func (h *catchAllHandler) CheckUpdate(_ *gotdbot.Client, _ gotdbot.TlObject) bool { return true }
func (h *catchAllHandler) HandleUpdate(c *gotdbot.Client, update gotdbot.TlObject) error {
return h.fn(c, update)
}