-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
104 lines (90 loc) · 2.34 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
103
104
package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/prim69/fbi-bot/commands"
"github.com/prim69/fbi-bot/utils/settings"
"os"
"os/signal"
"syscall"
)
func main() {
dg, err := discordgo.New("Bot " + settings.Data.Token)
if err != nil {
panic(err)
}
dg.AddHandler(onMessageDelete)
dg.AddHandler(onMessageUpdate)
commands.RegisterAll(dg)
dg.Identify.Intents = discordgo.IntentsGuilds | discordgo.IntentsGuildMessages | discordgo.IntentsGuildMembers | discordgo.IntentsGuildPresences
if err := dg.Open(); err != nil {
panic(err)
}
dg.State.MaxMessageCount = 30000
_ = dg.UpdateListeningStatus("moans")
fmt.Println("FBI Bot is now running!")
c := make(chan os.Signal, 2)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-c
settings.Data.DisabledCommands = commands.GetHandler().GetCommandMap().GetDisabled()
settings.Save()
os.Exit(0)
}()
select {}
}
func onMessageDelete(_ *discordgo.Session, msg *discordgo.MessageDelete) {
b := msg.BeforeDelete
if b == nil {
return
}
var attachment *discordgo.MessageAttachment
if len(b.Attachments) > 0 {
attachment = b.Attachments[0]
}
var list []*commands.SnipedMessage
list = append(list, &commands.SnipedMessage{
Content: b.Content,
Author: b.Author,
ChannelID: b.ChannelID,
ID: b.ID,
Timestamp: b.Timestamp,
Attachment: attachment,
})
for _, value := range commands.Snipes[b.ChannelID] {
list = append(list, value)
}
if len(list) > settings.Data.SnipeLimit {
commands.Snipes[b.ChannelID] = list[:settings.Data.SnipeLimit]
} else {
commands.Snipes[b.ChannelID] = list
}
}
func onMessageUpdate(_ *discordgo.Session, msg *discordgo.MessageUpdate) {
b := msg.BeforeUpdate
if b == nil {
return
}
var attachment *discordgo.MessageAttachment
if len(b.Attachments) > 0 {
attachment = b.Attachments[0]
}
var list []*commands.SnipedMessage
list = append(list, &commands.SnipedMessage{
Content: b.Content,
NewContent: msg.Content,
Author: b.Author,
ChannelID: b.ChannelID,
ID: b.ID,
Timestamp: b.Timestamp,
Attachment: attachment,
})
for _, value := range commands.EditSnipes[b.ChannelID] {
list = append(list, value)
}
if len(list) > settings.Data.SnipeLimit {
commands.EditSnipes[b.ChannelID] = list[:settings.Data.SnipeLimit]
} else {
commands.EditSnipes[b.ChannelID] = list
}
}