aboutsummaryrefslogtreecommitdiff
path: root/tea-cleaner/TeaCleaner/Configuration.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-06-29 15:10:26 +0200
committerEugen Wissner <belka@caraus.de>2026-06-29 15:10:26 +0200
commit5cb4767698cf5b15906fad1d43ac0cfb5ec76ff4 (patch)
tree39038f6777ad9adebca0a9e0ba5a19843e8760be /tea-cleaner/TeaCleaner/Configuration.hs
parent620038356a50f30459820833fdf3a38250c6cbf9 (diff)
downloadkazbek-master.tar.gz
Remove tea-cleanerHEADmaster
Since I do not use gitea anymore and cannot maintain the compatibility with the new versions.
Diffstat (limited to 'tea-cleaner/TeaCleaner/Configuration.hs')
-rw-r--r--tea-cleaner/TeaCleaner/Configuration.hs87
1 files changed, 0 insertions, 87 deletions
diff --git a/tea-cleaner/TeaCleaner/Configuration.hs b/tea-cleaner/TeaCleaner/Configuration.hs
deleted file mode 100644
index b958264..0000000
--- a/tea-cleaner/TeaCleaner/Configuration.hs
+++ /dev/null
@@ -1,87 +0,0 @@
-{- This Source Code Form is subject to the terms of the Mozilla Public License,
- v. 2.0. If a copy of the MPL was not distributed with this file, You can
- obtain one at https://mozilla.org/MPL/2.0/. -}
-
-module TeaCleaner.Configuration
- ( ProgramOptions(..)
- , Settings(..)
- , decodeSettingsFile
- , commandLineInfo
- , execParser
- ) where
-
-import GHC.Records (HasField(..))
-import Data.Text (StrictText)
-import qualified Toml
-import Toml ((.=))
-import Options.Applicative
- ( Parser
- , ParserInfo
- , (<**>)
- , execParser
- , fullDesc
- , help
- , helper
- , info
- , long
- , progDesc
- , switch
- )
-import Text.URI (URI)
-import qualified Text.URI as URI
-import Data.Time (UTCTime(..), getCurrentTime)
-import Data.IORef (IORef, newIORef)
-
-data ConfigFile = ConfigFile
- { token :: StrictText
- , server :: StrictText
- , spamWords :: [StrictText]
- , mailDomains :: [StrictText]
- , noLogin :: Word
- } deriving (Eq, Show)
-
-configFileCodec :: Toml.TomlCodec ConfigFile
-configFileCodec = ConfigFile
- <$> Toml.text "token" .= getField @"token"
- <*> 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
- , server :: URI
- , now :: UTCTime
- , spamWords :: [StrictText]
- , mailDomains :: [StrictText]
- , statistics :: IORef Int
- , noLogin :: Word
- } deriving Eq
-
-decodeSettingsFile :: FilePath -> IO Settings
-decodeSettingsFile configPath = do
- ConfigFile{..} <- Toml.decodeFile configFileCodec configPath
- parsedServer <- URI.mkURI server
- now <- getCurrentTime
- ioRef <- newIORef 0
- pure $ Settings
- { token = token
- , server = parsedServer
- , now = now
- , spamWords = spamWords
- , mailDomains = mailDomains
- , noLogin = noLogin
- , statistics = ioRef
- }
-
-newtype ProgramOptions = ProgramOptions
- { live :: Bool
- } deriving (Eq, Show)
-
-commandLineInfo :: ParserInfo ProgramOptions
-commandLineInfo = info (commandLine <**> helper)
- $ fullDesc <> progDesc "Helps to detect some spam gitea accounts"
-
-commandLine :: Parser ProgramOptions
-commandLine = ProgramOptions
- <$> switch (long "live" <> help "Purge suspicious users")