diff options
| author | LLLL Colonq <llll@colonq> | 2024-07-31 22:59:58 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2024-07-31 22:59:58 -0400 |
| commit | 7ffb7b021eec46f2d714e04b47d752012e1bf8ea (patch) | |
| tree | 15d9af7555300bd2b452dda55747cf5870b747d3 /fig-monitor-twitch | |
| parent | 92556dc23ead56ed2c2d2bcc752fe0e7378fa022 (diff) | |
Frontend updates
Diffstat (limited to 'fig-monitor-twitch')
| -rw-r--r-- | fig-monitor-twitch/main/Main.hs | 3 | ||||
| -rw-r--r-- | fig-monitor-twitch/src/Fig/Monitor/Twitch.hs | 20 | ||||
| -rw-r--r-- | fig-monitor-twitch/src/Fig/Monitor/Twitch/Utils.hs | 3 |
3 files changed, 19 insertions, 7 deletions
diff --git a/fig-monitor-twitch/main/Main.hs b/fig-monitor-twitch/main/Main.hs index 2232a03..05f3cdb 100644 --- a/fig-monitor-twitch/main/Main.hs +++ b/fig-monitor-twitch/main/Main.hs @@ -11,12 +11,14 @@ data Command = Monitor | Chatbot | RedirectServer + | Validate parseCommand :: Parser Command parseCommand = subparser $ mconcat [ command "monitor" $ info (pure Monitor) (progDesc "Launch the Twitch monitor") , command "chatbot" $ info (pure Chatbot) (progDesc "Launch the Twitch chatbot") , command "user-token-server" $ info (pure RedirectServer) (progDesc "Launch a web server to handle authentication redirects") + , command "validate-endpoint" $ info (pure Validate) (progDesc "Test Twitch authentication") ] data Opts = Opts { busHost :: Text @@ -43,3 +45,4 @@ main = do Monitor -> twitchEventClient cfg (opts.busHost, opts.busPort) Chatbot -> twitchChatClient cfg (opts.busHost, opts.busPort) RedirectServer -> userTokenRedirectServer cfg + Validate -> twitchEndpointTest cfg diff --git a/fig-monitor-twitch/src/Fig/Monitor/Twitch.hs b/fig-monitor-twitch/src/Fig/Monitor/Twitch.hs index 1889545..17f2b8a 100644 --- a/fig-monitor-twitch/src/Fig/Monitor/Twitch.hs +++ b/fig-monitor-twitch/src/Fig/Monitor/Twitch.hs @@ -5,6 +5,7 @@ module Fig.Monitor.Twitch ( twitchEventClient , twitchChatClient + , twitchEndpointTest , userTokenRedirectServer ) where @@ -233,6 +234,11 @@ shoutout souser user = do unless (HTTP.statusIsSuccessful $ HTTP.responseStatus response) $ do log $ "Failed to shoutout: error " <> tshow (HTTP.statusCode $ HTTP.responseStatus response) +twitchEndpointTest :: Config -> IO () +twitchEndpointTest cfg = runAuthed cfg do + user <- loginToUserId "lcolonq" + log user + twitchEventClient :: Config -> (Text, Text) -> IO () twitchEventClient cfg busAddr = do WS.runSecureClient "eventsub.wss.twitch.tv" 443 "/ws" \conn -> do @@ -248,6 +254,7 @@ twitchEventClient cfg busAddr = do log $ "Connected to Twitch API, session ID is: " <> sessionId runAuthed cfg do user <- loginToUserId cfg.userLogin + log "got user id" subscribe sessionId "channel.channel_points_custom_reward_redemption.add" user subscribe sessionId "channel.prediction.begin" user subscribe sessionId "channel.prediction.end" user @@ -255,6 +262,7 @@ twitchEventClient cfg busAddr = do subscribe sessionId "channel.poll.end" user subscribe sessionId "channel.subscribe" user subscribe sessionId "channel.subscription.gift" user + log "finished subscribing" subscribeFollows sessionId user subscribeRaids sessionId user busClient busAddr @@ -275,7 +283,7 @@ twitchEventClient cfg busAddr = do let parseEvent o = do payload <- o .: "payload" event <- payload .: "event" - nm <- event .: "user_name" + nm <- event .: "user_login" reward <- event .: "reward" title <- reward .: "title" minput <- event .:? "user_input" @@ -312,7 +320,7 @@ twitchEventClient cfg busAddr = do let parseEvent o = do payload <- o .: "payload" event <- payload .: "event" - event .: "from_broadcaster_user_name" + event .: "from_broadcaster_user_login" case Aeson.parseMaybe parseEvent res of Just nm -> do log $ "Incoming raid from: " <> nm @@ -322,7 +330,7 @@ twitchEventClient cfg busAddr = do let parseEvent o = do payload <- o .: "payload" event <- payload .: "event" - event .: "user_name" + event .: "user_login" case Aeson.parseMaybe parseEvent res of Just nm -> do log $ "New follower: " <> nm @@ -332,7 +340,7 @@ twitchEventClient cfg busAddr = do let parseEvent o = do payload <- o .: "payload" event <- payload .: "event" - event .: "user_name" + event .: "user_login" case Aeson.parseMaybe parseEvent res of Just nm -> do log $ "New subscriber: " <> nm @@ -342,7 +350,7 @@ twitchEventClient cfg busAddr = do let parseEvent o = do payload <- o .: "payload" event <- payload .: "event" - nm <- event .: "user_name" + nm <- event .: "user_login" bits <- event .: "bits" pure (nm, bits) case Aeson.parseMaybe parseEvent res of @@ -354,7 +362,7 @@ twitchEventClient cfg busAddr = do let parseEvent o = do payload <- o .: "payload" event <- payload .: "event" - nm <- event .: "user_name" + nm <- event .: "user_login" num <- event .: "total" pure (nm, num) case Aeson.parseMaybe parseEvent res of diff --git a/fig-monitor-twitch/src/Fig/Monitor/Twitch/Utils.hs b/fig-monitor-twitch/src/Fig/Monitor/Twitch/Utils.hs index f1d757c..59ba04c 100644 --- a/fig-monitor-twitch/src/Fig/Monitor/Twitch/Utils.hs +++ b/fig-monitor-twitch/src/Fig/Monitor/Twitch/Utils.hs @@ -78,7 +78,8 @@ authedRequestJSON :: (Aeson.ToJSON a, Aeson.FromJSON b) => Text -> Text -> a -> authedRequestJSON method url val = do resp <- authedRequest method url $ Aeson.encode val case Aeson.eitherDecode resp of - Left err -> throwM . FigMonitorTwitchException $ tshow err + Left err -> do + throwM . FigMonitorTwitchException $ tshow err Right res -> pure res runAuthed :: Config -> Authed a -> IO a |
