-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathrole_reapplicator.go
More file actions
44 lines (39 loc) · 936 Bytes
/
role_reapplicator.go
File metadata and controls
44 lines (39 loc) · 936 Bytes
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
package main
import (
"io/ioutil"
"log"
"net/http"
"os"
"github.com/bwmarrin/discordgo"
)
// note: this is not for mutes. rekt does that
// this is for roles determined by the central db
func onUserJoin3(s *discordgo.Session, m *discordgo.GuildMemberAdd) {
if m.GuildID != impactServer {
return
}
if shouldGiveDonator(m.User.ID) {
err := discord.GuildMemberRoleAdd(impactServer, m.User.ID, Donator.ID)
if err != nil {
log.Println(err)
}
}
}
func shouldGiveDonator(discordID string) bool {
url := "https://api.impactclient.net/v1/integration/impactbot/checkdonator/" + discordID + "?auth=" + os.Getenv("IMPACTBOT_AUTH_SECRET")
return isYes(url)
}
func isYes(url string) bool {
resp, err := http.Get(url)
if err != nil {
log.Println(err)
return false
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println(err)
return false
}
return string(data) == "yes"
}