3435
|
1 |
module HandlerUtils where
|
|
2 |
|
|
3 |
import Control.Monad.Reader
|
|
4 |
|
|
5 |
import RoomsAndClients
|
|
6 |
import CoreTypes
|
|
7 |
import Actions
|
|
8 |
|
|
9 |
thisClient :: Reader (ClientIndex, IRnC) ClientInfo
|
|
10 |
thisClient = do
|
|
11 |
(ci, rnc) <- ask
|
|
12 |
return $ rnc `client` ci
|
|
13 |
|
|
14 |
clientNick :: Reader (ClientIndex, IRnC) String
|
|
15 |
clientNick = liftM nick thisClient
|
|
16 |
|
|
17 |
roomOthersChans :: Reader (ClientIndex, IRnC) [ClientChan]
|
|
18 |
roomOthersChans = do
|
|
19 |
(ci, rnc) <- ask
|
|
20 |
let ri = clientRoom rnc ci
|
|
21 |
return $ map (sendChan . client rnc) (roomClients rnc ri)
|
|
22 |
|
|
23 |
thisClientChans :: Reader (ClientIndex, IRnC) [ClientChan]
|
|
24 |
thisClientChans = do
|
|
25 |
(ci, rnc) <- ask
|
|
26 |
return $ [sendChan (rnc `client` ci)]
|
|
27 |
|
|
28 |
answerClient :: [String] -> Reader (ClientIndex, IRnC) [Action]
|
|
29 |
answerClient msg = thisClientChans >>= return . (: []) . flip AnswerClients msg
|