Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
311497086e | ||
|
|
f41bd63fcd |
+1
-1
@@ -39,7 +39,7 @@ func main() {
|
|||||||
CheckPermissions: false,
|
CheckPermissions: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
dg.AddHandler(messages.OnMessage)
|
dg.AddHandler(messages.CleanAmazonURLs)
|
||||||
|
|
||||||
err = dg.Open()
|
err = dg.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import (
|
|||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OnMessage(s *discordgo.Session, message *discordgo.MessageCreate) {
|
func CleanAmazonURLs(s *discordgo.Session, message *discordgo.MessageCreate) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
log.Println("Recovered from panic in OnMessage")
|
log.Println("Recovered from panic in CleanAmazonURLs")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if message.Author.Bot {
|
if message.Author.Bot {
|
||||||
@@ -28,6 +28,10 @@ func OnMessage(s *discordgo.Session, message *discordgo.MessageCreate) {
|
|||||||
if strings.Contains(url, "ref=") || strings.Contains(url, "?") {
|
if strings.Contains(url, "ref=") || strings.Contains(url, "?") {
|
||||||
parts := strings.Split(url, "/")
|
parts := strings.Split(url, "/")
|
||||||
new := strings.Join(parts[:len(parts)-1], "/")
|
new := strings.Join(parts[:len(parts)-1], "/")
|
||||||
|
if strings.Contains(new, "ref=") {
|
||||||
|
parts = strings.Split(new, "ref=")
|
||||||
|
new = parts[0]
|
||||||
|
}
|
||||||
content = strings.ReplaceAll(content, url, new)
|
content = strings.ReplaceAll(content, url, new)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user