Skip to content

Commit

Permalink
Disable "display links"
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed Apr 3, 2024
1 parent 108aeda commit 094d83a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions cmd/bot/main.go
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/signal"
"path/filepath"
"regexp"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -380,6 +381,51 @@ func (a *App) onMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
}
}

// Remove messages containing "display links"
linkRegex := regexp.MustCompile(`\[(.*?)\]\((https?://\S+)\)`)
matches := linkRegex.FindAllStringSubmatch(m.Message.Content, -1)
if len(matches) > 0 {
hasAccess, err := utils.MemberInRoles(s, m.GuildID, m.Author.ID, "minimod")
if err != nil {
fmt.Println("Error:", err)
return
}
if !hasAccess {
err := s.ChannelMessageDelete(m.Message.ChannelID, m.Message.ID)
if err != nil {
fmt.Println("Error deleting message")
}
embed := &discordgo.MessageEmbed{
Title: "Message deleted because it contained a link with a different display text",
}
payload := fmt.Sprintf("<@%s> - Name: %s#%s - ID: %s", m.Author.ID, m.Author.Username, m.Author.Discriminator, m.Author.ID)
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
Name: "Author",
Value: payload,
Inline: true,
})
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
Name: "Content",
Value: strings.Replace(m.Content, "`", "", -1),
Inline: true,
})
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
Name: "Channel",
Value: "<#" + m.ChannelID + ">",
Inline: true,
})

targetChannel := serverconfig.Get(m.GuildID, "channel:action-log")
if targetChannel == "" {
fmt.Println("No channel set up for moderation actions")
return
}

s.ChannelMessageSendEmbed(targetChannel, embed)
return
}
}

for _, a := range m.Message.Attachments {
attachmentsMutex.Lock()
attachments[m.Message.ID] = append(attachments[m.Message.ID], a)
Expand Down
1 change: 1 addition & 0 deletions tools.go
@@ -1,3 +1,4 @@
//go:build tools
// +build tools

package tools
Expand Down

0 comments on commit 094d83a

Please sign in to comment.