summaryrefslogtreecommitdiff
path: root/fig-web/src/Fig/Web/Module/Misc.hs
blob: 3163b3f2613dfb9ad5c03665177ea72c44d45d22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Fig.Web.Module.Misc
  ( public
  ) where

import Fig.Prelude

import System.Random (randomRIO)

import Control.Lens ((^?), Ixed (..))

import Fig.Web.Utils
import Fig.Web.Types
import qualified Fig.Utils.DB as DB

public :: PublicModule
public a = do
  onGet "/api/motd" do
    log "getting motd"
    DB.run a.db (DB.get "motd") >>= \case
      Nothing -> respondText ""
      Just val -> respondText $ decodeUtf8 val
  onGet "/api/catchphrase" do
    let catchphrases =
          [ "vtuber (male)"
          , "man of letters"
          , "cool guy, online"
          , "internet clown man"
          , "professional emacs fan"
          , "web freak"
          , "guy who really likes programming"
          , "i use nixos btw"
          , "(are these funny or cringe or both?)"
          , "haha yay"
          , "Joel"
          ] :: [Text]
    i <- randomRIO (0, length catchphrases - 1)
    case catchphrases ^? ix i of
      Nothing -> respondText "man of letters"
      Just val -> respondText val