tea-cleaner: Make no login period configurable
This commit is contained in:
@ -37,6 +37,7 @@ data ConfigFile = ConfigFile
|
||||
, server :: StrictText
|
||||
, spamWords :: [StrictText]
|
||||
, mailDomains :: [StrictText]
|
||||
, noLogin :: Word
|
||||
} deriving (Eq, Show)
|
||||
|
||||
configFileCodec :: Toml.TomlCodec ConfigFile
|
||||
@ -45,6 +46,7 @@ configFileCodec = ConfigFile
|
||||
<*> Toml.text "server" .= getField @"server"
|
||||
<*> Toml.arrayOf Toml._Text "spam_words" .= getField @"spamWords"
|
||||
<*> Toml.arrayOf Toml._Text "mail_domains" .= getField @"mailDomains"
|
||||
<*> Toml.word "no_login" .= getField @"noLogin"
|
||||
|
||||
data Settings = Settings
|
||||
{ token :: StrictText
|
||||
@ -53,6 +55,7 @@ data Settings = Settings
|
||||
, spamWords :: [StrictText]
|
||||
, mailDomains :: [StrictText]
|
||||
, statistics :: IORef Int
|
||||
, noLogin :: Word
|
||||
} deriving Eq
|
||||
|
||||
decodeSettingsFile :: FilePath -> IO Settings
|
||||
@ -67,11 +70,12 @@ decodeSettingsFile configPath = do
|
||||
, now = now
|
||||
, spamWords = spamWords
|
||||
, mailDomains = mailDomains
|
||||
, noLogin = noLogin
|
||||
, statistics = ioRef
|
||||
}
|
||||
|
||||
newtype ProgramOptions = ProgramOptions
|
||||
{ liveRun :: Bool
|
||||
{ live :: Bool
|
||||
} deriving (Eq, Show)
|
||||
|
||||
commandLineInfo :: ParserInfo ProgramOptions
|
||||
@ -80,6 +84,4 @@ commandLineInfo = info (commandLine <**> helper)
|
||||
|
||||
commandLine :: Parser ProgramOptions
|
||||
commandLine = ProgramOptions
|
||||
<$> liveRunOption
|
||||
where
|
||||
liveRunOption = switch $ long "live-run" <> help "Purge suspicious users"
|
||||
<$> switch (long "live" <> help "Purge suspicious users")
|
||||
|
@ -48,8 +48,9 @@ filterByUserProperties settings user@User{ created, lastLogin }
|
||||
= not (Text.null $ getField @"description" user)
|
||||
&& not (Text.null $ getField @"website" user)
|
||||
noLoginSinceRegistration =
|
||||
let monthAgo = utctDay $ addUTCTime (-2592000) $ getField @"now" settings
|
||||
in zonedDay created < monthAgo && zonedDay created == zonedDay lastLogin
|
||||
let period = fromIntegral (getField @"noLogin" settings) * (-3600) * 24
|
||||
periodAgo = utctDay $ addUTCTime period $ getField @"now" settings
|
||||
in zonedDay created < periodAgo && zonedDay created == zonedDay lastLogin
|
||||
zonedDay = localDay . zonedTimeToLocalTime
|
||||
|
||||
filterByActivities :: Settings -> User -> IO FilterResult
|
||||
|
Reference in New Issue
Block a user