summaryrefslogtreecommitdiff
path: root/fig-monitor-twitch/src/Fig
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-10-07 15:16:01 -0400
committerLLLL Colonq <llll@colonq>2025-10-07 15:16:01 -0400
commit6bf32bdad1920aaef196a944cc4313dccbc2eacc (patch)
treeed3d0c3ed924682fb31b6cf814ce9132e928744a /fig-monitor-twitch/src/Fig
parentafcce7f07423288ce1596b19b9868b4073c18167 (diff)
Fix
Diffstat (limited to 'fig-monitor-twitch/src/Fig')
-rw-r--r--fig-monitor-twitch/src/Fig/Monitor/Twitch.hs21
1 files changed, 12 insertions, 9 deletions
diff --git a/fig-monitor-twitch/src/Fig/Monitor/Twitch.hs b/fig-monitor-twitch/src/Fig/Monitor/Twitch.hs
index 4243c46..e1c7cc9 100644
--- a/fig-monitor-twitch/src/Fig/Monitor/Twitch.hs
+++ b/fig-monitor-twitch/src/Fig/Monitor/Twitch.hs
@@ -409,6 +409,7 @@ twitchEventClient cfg busAddr = do
let parseEvent o = do
payload <- o .: "payload"
event <- payload .: "event"
+ status <- event .: "status"
pollid <- event .: "id"
event .: "choices" >>= \case
Aeson.Array cs -> do
@@ -418,14 +419,16 @@ twitchEventClient cfg busAddr = do
v <- c .: "votes"
pure (t, v)
_else -> mempty
- pure (pollid, toList choices)
+ pure (status, pollid, toList choices)
_else -> mempty
- case Aeson.parseMaybe parseEvent res of
- Just (pollid, choices) -> do
- let schoices = (\(t, v) -> t <> "," <> v) <$> choices
- log $ "Poll end: " <> pollid
- cmds.publish "fig monitor twitch poll end" . encodeUtf8 . Text.unwords $ [pollid] <> schoices
- _else -> log $ "Failed to extract ID from payload for poll end event: " <> tshow res
+ case Aeson.parseEither parseEvent res of
+ Right (status :: Text, pollid, choices :: [(Text, Integer)]) -> do
+ when (status /= "archived") do
+ let schoices = (\(t, v) -> t <> "\t" <> tshow v) <$> choices
+ log $ "Poll end: " <> pollid
+ cmds.publish "fig monitor twitch poll end" . encodeUtf8 . Text.intercalate "\n"
+ $ [pollid] <> schoices
+ Left err -> log $ "Failed to extract ID from payload for poll end event: " <> pack err
_else -> log $ "Received unknown notification event: " <> tshow resp
Just "session_keepalive" -> pure ()
_else -> log $ "Received unknown response: " <> tshow resp
@@ -434,12 +437,12 @@ twitchEventClient cfg busAddr = do
let args = Text.splitOn "\t" $ decodeUtf8 d
case (ev, args) of
("fig monitor twitch poll create", [title, schoices]) -> do
- let choices = Text.splitOn "," schoices
+ let choices = Text.splitOn "\n" schoices
runAuthed cfg do
user <- loginToUserId cfg.userLogin
poll title choices user
("fig monitor twitch prediction create", [title, schoices]) -> do
- let choices = Text.splitOn "," schoices
+ let choices = Text.splitOn "\n" schoices
runAuthed cfg do
user <- loginToUserId cfg.userLogin
createPrediction title choices user