diff options
| author | LLLL Colonq <llll@colonq> | 2024-03-29 00:06:11 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2024-03-29 00:06:11 -0400 |
| commit | dec476ab9b8602225964cfa534bb004676ff6419 (patch) | |
| tree | 6b75b1905b4e2493633f6be7490a37b489dbffb1 /fig-frontend | |
| parent | b679cce8e0c8ca20d53b1032b15f80ebf6072617 (diff) | |
Update frontend
Diffstat (limited to 'fig-frontend')
| -rw-r--r-- | fig-frontend/fig-frontend.cabal | 1 | ||||
| -rw-r--r-- | fig-frontend/src/Fig/Frontend.hs | 14 |
2 files changed, 14 insertions, 1 deletions
diff --git a/fig-frontend/fig-frontend.cabal b/fig-frontend/fig-frontend.cabal index a15047d..855683b 100644 --- a/fig-frontend/fig-frontend.cabal +++ b/fig-frontend/fig-frontend.cabal @@ -29,6 +29,7 @@ common deps , megaparsec , mtl , network + , random , req , safe-exceptions , text diff --git a/fig-frontend/src/Fig/Frontend.hs b/fig-frontend/src/Fig/Frontend.hs index c4ba523..943db8f 100644 --- a/fig-frontend/src/Fig/Frontend.hs +++ b/fig-frontend/src/Fig/Frontend.hs @@ -4,7 +4,9 @@ module Fig.Frontend where import Fig.Prelude -import Control.Lens (use) +import System.Random (randomRIO) + +import Control.Lens (use, (^?), Ixed (..)) import qualified Data.Text as Text import qualified Data.ByteString.Base64 as BS.Base64 @@ -49,6 +51,16 @@ app cfg cmds = do , Tw.put "/api/buffer" do buf <- withState st $ use buffer Tw.send $ Tw.text buf + , Tw.get "/api/motd" do + DB.get db "motd" >>= \case + Nothing -> Tw.send $ Tw.text "" + Just val -> Tw.send . Tw.text $ decodeUtf8 val + , Tw.get "/api/catchphrase" do + let catchphrases = ["foo", "bar", "baz"] :: [Text] + i <- randomRIO (0, length catchphrases - 1) + case catchphrases ^? ix i of + Nothing -> Tw.send $ Tw.text "man of letters" + Just val -> Tw.send $ Tw.text val , Tw.get "/api/user/:name" do name <- Text.toLower <$> Tw.param "name" DB.get db ("user:" <> encodeUtf8 name) >>= \case |
