Refactor toward general announcements cntd.

This commit is contained in:
Filip Gralinski 2021-08-21 09:49:30 +02:00
parent 2a6515d872
commit 8e9df1c311
3 changed files with 7 additions and 7 deletions

View File

@ -3,7 +3,7 @@ module Handler.Announcements where
import Import import Import
import Handler.Shared import Handler.Shared
import Web.Announcements (runSlackHook) import Web.Announcements (sendAnnouncement)
getTestAnnouncementsR :: Handler Html getTestAnnouncementsR :: Handler Html
getTestAnnouncementsR = do getTestAnnouncementsR = do
@ -16,7 +16,7 @@ getTestAnnouncementsR = do
Nothing -> "Gonito" Nothing -> "Gonito"
case webHook of case webHook of
Just hook -> liftIO $ runSlackHook hook ("Test message from " ++ (slackLink app name "")) Just hook -> liftIO $ sendAnnouncement hook ("Test message from " ++ (slackLink app name ""))
Nothing -> return () Nothing -> return ()
defaultLayout $ do defaultLayout $ do

View File

@ -973,7 +973,7 @@ doCreateSubmission' _ userId challengeId challengeSubmissionData chan = do
msg chan message msg chan message
case appNewBestResultSlackHook $ appSettings app of case appNewBestResultSlackHook $ appSettings app of
Just "" -> return () Just "" -> return ()
Just hook -> liftIO $ runSlackHook hook message Just hook -> liftIO $ sendAnnouncement hook message
Nothing -> return () Nothing -> return ()
else return () else return ()
@ -1022,7 +1022,7 @@ checkTarget theNow user submissionLink entries indicator target chan = do
msg chan message msg chan message
case appNewBestResultSlackHook $ appSettings app of case appNewBestResultSlackHook $ appSettings app of
Just "" -> return () Just "" -> return ()
Just hook -> liftIO $ runSlackHook hook message Just hook -> liftIO $ sendAnnouncement hook message
Nothing -> return () Nothing -> return ()
else else
return () return ()

View File

@ -2,7 +2,7 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Web.Announcements module Web.Announcements
(runSlackHook, (sendAnnouncement,
formatLink) formatLink)
where where
@ -15,8 +15,8 @@ import Data.Aeson
import Data.Default import Data.Default
runSlackHook :: Text -> Text -> IO () sendAnnouncement :: Text -> Text -> IO ()
runSlackHook hook message = do sendAnnouncement hook message = do
let (Just (hookUrl, _)) = parseUrlHttps $ DTE.encodeUtf8 hook let (Just (hookUrl, _)) = parseUrlHttps $ DTE.encodeUtf8 hook
R.runReq def $ do R.runReq def $ do