-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.go
97 lines (85 loc) · 2.23 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
package main
import (
"log"
"os"
"github.com/bwmarrin/discordgo"
"github.com/subosito/gotenv"
)
var discord *discordgo.Session
var myselfID string
func init() {
var err error
// You can set environment variables in the git-ignored .env file for convenience while running locally
err = gotenv.Load()
if err == nil {
println("Loaded .env file")
} else if os.IsNotExist(err) {
println("No .env file found")
err = nil // Mutating state is bad mkay
} else {
panic(err)
}
token := os.Getenv("DISCORD_BOT_TOKEN")
if token == "" {
panic("Must set environment variable DISCORD_BOT_TOKEN")
}
log.Println("Establishing discord connection")
discord, err = discordgo.New("Bot " + token)
if err != nil {
panic(err)
}
discord.Identify.Intents = discordgo.MakeIntent(discordgo.IntentsGuildMembers | discordgo.IntentsAllWithoutPrivileged)
user, err := discord.User("@me")
if err != nil {
panic(err)
}
myselfID = user.ID
log.Println("I am", myselfID)
discord.AddHandler(onUserJoin)
discord.AddHandler(onMessageSent)
discord.AddHandler(onMessageReactedTo)
discord.AddHandler(onReady)
discord.AddHandler(onMessageSent2)
discord.AddHandler(onMessageSentCommandHandler)
discord.AddHandler(onUserJoin2)
discord.AddHandler(onVoiceStateUpdate)
discord.AddHandler(onUserJoin3)
discord.AddHandler(onReady2)
discord.AddHandler(onGuildMemberUpdate)
discord.AddHandler(onMessageEdited)
}
func main() {
err := discord.Open()
if err != nil {
panic(err)
}
log.Println("Connected to discord")
forever := make(chan int)
<-forever
}
func onReady(discord *discordgo.Session, ready *discordgo.Ready) {
err := discord.UpdateStatusComplex(discordgo.UpdateStatusData{
IdleSince: nil,
Activities: []*discordgo.Activity{{
Name: "the Impact Discord",
Type: 3,
}},
AFK: false,
Status: "",
})
if err != nil {
log.Println("Error attempting to set my status")
log.Println(err)
}
servers := discord.State.Guilds
log.Printf("Impcat bot has started on %d servers:", len(servers))
for _, guild := range servers {
log.Println("Server ID", guild.ID)
fullGuild, err := discord.Guild(guild.ID)
if err == nil {
log.Println("Full server ID", fullGuild.ID, "Full name", fullGuild.Name)
}
}
// Replace rules message
updateRules()
}