summaryrefslogtreecommitdiff
path: root/fig-frontend/src
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-03-29 00:06:11 -0400
committerLLLL Colonq <llll@colonq>2024-03-29 00:06:11 -0400
commitdec476ab9b8602225964cfa534bb004676ff6419 (patch)
tree6b75b1905b4e2493633f6be7490a37b489dbffb1 /fig-frontend/src
parentb679cce8e0c8ca20d53b1032b15f80ebf6072617 (diff)
Update frontend
Diffstat (limited to 'fig-frontend/src')
-rw-r--r--fig-frontend/src/Fig/Frontend.hs14
1 files changed, 13 insertions, 1 deletions
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