summaryrefslogtreecommitdiff
path: root/fig-web/src/Fig/Web
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-03-06 20:18:53 -0500
committerLLLL Colonq <llll@colonq>2026-03-06 20:18:53 -0500
commit8cbf224b0edc8646690ebbc877d6f72507447d7a (patch)
tree880b2cde892c24560cb43dcca75be4f9668197ab /fig-web/src/Fig/Web
parent3eae057004597db4d41cdcc3770d5c7e22c50d15 (diff)
fig-web: Talent API
Diffstat (limited to 'fig-web/src/Fig/Web')
-rw-r--r--fig-web/src/Fig/Web/Module/Advent.hs2
-rw-r--r--fig-web/src/Fig/Web/Module/User.hs39
-rw-r--r--fig-web/src/Fig/Web/Secure.hs2
3 files changed, 42 insertions, 1 deletions
diff --git a/fig-web/src/Fig/Web/Module/Advent.hs b/fig-web/src/Fig/Web/Module/Advent.hs
index f46cc6c..d1bfe1c 100644
--- a/fig-web/src/Fig/Web/Module/Advent.hs
+++ b/fig-web/src/Fig/Web/Module/Advent.hs
@@ -31,7 +31,7 @@ secure a = do
head_ do
title_ . L.toHtml $ "adventure of advent of code 2025: puzzle " <> tshow pid
link_ [rel_ "icon", href_ "/assets/mrgreen.png"]
- link_ [rel_ "stylesheet", type_ "text/css", href_ "/main.css"]
+ link_ [rel_ "stylesheet", type_ "text/css", href_ "/assets/main.css"]
body_ [id_ "lcolonq-advent"] do
div_ [class_ "lcolonq-advent-header"] do
h1_ . L.toHtml $ "puzzle " <> tshow pid <> " (part 1)"
diff --git a/fig-web/src/Fig/Web/Module/User.hs b/fig-web/src/Fig/Web/Module/User.hs
index e695aeb..1e82e0b 100644
--- a/fig-web/src/Fig/Web/Module/User.hs
+++ b/fig-web/src/Fig/Web/Module/User.hs
@@ -1,5 +1,6 @@
module Fig.Web.Module.User
( public
+ , secure
) where
import Fig.Prelude
@@ -14,6 +15,7 @@ import qualified Database.Redis as Redis
import Fig.Web.Utils
import Fig.Web.Types
+import Fig.Web.Auth
import qualified Fig.Web.DB as DB
getText :: MonadIO m => DB -> ByteString -> m (Maybe Text)
@@ -212,3 +214,40 @@ public a = do
Just img -> do
addHeader "Content-Type" "image/png"
respondBytes img
+
+secure :: SecureModule
+secure a = do
+ onPost "/api/talent/reset" $ authed a \creds -> do
+ let buid = encodeUtf8 creds.twitchId
+ let skey = "user:stats:" <> buid
+ let tkey = "user:talents:" <> buid
+ DB.run a.db do
+ DB.hset skey "allocatedtalentpoints" "0"
+ DB.del [tkey]
+ respondText "talents reset!"
+ onPost "/api/talent/:tid/purchase" $ authed a \creds -> do
+ tid <- pathParam "tid"
+ let buid = encodeUtf8 creds.twitchId
+ let skey = "user:stats:" <> buid
+ let tkey = "user:talents:" <> buid
+ let parseToInt mbs = fromMaybe 0 do
+ bs <- mbs
+ (iv, _) <- BS.C8.readInteger bs
+ pure iv
+ (mtp, matp, mprev) <- DB.run a.db $ (,,)
+ <$> DB.hget skey "talentpoints"
+ <*> DB.hget skey "allocatedtalentpoints"
+ <*> DB.hget tkey tid
+ let tp = parseToInt mtp
+ let atp = parseToInt matp
+ let prev = parseToInt mprev
+ if atp < tp
+ then do
+ DB.run a.db do
+ DB.hset skey "allocatedtalentpoints" . encodeUtf8 . tshow $ atp + 1
+ DB.hset tkey tid . encodeUtf8 . tshow $ prev + 1
+ respondText "talent allocated!"
+ else do
+ status status403
+ respondText "no talent points"
+
diff --git a/fig-web/src/Fig/Web/Secure.hs b/fig-web/src/Fig/Web/Secure.hs
index b5d3299..5aebff8 100644
--- a/fig-web/src/Fig/Web/Secure.hs
+++ b/fig-web/src/Fig/Web/Secure.hs
@@ -18,6 +18,7 @@ import qualified Fig.Web.DB as DB
import qualified Fig.Web.Module.Exchange as Exchange
import qualified Fig.Web.Module.Redeem as Redeem
import qualified Fig.Web.Module.Advent as Advent
+import qualified Fig.Web.Module.User as User
allBusEvents :: SecureModuleArgs -> BusEventHandlers
allBusEvents args = busEvents . mconcat $ fmap ($ args)
@@ -72,5 +73,6 @@ app args = do
Exchange.secure args
Redeem.secure args
Advent.secure args
+ User.secure args
Sc.notFound do
respondText "not found"