-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmain.go
More file actions
60 lines (54 loc) · 1.66 KB
/
main.go
File metadata and controls
60 lines (54 loc) · 1.66 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
58
59
60
// Channel Bot
// Copyright (C) 2021 Reeshuxd (@itsreeshu)
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
package main
import (
"fmt"
"net/http"
"github.com/PaulSonOfLars/gotgbot/v2"
"github.com/PaulSonOfLars/gotgbot/v2/ext"
"github.com/PaulSonOfLars/gotgbot/v2/ext/handlers"
"github.com/Reeshuxd/ChannelBot/plugs"
)
func main() {
b, err := gotgbot.NewBot(TOKEN, &gotgbot.BotOpts{
Client: http.Client{},
GetTimeout: gotgbot.DefaultGetTimeout,
PostTimeout: gotgbot.DefaultPostTimeout,
})
if err != nil {
fmt.Println(fmt.Sprintf("Error: %v", err.Error()))
}
updater := ext.NewUpdater(&ext.UpdaterOpts{
ErrorLog: nil,
DispatcherOpts: ext.DispatcherOpts{
Error: func(b *gotgbot.Bot, ctx *ext.Context, err error) ext.DispatcherAction {
fmt.Println("an error occurred while handling update:", err.Error())
return ext.DispatcherActionNoop
},
Panic: nil,
ErrorLog: nil,
MaxRoutines: 0,
},
})
dispatcher := updater.Dispatcher
dispatcher.AddHandler(handlers.NewCommand("start", plugs.Start))
dispatcher.AddHandler(handlers.NewCommand("unban", plugs.UnBan))
dispatcher.AddHandler(
handlers.NewMessage(
func(msg *gotgbot.Message) bool {
return msg.GetSender().IsAnonymousChannel()
},
plugs.Detector,
),
)
erro := updater.StartPolling(b, &ext.PollingOpts{DropPendingUpdates: true})
if erro != nil {
fmt.Println("Failed:" + err.Error())
}
fmt.Printf("Succesfully Started Bot!")
updater.Idle()
}