forked from botlabs-gg/yagpdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invites.go
52 lines (40 loc) · 1.5 KB
/
invites.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
package common
import (
"regexp"
)
type InviteSource struct {
Name string
Regex *regexp.Regexp
}
var DiscordInviteSource = &InviteSource{
Name: "Discord",
Regex: regexp.MustCompile(`(discord\.gg|discordapp\.com\/invite)(?:\/#)?\/([a-zA-Z0-9-]+)`),
}
var ThirdpartyDiscordSites = []*InviteSource{
&InviteSource{Name: "discord.me", Regex: regexp.MustCompile(`discord\.me\/.+`)},
&InviteSource{Name: "invite.gg", Regex: regexp.MustCompile(`invite\.gg\/.+`)},
&InviteSource{Name: "discord.io", Regex: regexp.MustCompile(`discord\.io\/.+`)},
&InviteSource{Name: "disboard.org", Regex: regexp.MustCompile(`disboard\.org\/server\/join\/.+`)},
&InviteSource{Name: "discordy.com", Regex: regexp.MustCompile(`discordy\.com\/server\.php`)},
// regexp.MustCompile(`disco\.gg\/.+`), Youc can't actually link to specific servers here can you, so not needed for now?
}
var AllInviteSources = append([]*InviteSource{DiscordInviteSource}, ThirdpartyDiscordSites...)
func ReplaceServerInvites(msg string, guildID int64, replacement string) string {
for _, s := range AllInviteSources {
msg = s.Regex.ReplaceAllString(msg, replacement)
}
return msg
}
func ContainsInvite(s string, checkDiscordSource, checkThirdPartySources bool) *InviteSource {
for _, source := range AllInviteSources {
if source == DiscordInviteSource && !checkDiscordSource {
continue
} else if source != DiscordInviteSource && !checkThirdPartySources {
continue
}
if source.Regex.MatchString(s) {
return source
}
}
return nil
}