Browse Source

Adds ability to configure blacklisted danbooru tags

master
Noah Pederson 10 months ago
parent
commit
541da36a49
2 changed files with 12 additions and 5 deletions
  1. +5
    -3
      commands/commands.go
  2. +7
    -2
      config/config.go

+ 5
- 3
commands/commands.go View File

@ -44,15 +44,17 @@ func danbooruSearch(s *discordgo.Session, c *discordgo.Message, tags []string, r
return
}
query := strings.Split(c.Content, " ")[1:]
query = append(query, tags...)
queryTags := strings.Split(c.Content, " ")[1:]
query := append(queryTags, tags...)
//Add blacklisted tags
query = append(query, cfg.DanbooruConfig.BlacklistedTags...)
post, err := danbooru.SearchPost(query)
messageContent := ""
if err != nil || tags == nil || post.LargeFileUrl == "" {
log.Printf("Unable to retrieve an image")
messageContent = "I'm sorry, I was unable to find any images, <@!" + c.Author.ID + "> senpai."
} else {
messageContent = "I was able to find this for you <@!" + c.Author.ID + "> with tags (" + strings.Join(query, ", ") + ") "
messageContent = "I was able to find this for you <@!" + c.Author.ID + "> with tags (" + strings.Join(queryTags, ", ") + ") "
addCommandEntry(s, c)
}
message_send, err := imageLinkToComplexMessage(post.LargeFileUrl, post.MD5)


+ 7
- 2
config/config.go View File

@ -1,6 +1,7 @@
package config
import (
"fmt"
"github.com/BurntSushi/toml"
"log"
"os"
@ -19,8 +20,9 @@ type appConfig struct {
}
type danbooruConfig struct {
DanbooruUser string
DanbooruKey string
DanbooruUser string
DanbooruKey string
BlacklistedTags []string
}
type redditbooruConfig struct {
@ -45,5 +47,8 @@ func LoadConfig() *ConfigWrapper {
log.Fatal(err)
}
}
for i, v := range cfg.DanbooruConfig.BlacklistedTags {
cfg.DanbooruConfig.BlacklistedTags[i] = fmt.Sprintf("-%s", v)
}
return cfg
}

Loading…
Cancel
Save