2022-04-04 08:14:42 +01:00
|
|
|
{-# LANGUAGE NamedFieldPuns #-}
|
|
|
|
|
|
|
|
module Main where
|
|
|
|
|
|
|
|
import Simplex.Chat.Bot
|
|
|
|
import Simplex.Chat.Controller (versionNumber)
|
2022-04-10 17:13:06 +01:00
|
|
|
import Simplex.Chat.Core
|
2022-04-04 08:14:42 +01:00
|
|
|
import Simplex.Chat.Options
|
2022-05-11 16:52:08 +01:00
|
|
|
import Simplex.Chat.Terminal (terminalChatConfig)
|
2022-04-04 08:14:42 +01:00
|
|
|
import System.Directory (getAppUserDataDirectory)
|
|
|
|
import Text.Read
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
opts <- welcomeGetOpts
|
2023-10-11 09:50:11 +01:00
|
|
|
simplexChatCore terminalChatConfig opts $
|
2023-02-14 07:57:27 +00:00
|
|
|
chatBotRepl welcomeMessage $ \_contact msg ->
|
|
|
|
pure $ case readMaybe msg :: Maybe Integer of
|
2022-04-04 08:14:42 +01:00
|
|
|
Just n -> msg <> " * " <> msg <> " = " <> show (n * n)
|
|
|
|
_ -> "\"" <> msg <> "\" is not a number"
|
|
|
|
|
2023-02-14 07:57:27 +00:00
|
|
|
welcomeMessage :: String
|
|
|
|
welcomeMessage = "Hello! I am a simple squaring bot.\nIf you send me a number, I will calculate its square"
|
|
|
|
|
2022-04-04 08:14:42 +01:00
|
|
|
welcomeGetOpts :: IO ChatOpts
|
|
|
|
welcomeGetOpts = do
|
|
|
|
appDir <- getAppUserDataDirectory "simplex"
|
2025-01-10 15:27:29 +04:00
|
|
|
opts@ChatOpts {coreOptions} <- getChatOpts appDir "simplex_bot"
|
2022-04-04 08:14:42 +01:00
|
|
|
putStrLn $ "SimpleX Chat Bot v" ++ versionNumber
|
2025-01-10 15:27:29 +04:00
|
|
|
printDbOpts coreOptions
|
2022-04-04 08:14:42 +01:00
|
|
|
pure opts
|