-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
64 lines (54 loc) · 1.65 KB
/
main.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
package main
import (
"github.com/AshokShau/Assistant/Assistant/config"
"github.com/AshokShau/Assistant/Assistant/modules"
"log"
"net/http"
"time"
"github.com/PaulSonOfLars/gotgbot/v2"
"github.com/PaulSonOfLars/gotgbot/v2/ext"
"github.com/PaulSonOfLars/gotgbot/v2/ext/handlers"
"github.com/PaulSonOfLars/gotgbot/v2/ext/handlers/filters/message"
)
func main() {
if config.Token == "" {
log.Fatalf("TOKEN is not set in the environment variables")
}
b, err := gotgbot.NewBot(config.Token, &gotgbot.BotOpts{
BotClient: &gotgbot.BaseBotClient{
Client: http.Client{},
DefaultRequestOpts: &gotgbot.RequestOpts{
Timeout: gotgbot.DefaultTimeout,
APIURL: gotgbot.DefaultAPIURL,
},
},
})
if err != nil {
log.Fatalf("failed to create bot: %s", err)
}
dispatcher := ext.NewDispatcher(&ext.DispatcherOpts{
Error: func(b *gotgbot.Bot, ctx *ext.Context, err error) ext.DispatcherAction {
log.Println("an error occurred while handling update:", err.Error())
return ext.DispatcherActionNoop
},
MaxRoutines: ext.DefaultMaxRoutines,
})
updater := ext.NewUpdater(dispatcher, nil)
dispatcher.AddHandler(handlers.NewCommand("start", modules.Start))
dispatcher.AddHandler(handlers.NewMessage(message.All, modules.PmMessage))
err = updater.StartPolling(b, &ext.PollingOpts{
DropPendingUpdates: true,
GetUpdatesOpts: &gotgbot.GetUpdatesOpts{
Timeout: 9,
RequestOpts: &gotgbot.RequestOpts{
Timeout: time.Second * 10,
},
},
})
if err != nil {
log.Fatalf("failed to start polling: %s", err)
}
log.Printf("%s has been started...\n", b.User.Username)
// Idle, to keep updates coming in, and avoid bot stopping.
updater.Idle()
}