Skip to content

Commit

Permalink
Support Whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
lb-migii committed May 1, 2023
1 parent 692820e commit 2fffd61
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
9 changes: 5 additions & 4 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ db:
guild:
prefix: p.
lang: japanese
domain_blacklist:
- "google.com"
- "letmegooglethat.com"
- "discord.com"
domain:
type: white
list:
- "twitter.com"
- "youtube.com"
user_blacklist:
- "0000000000000000000" # Add here to ignore user at all
channel_blacklist:
Expand Down
24 changes: 19 additions & 5 deletions lib/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,23 @@ type Config struct {
Parameter string
Tableprefix string
}
Guild Guild
DomainBlacklist []string `yaml:"domain_blacklist"`
UserBlacklist []string `yaml:"user_blacklist"`
Guild Guild
Domain struct {
Type string
YamlList []string `yaml:"list"`
}
UserBlacklist []string `yaml:"user_blacklist"`
ChannelBlacklist []string `yaml:"channel_blacklist"`
LogPeriod int64 `yaml:"log_period"`
LogPeriod int64 `yaml:"log_period"`
}

type Guild struct {
Prefix string
Lang string
}

var ListMap map[string]bool

const configFile = "./config.yml"

var CurrentConfig Config
Expand All @@ -61,8 +66,17 @@ func init() {
if CurrentConfig.Db.Tableprefix == "" {
log.Fatal("Tableprefix is empty")
}
if CurrentConfig.Domain.Type != "white" && CurrentConfig.Domain.Type != "black" {
log.Fatal("Domain type is invalid")
}
if CurrentConfig.LogPeriod == 0 {
log.Print("LogPeriod is empty, setting 31536000")
CurrentConfig.LogPeriod = 2592000
log.Print("LogPeriod is empty, setting to 2592000")
}

ListMap = make(map[string]bool)
for _, item := range CurrentConfig.Domain.YamlList {
ListMap[item] = true
}

loadLang()
Expand Down
10 changes: 8 additions & 2 deletions lib/handler/url_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ url_loop:
if err != nil {
log.Panic("Invalid URL: ", rawUrl)
}
for _, v := range config.CurrentConfig.DomainBlacklist {
if strings.Contains(Url.Host, v) {
list := config.ListMap
switch config.CurrentConfig.Domain.Type {
case "black":
if list[Url.Host] {
continue url_loop
}
case "white":
if !list[Url.Host] {
continue url_loop
}
}
Expand Down

0 comments on commit 2fffd61

Please sign in to comment.