mirror of
https://github.com/get-got/discord-downloader-go.git
synced 2025-10-29 11:37:50 +00:00
Compare commits
5 Commits
deb66cd512
...
02e4ffdd46
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02e4ffdd46 | ||
|
|
e1d3175f3b | ||
|
|
e59ebce987 | ||
|
|
55017ee3b6 | ||
|
|
7083042fd4 |
49
config.go
49
config.go
@ -431,6 +431,9 @@ type configurationSourceFilters struct {
|
||||
BlockedRoles *[]string `json:"blockedRoles,omitempty" yaml:"blockedRoles,omitempty"`
|
||||
AllowedRoles *[]string `json:"allowedRoles,omitempty" yaml:"allowedRoles,omitempty"`
|
||||
|
||||
BlockedLinkContent *[]string `json:"blockedLinkContent,omitempty" yaml:"blockedLinkContent,omitempty"`
|
||||
AllowedLinkContent *[]string `json:"allowedLinkContent,omitempty" yaml:"allowedLinkContent,omitempty"`
|
||||
|
||||
BlockedDomains *[]string `json:"blockedDomains,omitempty" yaml:"blockedDomains,omitempty"`
|
||||
AllowedDomains *[]string `json:"allowedDomains,omitempty" yaml:"allowedDomains,omitempty"`
|
||||
|
||||
@ -1121,11 +1124,53 @@ func sourceDefault(source *configurationSource) {
|
||||
if source.Filters == nil {
|
||||
source.Filters = &configurationSourceFilters{}
|
||||
}
|
||||
if source.Filters.BlockedPhrases == nil && config.Filters.BlockedPhrases != nil {
|
||||
source.Filters.BlockedPhrases = config.Filters.BlockedPhrases
|
||||
}
|
||||
if source.Filters.AllowedPhrases == nil && config.Filters.AllowedPhrases != nil {
|
||||
source.Filters.AllowedPhrases = config.Filters.AllowedPhrases
|
||||
}
|
||||
if source.Filters.BlockedUsers == nil && config.Filters.BlockedUsers != nil {
|
||||
source.Filters.BlockedUsers = config.Filters.BlockedUsers
|
||||
}
|
||||
if source.Filters.AllowedUsers == nil && config.Filters.AllowedUsers != nil {
|
||||
source.Filters.AllowedUsers = config.Filters.AllowedUsers
|
||||
}
|
||||
if source.Filters.BlockedRoles == nil && config.Filters.BlockedRoles != nil {
|
||||
source.Filters.BlockedRoles = config.Filters.BlockedRoles
|
||||
}
|
||||
if source.Filters.AllowedRoles == nil && config.Filters.AllowedRoles != nil {
|
||||
source.Filters.AllowedRoles = config.Filters.AllowedRoles
|
||||
}
|
||||
if source.Filters.BlockedLinkContent == nil && config.Filters.BlockedLinkContent != nil {
|
||||
source.Filters.BlockedLinkContent = config.Filters.BlockedLinkContent
|
||||
}
|
||||
if source.Filters.AllowedLinkContent == nil && config.Filters.AllowedLinkContent != nil {
|
||||
source.Filters.AllowedLinkContent = config.Filters.AllowedLinkContent
|
||||
}
|
||||
if source.Filters.BlockedDomains == nil && config.Filters.BlockedDomains != nil {
|
||||
source.Filters.BlockedDomains = config.Filters.BlockedDomains
|
||||
}
|
||||
if source.Filters.AllowedDomains == nil && config.Filters.AllowedDomains != nil {
|
||||
source.Filters.AllowedDomains = config.Filters.AllowedDomains
|
||||
}
|
||||
if source.Filters.BlockedExtensions == nil && config.Filters.BlockedExtensions != nil {
|
||||
source.Filters.BlockedExtensions = config.Filters.BlockedExtensions
|
||||
}
|
||||
if source.Filters.BlockedPhrases == nil && config.Filters.BlockedPhrases != nil {
|
||||
source.Filters.BlockedPhrases = config.Filters.BlockedPhrases
|
||||
if source.Filters.AllowedExtensions == nil && config.Filters.AllowedExtensions != nil {
|
||||
source.Filters.AllowedExtensions = config.Filters.AllowedExtensions
|
||||
}
|
||||
if source.Filters.BlockedFilenames == nil && config.Filters.BlockedFilenames != nil {
|
||||
source.Filters.BlockedFilenames = config.Filters.BlockedFilenames
|
||||
}
|
||||
if source.Filters.AllowedFilenames == nil && config.Filters.AllowedFilenames != nil {
|
||||
source.Filters.AllowedFilenames = config.Filters.AllowedFilenames
|
||||
}
|
||||
if source.Filters.BlockedReactions == nil && config.Filters.BlockedReactions != nil {
|
||||
source.Filters.BlockedReactions = config.Filters.BlockedReactions
|
||||
}
|
||||
if source.Filters.AllowedReactions == nil && config.Filters.AllowedReactions != nil {
|
||||
source.Filters.AllowedReactions = config.Filters.AllowedReactions
|
||||
}
|
||||
if source.Duplo == nil && config.Duplo {
|
||||
source.Duplo = &config.Duplo
|
||||
|
||||
@ -274,6 +274,8 @@ func dataKeys(input string) string {
|
||||
projectVersion},
|
||||
{"{{apiVersion}}",
|
||||
discordgo.APIVersion},
|
||||
{"{{botUsername}}",
|
||||
clearPathIllegalChars(botUser.Username)},
|
||||
{"{{countNoCommas}}",
|
||||
fmt.Sprint(countInt)},
|
||||
{"{{count}}",
|
||||
@ -465,6 +467,8 @@ func dataKeysDownload(input string, sourceConfig configurationSource, download d
|
||||
{"{{domain}}", domain},
|
||||
{"{{nanoID}}", nanoID},
|
||||
{"{{shortID}}", shortID},
|
||||
{"{{botUsername}}",
|
||||
clearPathIllegalChars(botUser.Username)},
|
||||
}
|
||||
for _, key := range keys {
|
||||
if strings.Contains(ret, key[0]) {
|
||||
@ -498,6 +502,8 @@ func dataKeys_DiscordMessage(input string, m *discordgo.Message) string {
|
||||
{"{{messageID}}", m.ID},
|
||||
{"{{message}}", clearPathIllegalChars(m.Content)},
|
||||
{"{{channelID}}", m.ChannelID},
|
||||
{"{{botUsername}}",
|
||||
clearPathIllegalChars(botUser.Username)},
|
||||
}
|
||||
// Author data if present
|
||||
if m.Author != nil {
|
||||
|
||||
42
handlers.go
42
handlers.go
@ -369,16 +369,55 @@ func handleMessage(m *discordgo.Message, c *discordgo.Channel, edited bool, hist
|
||||
time.Sleep(time.Duration(delay) * time.Millisecond)
|
||||
}
|
||||
|
||||
// Process Files
|
||||
// Process Collected Links
|
||||
var downloadedItems []downloadedItem
|
||||
files := getLinksByMessage(m)
|
||||
for _, file := range files {
|
||||
// Blank link?
|
||||
if file.Link == "" {
|
||||
continue
|
||||
}
|
||||
// Filter Checks
|
||||
shouldAbort := false
|
||||
if sourceConfig.Filters.BlockedLinkContent != nil {
|
||||
for _, phrase := range *sourceConfig.Filters.BlockedLinkContent {
|
||||
if strings.Contains(file.Link, phrase) && phrase != "" {
|
||||
shouldAbort = true
|
||||
if config.Debug {
|
||||
log.Println(lg("Debug", "Message", color.YellowString,
|
||||
"%s blockedLinkContent found \"%s\" in link, planning to abort...",
|
||||
color.HiMagentaString("(FILTER)"), phrase))
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if sourceConfig.Filters.AllowedLinkContent != nil {
|
||||
for _, phrase := range *sourceConfig.Filters.AllowedLinkContent {
|
||||
if strings.Contains(file.Link, phrase) && phrase != "" {
|
||||
shouldAbort = false
|
||||
if config.Debug {
|
||||
log.Println(lg("Debug", "Message", color.YellowString,
|
||||
"%s allowedLinkContent found \"%s\" in link, planning to process...",
|
||||
color.HiMagentaString("(FILTER)"), phrase))
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if shouldAbort {
|
||||
if config.Debug {
|
||||
log.Println(lg("Debug", "Message", color.YellowString,
|
||||
"%s Filter decided to ignore link...",
|
||||
color.HiMagentaString("(FILTER)")))
|
||||
}
|
||||
continue
|
||||
}
|
||||
// Output
|
||||
if config.Debug && (!history || config.MessageOutputHistory) {
|
||||
log.Println(lg("Debug", "Message", color.HiCyanString, "FOUND FILE: "+file.Link+fmt.Sprintf(" \t<%s>", m.ID)))
|
||||
}
|
||||
// Handle Download
|
||||
status, filesize := downloadRequestStruct{
|
||||
InputURL: file.Link,
|
||||
Filename: file.Filename,
|
||||
@ -391,6 +430,7 @@ func handleMessage(m *discordgo.Message, c *discordgo.Channel, edited bool, hist
|
||||
StartTime: time.Now(),
|
||||
AttachmentID: file.AttachmentID,
|
||||
}.handleDownload()
|
||||
// Await Status
|
||||
if status.Status == downloadSuccess {
|
||||
domain, _ := getDomain(file.Link)
|
||||
downloadedItems = append(downloadedItems, downloadedItem{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user