werewolf-slack 0.3.0.2 → 0.4.0.0
raw patch · 7 files changed
+54/−53 lines, 7 files
Files
- CHANGELOG.md +16/−0
- README.md +9/−9
- app/Werewolf/Slack/Application.hs +6/−6
- app/Werewolf/Slack/Options.hs +11/−17
- app/Werewolf/Slack/Slack.hs +4/−7
- app/Werewolf/Slack/Werewolf.hs +5/−11
- werewolf-slack.cabal +3/−3
CHANGELOG.md view
@@ -2,6 +2,22 @@ ### Upcoming +### v0.4.0.0++*Major*++* Renamed `--authentication-token` to `--webhook-url`. ([#15](https://github.com/hjwylde/werewolf/issues/15))+* Renamed `--validation-token` to `--token`. ([#15](https://github.com/hjwylde/werewolf/issues/15))+* Removed `--channel-name` option. ([#16](https://github.com/hjwylde/werewolf/issues/16))++*Minor*++* Split out Dockerfile into its own repository. ([#13](https://github.com/hjwylde/werewolf/issues/13))++*Revisions*++* Changed 202 response to 200. ([#17](https://github.com/hjwylde/werewolf/issues/17))+ ### v0.3.0.2 *Revisions*
README.md view
@@ -3,10 +3,12 @@ [](http://www.repostatus.org/#wip) [](https://travis-ci.org/hjwylde/werewolf-slack) [](https://github.com/hjwylde/werewolf-slack/releases/latest)+[](https://www.stackage.org/lts/package/werewolf-slack)+[](https://www.stackage.org/nightly/package/werewolf-slack) A chat interface for playing [werewolf](https://github.com/hjwylde/werewolf) in [Slack](https://slack.com/).-The game engine is based off of the party game Mafia, also known as Werewolf.+Werewolf is a well known social party game, commonly also called Mafia. See the [Wikipedia article](https://en.wikipedia.org/wiki/Mafia_(party_game)) for a rundown on it's gameplay and history. @@ -17,8 +19,7 @@ the village has yet to lay eyes on the merciless Werewolf. Each night Werewolves attack the village and devour the innocent.-For centuries no one knew how to fight this scourge, however recently a theory has taken ahold- that+For centuries no-one knew how to fight this scourge, however recently a theory has taken ahold that mayhaps the Werewolves walk among the Villagers themselves... Objective of the Game: @@ -49,7 +50,7 @@ **Using Docker:** ```bash-docker pull hjwylde/werewolf-slack+docker pull hjwylde/werewolf-slack-docker ``` **Using stack:**@@ -80,7 +81,7 @@ **With Docker:** ```bash-docker run -d -p 80:8080 hjwylde/werewolf-slack -t ACCESS_TOKEN -v VALIDATION_TOKEN+docker run -d -p 80:8080 hjwylde/werewolf-slack-docker -t ACCESS_TOKEN -v VALIDATION_TOKEN ``` **With werewolf-slack:**@@ -91,11 +92,10 @@ #### Configuration -It is possible to also configure the channel to play werewolf in and the port that werewolf-slack- listens on.-This is done via the `--channel-name` (`-c`) and `--port` (`-p`) options respectively.+It is possible to also configure the port that werewolf-slack listens on. This is done via the+ `--port` (`-p`) option. -By default the channel name is *werewolf* and port *8080*.+The default port is *8080*. ### Usage
app/Werewolf/Slack/Application.hs view
@@ -43,14 +43,14 @@ application :: Options -> Manager -> Application application options manager request respond- | isNothing mToken = debugRequest >> badRequest- | fromJust mToken /= optValidationToken options = debugRequest >> unauthorized- | isNothing mUser || isNothing mUserCommand = debugRequest >> badRequest- | otherwise = debugRequest >> forkIO (evalStateT (runReaderT action options) manager) >> accepted+ | isNothing mToken = debugRequest >> badRequest+ | fromJust mToken /= optToken options = debugRequest >> unauthorized+ | isNothing mUser || isNothing mUserCommand = debugRequest >> badRequest+ | otherwise = debugRequest >> forkIO (evalStateT (runReaderT action options) manager) >> ok where debugRequest = when (optDebug options) $ print request - accepted = respond $ responseLBS status202 [] (BSLC.pack $ unwords [":wolf:", fromJust mUserCommand, ":moon:"])+ ok = respond $ responseLBS status200 [] (BSLC.pack $ unwords [":wolf:", fromJust mUserCommand, ":moon:"]) badRequest = respond $ responseLBS status400 [] "bad request" unauthorized = respond $ responseLBS status401 [] "unauthorized" @@ -58,4 +58,4 @@ mToken = BSC.unpack <$> param "token" mUser = BSC.unpack <$> param "user_name" mUserCommand = BSC.unpack <$> param "text"- action = fromJust $ execute <$> mUser <*> mUserCommand+ action = fromJust $ execute <$> mToken <*> mUser <*> mUserCommand
app/Werewolf/Slack/Options.hs view
@@ -26,11 +26,10 @@ import qualified Werewolf.Slack.Version as This data Options = Options- { optAccessToken :: String- , optChannelName :: String- , optDebug :: Bool- , optPort :: Port- , optValidationToken :: String+ { optDebug :: Bool+ , optPort :: Port+ , optToken :: String+ , optWebhookUrl :: String } deriving (Eq, Show) -- | The default preferences.@@ -55,16 +54,7 @@ -- | An options parser. werewolfSlack :: Parser Options werewolfSlack = Options- <$> strOption (mconcat- [ long "access-token", short 't', metavar "TOKEN"- , help "Specify the access token"- ])- <*> strOption (mconcat- [ long "channel-name", short 'c', metavar "CHANNEL"- , value "werewolf", showDefault- , help "Specify the channel name"- ])- <*> switch (mconcat+ <$> switch (mconcat [ long "debug", short 'd' , help "Enable debug mode" ])@@ -74,8 +64,12 @@ , help "Specify the port for the server to listen on" ]) <*> strOption (mconcat- [ long "validation-token", short 'v', metavar "TOKEN"- , help "Specify the validation token"+ [ long "token", short 't', metavar "TOKEN"+ , help "Specify the Slash Command token"+ ])+ <*> strOption (mconcat+ [ long "webhook-url", short 'u', metavar "URL"+ , help "Specify the Incoming Webhook URL" ]) where portOption = option auto
app/Werewolf/Slack/Slack.hs view
@@ -26,14 +26,11 @@ import Werewolf.Slack.Options -url :: MonadReader Options m => m String-url = asks $ ("https://hooks.slack.com/services/" ++) . optAccessToken--notify :: (MonadIO m, MonadReader Options m, MonadState Manager m) => String -> String -> m ()-notify to message = do+notify :: (MonadIO m, MonadReader Options m, MonadState Manager m) => Maybe String -> String -> m ()+notify mTo message = do manager <- get - initialRequest <- url >>= liftIO . parseUrl+ initialRequest <- asks optWebhookUrl >>= liftIO . parseUrl let request = initialRequest { method = methodPost, requestBody = body } whenM (asks optDebug) $ liftIO (print request)@@ -44,6 +41,6 @@ where body = RequestBodyLBS $ encode payload payload = object- [ "channel" .= to+ [ "channel" .= mTo , "text" .= message ]
app/Werewolf/Slack/Werewolf.hs view
@@ -19,7 +19,6 @@ import Control.Monad.State import Data.Aeson-import Data.Maybe import qualified Data.Text as T import qualified Data.Text.Lazy as TL import Data.Text.Lazy.Encoding@@ -33,27 +32,22 @@ import Werewolf.Slack.Options import Werewolf.Slack.Slack -execute :: (MonadIO m, MonadReader Options m, MonadState Manager m) => String -> String -> m ()-execute user userCommand = do- channelName <- asks optChannelName-- whenJustM (interpret channelName user userCommand) handle+execute :: (MonadIO m, MonadReader Options m, MonadState Manager m) => String -> String -> String -> m ()+execute tag user userCommand = whenJustM (interpret tag user userCommand) handle interpret :: MonadIO m => String -> String -> String -> m (Maybe Response)-interpret channelName user userCommand = do+interpret tag user userCommand = do stdout <- liftIO $ readCreateProcess (proc command arguments) "" return (decode (encodeUtf8 $ TL.pack stdout) :: Maybe Response) where atUser = if take 1 user == "@" then user else '@':user command = "werewolf"- arguments = ["--caller", atUser, "--tag", channelName, "interpret", "--"] ++ words userCommand+ arguments = ["--caller", atUser, "--tag", tag, "interpret", "--"] ++ words userCommand handle :: (MonadIO m, MonadReader Options m, MonadState Manager m) => Response -> m () handle response = do whenM (asks optDebug) $ liftIO (print response) - channelName <- asks $ ('#':) . optChannelName- forM_ (messages response) $ \(Message mTo message) ->- notify (fromMaybe channelName (T.unpack <$> mTo)) (T.unpack message)+ notify (T.unpack <$> mTo) (T.unpack message)
werewolf-slack.cabal view
@@ -1,12 +1,12 @@ name: werewolf-slack-version: 0.3.0.2+version: 0.4.0.0 author: Henry J. Wylde maintainer: public@hjwylde.com homepage: https://github.com/hjwylde/werewolf-slack -synopsis: A Slack chat client for playing werewolf-description: The game engine is based off of the party game Mafia, also known as Werewolf.+synopsis: A chat interface for playing werewolf in Slack+description: A chat interface for playing werewolf in Slack. license: BSD3 license-file: LICENSE