-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebhook.go
121 lines (97 loc) · 3.07 KB
/
webhook.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package webhooks
import (
"example.com/Quaver/Z/config"
"fmt"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/webhook"
"log"
"time"
)
var (
AntiCheat webhook.Client
PrivateChat webhook.Client
)
const QuaverLogo string = "https://i.imgur.com/DkJhqvT.jpg"
const antiCheatDescription string = "**❌ Anti-cheat Triggered!**"
func Initialize() {
hooks := []string{
config.Instance.DiscordWebhooks.AntiCheat,
config.Instance.DiscordWebhooks.PrivateChat,
}
for _, hook := range hooks {
if hook == "" {
continue
}
var err error
switch hook {
case config.Instance.DiscordWebhooks.AntiCheat:
AntiCheat, err = webhook.NewWithURL(hook)
case config.Instance.DiscordWebhooks.PrivateChat:
PrivateChat, err = webhook.NewWithURL(hook)
}
if err != nil {
panic(err)
}
log.Printf("Initialized Webhook: %v\n", hook)
}
}
func SendAntiCheat(username string, userId int, url string, icon string, reason string, text string) {
if AntiCheat == nil {
log.Printf("Cannot send nil Anti-Cheat webhook\n")
return
}
viewProfile := fmt.Sprintf("[View Profile](%v)", url)
banUser := fmt.Sprintf("[Ban User](https://a.quavergame.com/ban/%v)", userId)
editUser := fmt.Sprintf("[Edit User](https://a.quavergame.com/edituser/%v)", userId)
embed := discord.NewEmbedBuilder().
SetAuthor(username, url, icon).
SetDescription(antiCheatDescription).
SetFields(discord.EmbedField{
Name: reason,
Value: text,
}, discord.EmbedField{
Name: "Admin Actions",
Value: fmt.Sprintf("%v | %v | %v", viewProfile, banUser, editUser),
Inline: nil,
}).
SetThumbnail(QuaverLogo).
SetFooter("Quaver", QuaverLogo).
SetTimestamp(time.Now()).
SetColor(0xFF0000).
Build()
_, err := AntiCheat.CreateEmbeds([]discord.Embed{embed})
if err != nil {
log.Printf("Failed to send anti-cheat webhook: %v\n", err)
}
}
func SendAntiCheatProcessLog(username string, userId int, url string, icon string, processes []string) {
formatted := ""
for i, proc := range processes {
formatted += fmt.Sprintf("**%v. %v**\n", i+1, proc)
}
SendAntiCheat(username, userId, url, icon, "Detected Processes", formatted)
}
func SendAntiCheatLibraries(username string, userId int, url string, icon string, libraries []string) {
formatted := ""
for i, library := range libraries {
formatted += fmt.Sprintf("**%v. %v**\n", i+1, library)
}
SendAntiCheat(username, userId, url, icon, "Detected Libraries", formatted)
}
// SendChatMessage Sends a chat message webhook to Discord
func SendChatMessage(webhook webhook.Client, senderUsername string, senderProfileUrl string, senderAvatarUrl, receiverName string, message string) {
if webhook == nil {
return
}
embed := discord.NewEmbedBuilder().
SetAuthor(fmt.Sprintf("%v → %v", senderUsername, receiverName), senderProfileUrl, senderAvatarUrl).
SetDescription(message).
SetFooter("Quaver", QuaverLogo).
SetTimestamp(time.Now()).
SetColor(0x00FFFF).
Build()
_, err := webhook.CreateEmbeds([]discord.Embed{embed})
if err != nil {
log.Printf("Failed to send webhook to channel: %v - %v\n", receiverName, err)
}
}