Compare commits

...

2 Commits

4 changed files with 64 additions and 17 deletions

View File

@ -145,10 +145,12 @@ func defaultConfiguration() configuration {
StickersFilenameFormat: "{{ID}} {{name}}",
// Source Setup Defaults
Save: true,
AllowCommands: true,
ScanEdits: true,
IgnoreBots: true,
Save: true,
AllowCommands: true,
ScanEdits: true,
IgnoreBots: true,
IgnoreEmojis: true,
IgnoreStickers: true,
SendErrorMessages: false,
SendFileToChannel: "",
@ -266,6 +268,9 @@ type configuration struct {
DownloadTimeout int `json:"downloadTimeout" yaml:"downloadTimeout"`
DownloadRetryMax int `json:"downloadRetryMax" yaml:"downloadRetryMax"`
SendErrorMessages bool `json:"sendErrorMessages" yaml:"sendErrorMessages"`
IgnoreEmojis bool `json:"ignoreEmojis" yaml:"ignoreEmojis"`
IgnoreStickers bool `json:"ignoreStickers" yaml:"ignoreStickers"`
IgnoreEmojisWEBP *bool `json:"ignoreEmojisWEBP" yaml:"ignoreEmojisWEBP"`
// Discord Emojis & Stickers
EmojisServers *[]string `json:"emojisServers" yaml:"emojisServers"`
@ -373,12 +378,14 @@ type configurationSource struct {
Aliases *[]string `json:"aliases,omitempty" yaml:"aliases,omitempty"`
// Setup
Enabled *bool `json:"enabled" yaml:"enabled"`
Save *bool `json:"save" yaml:"save"`
AllowCommands *bool `json:"allowCommands" yaml:"allowCommands"`
ScanEdits *bool `json:"scanEdits" yaml:"scanEdits"`
IgnoreBots *bool `json:"ignoreBots" yaml:"ignoreBots"`
CommandPrefix *string `json:"commandPrefix" yaml:"commandPrefix"`
Enabled *bool `json:"enabled" yaml:"enabled"`
Save *bool `json:"save" yaml:"save"`
AllowCommands *bool `json:"allowCommands" yaml:"allowCommands"`
ScanEdits *bool `json:"scanEdits" yaml:"scanEdits"`
IgnoreBots *bool `json:"ignoreBots" yaml:"ignoreBots"`
CommandPrefix *string `json:"commandPrefix" yaml:"commandPrefix"`
IgnoreEmojis *bool `json:"ignoreEmojis" yaml:"ignoreEmojis"`
IgnoreStickers *bool `json:"ignoreStickers" yaml:"ignoreStickers"`
SendErrorMessages *bool `json:"sendErrorMessages" yaml:"sendErrorMessages"`
SendFileToChannel *string `json:"sendFileToChannel" yaml:"sendFileToChannel"`
@ -1022,6 +1029,12 @@ func sourceDefault(source *configurationSource) {
if source.IgnoreBots == nil {
source.IgnoreBots = &config.IgnoreBots
}
if source.IgnoreEmojis == nil {
source.IgnoreEmojis = &config.IgnoreEmojis
}
if source.IgnoreStickers == nil {
source.IgnoreStickers = &config.IgnoreStickers
}
if source.SendErrorMessages == nil {
source.SendErrorMessages = &config.SendErrorMessages

View File

@ -482,12 +482,6 @@ func getParsedLinks(inputURL string, m *discordgo.Message) map[string]string {
}
}
// Ignore Discord emojis / stickers
if strings.HasPrefix(inputURL, "https://cdn.discordapp.com/emojis/") ||
strings.HasPrefix(inputURL, "https://media.discordapp.net/stickers/") {
return nil
}
// Try without queries
/*parsedURL, err := url.Parse(inputURL)
if err == nil {
@ -527,6 +521,42 @@ func getLinksByMessage(m *discordgo.Message) []*fileItem {
}
}
// Scrape Emojis from message
for _, emoji := range m.GetCustomEmojis() {
emojisWEBP := false
if config.IgnoreEmojisWEBP != nil {
emojisWEBP = *config.IgnoreEmojisWEBP
}
link := "https://cdn.discordapp.com/emojis/" + emoji.ID + ".png"
if emojisWEBP {
link = "https://cdn.discordapp.com/emojis/" + emoji.ID + ".webp"
}
if emoji.Animated {
link = "https://cdn.discordapp.com/emojis/" + emoji.ID + ".gif"
if emojisWEBP {
link = "https://cdn.discordapp.com/emojis/" + emoji.ID + ".webp?animated=true"
}
}
fileItems = append(fileItems, &fileItem{
Link: link,
Filename: "Emoji " + emoji.Name,
Time: linkTime,
AttachmentID: "",
})
}
// Scrape Stickers from message
for _, sticker := range m.StickerItems {
fileItems = append(fileItems, &fileItem{
Link: "https://media.discordapp.net/stickers/" + sticker.ID + ".png",
Filename: "Sticker " + sticker.Name,
Time: linkTime,
AttachmentID: "",
})
}
return trimDuplicateLinks(fileItems)
}

View File

@ -391,6 +391,10 @@ func handleMessage(m *discordgo.Message, c *discordgo.Channel, edited bool, hist
if file.Link == "" {
continue
}
if (*sourceConfig.IgnoreEmojis && strings.HasPrefix(file.Link, "https://cdn.discordapp.com/emojis/")) ||
(*sourceConfig.IgnoreStickers && strings.HasPrefix(file.Link, "https://media.discordapp.net/stickers/")) {
continue
}
// Filter Checks
shouldAbort := false
if sourceConfig.Filters.BlockedLinkContent != nil {

View File

@ -10,7 +10,7 @@ var (
projectRepoBase = "get-got/discord-downloader-go"
projectRepoURL = "https://github.com/" + projectRepoBase
projectIcon = "https://cdn.discordapp.com/icons/780985109608005703/9dc25f1b91e6d92664590254e0797fad.webp?size=256"
projectVersion = "2.5.4-dev" // follows Semantic Versioning, (http://semver.org/)
projectVersion = "2.6.0-dev" // follows Semantic Versioning, (http://semver.org/)
pathCache = "cache"
pathCacheHistory = pathCache + string(os.PathSeparator) + "history"