mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-28 20:29:53 +00:00
* simplex-chat server * typescript types for chat commands and command serialization * typescript ChatResponse type * more types * more types * websocket chat client * aligb ts/haskell types * chat server & TS client via websockets - it works * TS chat client test * TS chat client test * update test * more api functions * more api methods, refactor, readme * squaring chat bot example, fixes * update readme * remove console.log * npm version 0.1.0
36 lines
1.2 KiB
Haskell
36 lines
1.2 KiB
Haskell
{-# LANGUAGE NamedFieldPuns #-}
|
|
|
|
module Main where
|
|
|
|
import Control.Concurrent (threadDelay)
|
|
import Server
|
|
import Simplex.Chat.Controller (versionNumber)
|
|
import Simplex.Chat.Core
|
|
import Simplex.Chat.Options
|
|
import Simplex.Chat.Terminal
|
|
import Simplex.Chat.View (serializeChatResponse)
|
|
import System.Directory (getAppUserDataDirectory)
|
|
import System.Terminal (withTerminal)
|
|
|
|
main :: IO ()
|
|
main = do
|
|
appDir <- getAppUserDataDirectory "simplex"
|
|
opts@ChatOpts {chatCmd, chatServerPort} <- getChatOpts appDir "simplex_v1"
|
|
if null chatCmd
|
|
then case chatServerPort of
|
|
Just chatPort ->
|
|
simplexChatServer defaultChatServerConfig {chatPort} terminalChatConfig opts
|
|
_ -> do
|
|
welcome opts
|
|
t <- withTerminal pure
|
|
simplexChatTerminal terminalChatConfig opts t
|
|
else simplexChatCore terminalChatConfig opts Nothing $ \_ cc -> do
|
|
r <- sendChatCmd cc chatCmd
|
|
putStrLn $ serializeChatResponse r
|
|
threadDelay $ chatCmdDelay opts * 1000000
|
|
|
|
welcome :: ChatOpts -> IO ()
|
|
welcome ChatOpts {dbFilePrefix} = do
|
|
putStrLn $ "SimpleX Chat v" ++ versionNumber
|
|
putStrLn $ "db: " <> dbFilePrefix <> "_chat.db, " <> dbFilePrefix <> "_agent.db"
|
|
putStrLn "type \"/help\" or \"/h\" for usage info"
|