-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (64 loc) · 1.87 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
//+build !test
// Copyright 2020 the commonlispbr authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"strings"
)
func main() {
setupLogging()
bot, botHidden, err := setupBots()
botUser := bot.Self.UserName
if err != nil {
log.Fatal(err.Error())
}
kills := loadKills(killsFile)
log.Printf("Currently kill state: %v", kills)
for update := range getUpdates(bot) {
if messageEvent(&update) {
// Exit automatically from group after the bot receive a message from it
for _, trollGroup := range trollGroups {
if fromChatEvent(&update, strings.TrimLeft(trollGroup, "@")) {
leaveChat(bot, &update, trollGroup)
}
}
}
if commandEvent(&update) {
msg := update.Message.Text
if checkCommand(botUser, msg, "/ping") {
reply(bot, &update, "Estou vivo.")
}
if checkCommand(botUser, msg, "/kills") {
reportKills(bot, &update, kills)
}
if checkCommand(botUser, msg, "/pass") && fromAdminEvent(&update) {
addPassList(bot, &update)
}
}
if newChatMemberEvent(&update) {
for _, member := range *update.Message.NewChatMembers {
if pass, ok := hasPass(member); ok {
removePassList(bot, &update, pass)
welcomeMessage(bot, &update, member)
continue
}
if trollHouse := findTrollHouses(botHidden, member.ID); trollHouse != "" {
err := kickTroll(bot, &update, member, trollHouse)
if err == nil {
kills++
if err := saveKills(killsFile, kills); err != nil {
log.Printf("saving kills failed: %v", err)
}
}
}
// Exit automatically from groups when I'm joining it
for _, trollGroup := range trollGroups {
if fromChatEvent(&update, strings.TrimLeft(trollGroup, "@")) && member.UserName == bot.Self.UserName {
leaveChat(bot, &update, trollGroup)
}
}
}
}
}
}