-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (44 loc) · 1.27 KB
/
main.go
File metadata and controls
57 lines (44 loc) · 1.27 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
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
package main
//go:generate go run github.com/AshokShau/gotdbot/scripts/tools
import (
"log"
"strconv"
"github.com/AshokShau/gotdbot"
"github.com/AshokShau/gotdbot/handlers"
)
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.64",
})
if err != nil {
log.Fatalf("Failed to create bot client: %v", err)
}
setupHandlers(bot.Dispatcher)
err = bot.Start()
if err != nil {
log.Fatalf("Failed to start bot: %v", err)
}
me := bot.Me
username := ""
if me.Usernames != nil {
username = me.Usernames.EditableUsername
}
bot.Logger.Info("Logged in", "username", username, "id", me.Id)
bot.Idle()
}
type catchAllHandler struct {
fn func(*gotdbot.Client, *gotdbot.Context) error
}
func (h *catchAllHandler) CheckUpdate(_ *gotdbot.Client, _ *gotdbot.Context) bool { return true }
func (h *catchAllHandler) HandleUpdate(c *gotdbot.Client, ctx *gotdbot.Context) error {
return h.fn(c, ctx)
}
func setupHandlers(d *gotdbot.Dispatcher) {
d.AddHandler(handlers.NewCommand("eval", evalCommandHandler))
d.AddHandler(handlers.NewCommand("debug", debugCommandHandler))
d.AddHandlerToGroup(&catchAllHandler{fn: printJsonHandler}, 0)
}