-
Notifications
You must be signed in to change notification settings - Fork 21
/
optout.go
55 lines (46 loc) · 2.02 KB
/
optout.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
package main
import (
"errors"
"fmt"
"strings"
"github.com/bwmarrin/discordgo"
)
func optOutHandler(caller *discordgo.Member, msg *discordgo.Message, args []string) (err error) {
if len(args) < 2 || strings.ToLower(strings.Join(args[1:], " ")) != "i am sure" {
return fmt.Errorf("You will be **kicked from this server** (or **banned** if you are a weeb) and **lose your roles** by continuing. Are you sure you want to opt out? `%s%s %s`", prefix, args[0], "i am sure")
}
if DB == nil {
return errors.New("Unable to connect to database")
}
// Delete anything referencing them
_, err = DB.Exec(`DELETE FROM mutes WHERE discord_id = $1`, caller.User.ID)
if err != nil {
return fmt.Errorf("We were unable to clear your info. Please contact a moderator.\nError: %s", err.Error())
}
// Check if they're muted
var muted bool
for _, role := range muteRoles {
if hasRole(caller, Role{ID: role}) {
muted = true
break
}
}
// If muted ban, if not kick
if muted {
// Send them a DM before banning
_ = SendDM(caller.User.ID, "We appreciate you opting out. We have deleted any data we had stored about you. You have been banned from the server to prevent bypassing our moderation system.")
// We have to ban them or they could bypass a mute
err = discord.GuildBanCreateWithReason(impactServer, caller.User.ID, "opted out of tos", 0)
if err != nil {
return fmt.Errorf("We were unable to ban you. Please contact a moderator.\nError: %s", err.Error())
}
} else {
// Send them a DM before kicking
_ = SendDM(caller.User.ID, "Thank you for opting out. We have deleted any data we had stored about you and kicked you from the server.")
err = discord.GuildMemberDeleteWithReason(impactServer, caller.User.ID, "opted out of tos")
if err != nil {
return fmt.Errorf("We were unable to kick you. Please contact a moderator.\nError: %s", err.Error())
}
}
return resp(msg.ChannelID, fmt.Sprintf("User @%s#%s has opted out and been banned to prevent mute bypassing", caller.User.Username, caller.User.Discriminator))
}