-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.go
100 lines (93 loc) · 2.6 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"flag"
"os"
"time"
"github.com/anonyindian/logger"
"github.com/celestix/gotgproto"
"github.com/celestix/gotgproto/dispatcher/handlers"
"github.com/celestix/gotgproto/dispatcher/handlers/filters"
"github.com/celestix/gotgproto/generic"
"github.com/gigauserbot/giga/bot/helpmaker"
"github.com/gigauserbot/giga/config"
"github.com/gigauserbot/giga/db"
"github.com/gigauserbot/giga/modules"
"github.com/gigauserbot/giga/utils"
"github.com/gotd/td/telegram/dcs"
"github.com/gotd/td/tg"
)
var (
delay = flag.Int("delay", 0, "")
restartChatId = flag.Int("chat", 0, "")
restartMsgId = flag.Int("msg_id", 0, "")
restartMsgText = flag.String("msg_text", "", "")
)
func main() {
flag.Parse()
l := logger.New(os.Stderr, &logger.LoggerOpts{
ProjectName: "GIGA-USERBOT",
})
if *restartMsgId != 0 {
// Clean Console
os.Stderr.Write([]byte("\n"))
}
if *delay != 0 {
l.Println("Delaying start for", *delay, "seconds")
time.Sleep(time.Second * time.Duration(*delay))
}
if config.DEBUG {
l.ChangeMinimumLevel(logger.LevelDebug)
}
utils.InitUpdate(l)
config.Load(l)
handlers.DefaultPrefix = []rune{'.', '$'}
db.Load(l)
runClient(l)
}
func runClient(l *logger.Logger) {
log := l.Create("CLIENT")
client, err := gotgproto.NewClient(
// Get AppID from https://my.telegram.org/apps
config.ValueOf.AppId,
// Get ApiHash from https://my.telegram.org/apps
config.ValueOf.ApiHash,
// ClientType, as we defined above
gotgproto.ClientTypePhone(""),
// Optional parameters of client
&gotgproto.ClientOpts{
Session: config.GetSession(),
DisableCopyright: true,
DCList: func() (dct dcs.List) {
if config.ValueOf.TestServer {
dct = dcs.Test()
}
return
}(),
},
)
if err != nil {
log.Fatalln("failed to start client:", err)
}
log.ChangeLevel(logger.LevelInfo).Println("STARTED")
utils.TelegramClient = client.Client
config.Self = client.Self
dispatcher := client.Dispatcher
dispatcher.AddHandlerToGroup(handlers.NewMessage(filters.Message.Text, utils.GetBotToken(l)), 2)
ctx := client.CreateContext()
if *restartMsgId == 0 && *restartMsgText == "" {
utils.StartupAutomations(l, ctx, client)
} else {
generic.EditMessage(ctx, *restartChatId, &tg.MessagesEditMessageRequest{
ID: *restartMsgId,
Message: *restartMsgText,
})
}
// Modules shall not be loaded unless the setup is complete
modules.Load(l, dispatcher)
helpmaker.MakeHelp()
if config.ValueOf.TestServer {
l.ChangeLevel(logger.LevelMain).Println("RUNNING ON TEST SERVER")
}
l.ChangeLevel(logger.LevelMain).Println("GIGA HAS BEEN STARTED")
client.Idle()
}