summaryrefslogtreecommitdiff
path: root/fig-frontend/src/Fig
diff options
context:
space:
mode:
Diffstat (limited to 'fig-frontend/src/Fig')
-rw-r--r--fig-frontend/src/Fig/Frontend.hs17
-rw-r--r--fig-frontend/src/Fig/Frontend/DB.hs20
2 files changed, 37 insertions, 0 deletions
diff --git a/fig-frontend/src/Fig/Frontend.hs b/fig-frontend/src/Fig/Frontend.hs
index 3cab953..b1c6aed 100644
--- a/fig-frontend/src/Fig/Frontend.hs
+++ b/fig-frontend/src/Fig/Frontend.hs
@@ -65,4 +65,21 @@ app cfg = do
DB.hget db "songnotes" hash >>= \case
Nothing -> Tw.send . Tw.status Tw.status404 $ Tw.text "song not found"
Just val -> Tw.send . Tw.text $ decodeUtf8 val
+ , Tw.get "/api/poke/:name" do
+ target <- encodeUtf8 . toLower <$> Tw.param "name"
+ inbox <- fromMaybe [] <$> DB.smembers db ("pokeinbox:" <> target)
+ Tw.send . Tw.text . pretty . SExprList @Void $ SExprString . decodeUtf8 <$> inbox
+ , Tw.post "/api/poke/:name" do
+ me <- encodeUtf8 . toLower <$> Tw.param "ayem"
+ target <- encodeUtf8 . toLower <$> Tw.param "name"
+ DB.sismember db ("pokeinbox:" <> me) target >>= \case
+ True -> do
+ log . tshow $ "handshake between " <> me <> " and " <> target <> " complete!"
+ DB.srem db ("pokeinbox:" <> target) [me]
+ DB.srem db ("pokeinbox:" <> me) [target]
+ Tw.send $ Tw.text "complete"
+ False -> do
+ log . tshow $ "partial handshake from " <> me <> " to " <> target
+ DB.sadd db ("pokeinbox:" <> target) [me]
+ Tw.send $ Tw.text "partial"
]
diff --git a/fig-frontend/src/Fig/Frontend/DB.hs b/fig-frontend/src/Fig/Frontend/DB.hs
index d0641de..5ca8772 100644
--- a/fig-frontend/src/Fig/Frontend/DB.hs
+++ b/fig-frontend/src/Fig/Frontend/DB.hs
@@ -24,3 +24,23 @@ hget c key hkey = liftIO $ Redis.runRedis c do
hvals :: MonadIO m => Redis.Connection -> ByteString -> m (Maybe [ByteString])
hvals c key = liftIO $ Redis.runRedis c do
hush <$> Redis.hvals key
+
+sadd :: MonadIO m => Redis.Connection -> ByteString -> [ByteString] -> m ()
+sadd c key skeys = liftIO $ Redis.runRedis c do
+ _ <- Redis.sadd key skeys
+ pure ()
+
+srem :: MonadIO m => Redis.Connection -> ByteString -> [ByteString] -> m ()
+srem c key skeys = liftIO $ Redis.runRedis c do
+ _ <- Redis.srem key skeys
+ pure ()
+
+smembers :: MonadIO m => Redis.Connection -> ByteString -> m (Maybe [ByteString])
+smembers c key = liftIO $ Redis.runRedis c do
+ hush <$> Redis.smembers key
+
+sismember :: MonadIO m => Redis.Connection -> ByteString -> ByteString -> m Bool
+sismember c key skey = liftIO $ Redis.runRedis c do
+ Redis.sismember key skey >>= hush >>> \case
+ Just x -> pure x
+ Nothing -> pure False