1
0
Fork 0
forked from External/ergo

Merge pull request #1496 from slingamn/jointime.1

fix #1490
This commit is contained in:
Shivaram Lingamneni 2021-01-21 01:20:45 -05:00 committed by GitHub
commit 2e7cf3cc1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 274 additions and 92 deletions

View file

@ -62,6 +62,45 @@ type listenerConfigBlock struct {
HideSTS bool `yaml:"hide-sts"`
}
type HistoryCutoff uint
const (
HistoryCutoffDefault HistoryCutoff = iota
HistoryCutoffNone
HistoryCutoffRegistrationTime
HistoryCutoffJoinTime
)
func historyCutoffToString(restriction HistoryCutoff) string {
switch restriction {
case HistoryCutoffDefault:
return "default"
case HistoryCutoffNone:
return "none"
case HistoryCutoffRegistrationTime:
return "registration-time"
case HistoryCutoffJoinTime:
return "join-time"
default:
return ""
}
}
func historyCutoffFromString(str string) (result HistoryCutoff, err error) {
switch strings.ToLower(str) {
case "default":
return HistoryCutoffDefault, nil
case "none", "disabled", "off", "false":
return HistoryCutoffNone, nil
case "registration-time":
return HistoryCutoffRegistrationTime, nil
case "join-time":
return HistoryCutoffJoinTime, nil
default:
return HistoryCutoffDefault, errInvalidParams
}
}
type PersistentStatus uint
const (
@ -615,9 +654,12 @@ type Config struct {
ChathistoryMax int `yaml:"chathistory-maxmessages"`
ZNCMax int `yaml:"znc-maxmessages"`
Restrictions struct {
ExpireTime custime.Duration `yaml:"expire-time"`
EnforceRegistrationDate bool `yaml:"enforce-registration-date"`
GracePeriod custime.Duration `yaml:"grace-period"`
ExpireTime custime.Duration `yaml:"expire-time"`
// legacy key, superceded by QueryCutoff:
EnforceRegistrationDate_ bool `yaml:"enforce-registration-date"`
QueryCutoff string `yaml:"query-cutoff"`
queryCutoff HistoryCutoff
GracePeriod custime.Duration `yaml:"grace-period"`
}
Persistent struct {
Enabled bool
@ -1358,6 +1400,19 @@ func LoadConfig(filename string) (config *Config, err error) {
config.History.ZNCMax = config.History.ChathistoryMax
}
if config.History.Restrictions.QueryCutoff != "" {
config.History.Restrictions.queryCutoff, err = historyCutoffFromString(config.History.Restrictions.QueryCutoff)
if err != nil {
return nil, fmt.Errorf("invalid value of history.query-restrictions: %w", err)
}
} else {
if config.History.Restrictions.EnforceRegistrationDate_ {
config.History.Restrictions.queryCutoff = HistoryCutoffRegistrationTime
} else {
config.History.Restrictions.queryCutoff = HistoryCutoffNone
}
}
config.Roleplay.addSuffix = utils.BoolDefaultTrue(config.Roleplay.AddSuffix)
config.Datastore.MySQL.ExpireTime = time.Duration(config.History.Restrictions.ExpireTime)