@@ -14,7 +14,6 @@ import qualified Data.Proxy as P
1414import qualified Data.Text as T
1515import Effect
1616import Entity
17- import Network.HTTP.Simple
1817import Property
1918import Reaction
2019import Text.InterpolatedString.QM
@@ -92,28 +91,17 @@ setDubtrackRoom =
9291 Nothing -> void $ createEntity P. Proxy $ DubtrackRoom msg) $
9392 cmapR (const " Updated room for dubtrack" ) $ Reaction replyMessage
9493
95- -- TODO(#221): Dubtrack room is hardcode
96- -- TODO: Rewrite in the Reaction api
9794currentSongCommand :: Reaction Message ()
9895currentSongCommand =
99- Reaction $ \ Message {messageSender = sender} -> do
100- mayRoom <- getRoom
101- case mayRoom of
102- Nothing ->
103- replyToSender
104- sender
105- " Dubtrack room not set, a mod can run '!config dubtrack <room-name>' to set it"
106- Just mahroom -> do
107- request <-
108- parseRequest $
109- " https://api.dubtrack.fm/room/" <>
110- T. unpack (unName $ entityPayload mahroom)
111- response <- eitherDecode . getResponseBody <$> httpRequest request
112- case response of
113- Left message -> errorEff $ T. pack message
114- Right dubtrackResponse ->
115- maybe
116- (replyToSender sender " Nothing is playing right now" )
117- (\ song ->
118- replyToSender sender [qms |❝{songName song}❞: {songLink song}|])
119- (roomCurrentSong $ drData dubtrackResponse)
96+ liftR (const getRoom) $
97+ replyOnNothing
98+ [qms |Dubtrack room not set, a mod can run
99+ '!config dubtrack <room-name>' to set it|] $
100+ cmapR (T. unpack . urlOfRoom . entityPayload) $
101+ jsonHttpRequestReaction $
102+ cmapR (roomCurrentSong . drData) $
103+ replyOnNothing " Nothing is playing right now" $
104+ cmapR (\ song -> [qms |❝{songName song}❞: {songLink song}|]) $
105+ Reaction replyMessage
106+ where
107+ urlOfRoom = (" https://api.dubtrack.fm/room/" <> ) . unName
0 commit comments