diff options
| author | LLLL Colonq <llll@colonq> | 2024-02-23 19:30:52 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2024-02-23 19:31:11 -0500 |
| commit | 4a23754fc6515c947e0bbac38cd0e558b701fe2f (patch) | |
| tree | 75c487c3ee77c3aef58eb33f3ff9018d4bd6dcdc /fig-monitor-twitch/src | |
| parent | 6942ffa61fe93dc6872f97d1a0b7683614e8c7e4 (diff) | |
Add poke API
Diffstat (limited to 'fig-monitor-twitch/src')
| -rw-r--r-- | fig-monitor-twitch/src/Fig/Monitor/Twitch.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/fig-monitor-twitch/src/Fig/Monitor/Twitch.hs b/fig-monitor-twitch/src/Fig/Monitor/Twitch.hs index 360e9c8..1889545 100644 --- a/fig-monitor-twitch/src/Fig/Monitor/Twitch.hs +++ b/fig-monitor-twitch/src/Fig/Monitor/Twitch.hs @@ -210,6 +210,29 @@ removeVIP vipuser user = do unless (HTTP.statusIsSuccessful $ HTTP.responseStatus response) $ do log $ "Failed to remove VIP: error " <> tshow (HTTP.statusCode $ HTTP.responseStatus response) +shoutout :: Text -> Text -> Authed () +shoutout souser user = do + log $ "Shoutout to: \"" <> souser <> "\"" + let body = Aeson.encode $ Aeson.object + [ "from_broadcaster_id" .= user + , "moderator_id" .= user + , "to_broadcaster_id" .= souser + ] + rc <- ask + initialRequest <- liftIO . HTTP.parseRequest $ unpack "https://api.twitch.tv/helix/chat/shoutouts" + let request = initialRequest + { method = encodeUtf8 "POST" + , requestBody = RequestBodyLBS body + , requestHeaders = + [ ("Authorization", encodeUtf8 $ "Bearer " <> rc.config.userToken) + , ("Client-Id", encodeUtf8 rc.config.clientId) + , ("Content-Type", "application/json") + ] + } + response <- liftIO $ HTTP.httpLbs request rc.manager + unless (HTTP.statusIsSuccessful $ HTTP.responseStatus response) $ do + log $ "Failed to shoutout: error " <> tshow (HTTP.statusCode $ HTTP.responseStatus response) + twitchEventClient :: Config -> (Text, Text) -> IO () twitchEventClient cfg busAddr = do WS.runSecureClient "eventsub.wss.twitch.tv" 443 "/ws" \conn -> do @@ -241,6 +264,7 @@ twitchEventClient cfg busAddr = do cmds.subscribe [sexp|(monitor twitch prediction finish)|] cmds.subscribe [sexp|(monitor twitch vip add)|] cmds.subscribe [sexp|(monitor twitch vip remove)|] + cmds.subscribe [sexp|(monitor twitch shoutout)|] forever do resp <- WS.receiveData conn case Aeson.eitherDecodeStrict resp of @@ -404,6 +428,12 @@ twitchEventClient cfg busAddr = do loginToMaybeUserId u >>= \case Nothing -> pure () Just vipuser -> removeVIP vipuser user + | ev == [sexp|(monitor twitch shoutout)|] -> do + runAuthed cfg do + user <- loginToUserId cfg.userLogin + loginToMaybeUserId u >>= \case + Nothing -> pure () + Just souser -> shoutout souser user _ -> log $ "Invalid incoming message: " <> tshow d ) (pure ()) |
