-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
62 lines (50 loc) · 1.25 KB
/
main.go
File metadata and controls
62 lines (50 loc) · 1.25 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
61
62
package main
import (
"io"
"log"
"main/modules"
"main/modules/db"
"net/http"
"os"
"strconv"
tg "github.com/amarnathcjd/gogram/telegram"
_ "github.com/joho/godotenv/autoload"
_ "net/http/pprof"
)
var ownerId int64 = 0
var LoadModules = os.Getenv("ENV") != "development"
func main() {
logZap, err := os.OpenFile("log.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatal(err)
}
defer logZap.Close()
wr := io.MultiWriter(os.Stdout, logZap)
appId, _ := strconv.Atoi(os.Getenv("APP_ID"))
ownerId, _ = strconv.ParseInt(os.Getenv("OWNER_ID"), 10, 64)
client, err := tg.NewClient(tg.ClientConfig{
//Session: "userxyz",
AppID: int32(appId),
AppHash: os.Getenv("APP_HASH"),
LogLevel: tg.LogInfo,
})
if err != nil {
panic(err)
}
client.Conn()
client.Log.SetOutput(wr)
client.LoginBot(os.Getenv("BOT_TOKEN"))
client.Logger.Info("Bot is running as @%s", client.Me().Username)
go func() {
log.Println("Pprof server starting on :9009")
if err := http.ListenAndServe(":9009", nil); err != nil {
log.Printf("Pprof server error: %v", err)
}
}()
modules.InitClient(client)
modules.SetupFilters(ownerId, LoadModules)
modules.RegisterHandlers()
client.Idle()
db.CloseDB()
client.Logger.Info("Bot stopped")
}