This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
/
main.go
102 lines (78 loc) · 2.19 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
101
102
package main
import (
"github.com/sirupsen/logrus"
"github.com/go-telegram-bot-api/telegram-bot-api"
r "gopkg.in/gorethink/gorethink.v3"
"os"
"strings"
)
var log = logrus.New()
var (
bot *tgbotapi.BotAPI
session *r.Session
dbPKPrefix = "tg:"
)
func main() {
log.Formatter = new(logrus.TextFormatter)
log.Info("OverStatsTelegram 1.0 started!")
var err error
token := os.Getenv("TOKEN")
if token == "" {
log.Fatal("TOKEN env variable not specified!")
}
bot, err = tgbotapi.NewBotAPI(token)
if err != nil {
log.Fatal(err)
}
// Database pool init
go InitConnectionPool()
// Debug log
bot.Debug = false
log.Infof("authorized on account @%s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := bot.GetUpdatesChan(u)
for update := range updates {
if update.Message == nil {
continue
}
// userId for logger
commandLogger := log.WithFields(logrus.Fields{"user_id": update.Message.From.ID})
if strings.HasPrefix(update.Message.Text, "/setchat") {
commandLogger.Info("command /setchat triggered")
go SetChatCommand(update)
}
if strings.HasPrefix(update.Message.Text, "/consoletop") {
commandLogger.Info("command /consoletop triggered")
go RatingTopCommand(update, "console")
}
if strings.HasPrefix(update.Message.Text, "/pctop") {
commandLogger.Info("command /pctop triggered")
go RatingTopCommand(update, "pc")
}
// Skip all commands from groups and supergroups
if update.Message.Chat.ID != int64(update.Message.From.ID) {
continue
}
if strings.HasPrefix(update.Message.Text, "/start") {
commandLogger.Info("command /start triggered")
go StartCommand(update)
}
if strings.HasPrefix(update.Message.Text, "/donate") {
commandLogger.Info("command /donate triggered")
go DonateCommand(update)
}
if strings.HasPrefix(update.Message.Text, "/save") {
commandLogger.Info("command /save triggered")
go SaveCommand(update)
}
if strings.HasPrefix(update.Message.Text, "/me") {
commandLogger.Info("command /me triggered")
go MeCommand(update)
}
if strings.HasPrefix(update.Message.Text, "/h_") {
commandLogger.Info("command /h_ triggered")
go HeroCommand(update)
}
}
}