werewolf-1.5.1.1: A game engine for playing werewolf within an arbitrary chat client

Copyright | (c) Henry J. Wylde 2016
License | BSD3
Maintainer | public@hjwylde.com
Safe Haskell | None
Language | Haskell2010

Game.Werewolf.Response

Contents

- Response
  - Common responses
  - Exit functions
- Message

Description

A response is used as a return result of calling the `werewolf` binary. Each response has a list of associated messages.

`werewolf` was designed to be ambivalent to the playing chat client. The response-message structure reflects this by staying away from anything that could be construed as client-specific. This includes features such as emoji support.

Synopsis

- data Response = Response {
  - ok :: Bool
  - messages :: [Message]
  }
- success :: Response
- failure :: Response
- exitWith :: MonadIO m => Response -> m a
- data Message = Message {
  - to :: Maybe Text
  - message :: Text
  }
- publicMessage :: Text -> Message
- privateMessage :: Text -> Text -> Message
- groupMessages :: [Text] -> Text -> [Message]

# Response

data Response Source #

When a user sends a command to the `werewolf` binary, a response is always returned.

The chat interface should then relay any `messages` from the response. Whether or not the command was valid (indicated by the `ok` flag) is often irrelevant as the returned `messages` will include errors to the user.

Constructors

Response |

Fields

- ok :: Bool

  Boolean flag to indicate success.

- messages :: [Message]

  List of messages.

Instances

Eq Response Source # |
Methods (==) :: Response -> Response -> Bool # (/=) :: Response -> Response -> Bool #
Show Response Source # |
Methods showsPrec :: Int -> Response -> ShowS # show :: Response -> String # showList :: [Response] -> ShowS #
Generic Response Source # |
Associated Types type Rep Response :: * -> * # Methods from :: Response -> Rep Response x # to :: Rep Response x -> Response #
ToJSON Response Source # |
Methods toJSON :: Response -> Value # toEncoding :: Response -> Encoding # toJSONList :: [Response] -> Value # toEncodingList :: [Response] -> Encoding #
FromJSON Response Source # |
Methods parseJSON :: Value -> Parser Response # parseJSONList :: Value -> Parser [Response] #
type Rep Response Source # |
type Rep Response = D1 (MetaData "Response" "Game.Werewolf.Response" "werewolf-1.5.1.1-299bPyE4rbm1dG0PTOqFlb" False) (C1 (MetaCons "Response" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "ok") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Bool)) (S1 (MetaSel (Just Symbol "messages") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Message]))))

## Common responses

success :: Response Source #

A successful, empty response.

failure :: Response Source #

An unsuccessful, empty response.

## Exit functions

exitWith :: MonadIO m => Response -> m a Source #

Exits fast with the given response. The response is encoded as JSON, printed to `stdout` and then the program is exited with `0` (success).

The program always exits with success even if the response was a failure one. This is to distinguish between bad calls to the binary and bad commands to the werewolf engine.

# Message

data Message Source #

A message may be either public or private, indicated by its `to` field.

Each message contains a single text field. This field is permitted to contain special characters such as new lines and tabs.

Constructors

Message |

Fields

- to :: Maybe Text

  The message recipient: `Nothing` for a public message, `Just` for a private message.

- message :: Text

  The message text.

Instances

Eq Message Source # |
Methods (==) :: Message -> Message -> Bool # (/=) :: Message -> Message -> Bool #
Show Message Source # |
Methods showsPrec :: Int -> Message -> ShowS # show :: Message -> String # showList :: [Message] -> ShowS #
Generic Message Source # |
Associated Types type Rep Message :: * -> * # Methods from :: Message -> Rep Message x # to :: Rep Message x -> Message #
ToJSON Message Source # |
Methods toJSON :: Message -> Value # toEncoding :: Message -> Encoding # toJSONList :: [Message] -> Value # toEncodingList :: [Message] -> Encoding #
FromJSON Message Source # |
Methods parseJSON :: Value -> Parser Message # parseJSONList :: Value -> Parser [Message] #
type Rep Message Source # |
type Rep Message = D1 (MetaData "Message" "Game.Werewolf.Response" "werewolf-1.5.1.1-299bPyE4rbm1dG0PTOqFlb" False) (C1 (MetaCons "Message" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "to") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe Text))) (S1 (MetaSel (Just Symbol "message") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Text))))

publicMessage :: Text -> Message Source #

Creates a public message with the given text.

privateMessage :: Text -> Text -> Message Source #

    privateMessage to message

Creates a private message to `to` with the given text.

groupMessages :: [Text] -> Text -> [Message] Source #

    groupMessages tos message

Creates multiple private messages (1 to each recipient) with the given text.