1
module HandlerUtils where
3
import Control.Monad.Reader
4
import qualified Data.ByteString.Char8 as B
11
thisClient :: Reader (ClientIndex, IRnC) ClientInfo
14
return $ rnc `client` ci
16
thisRoom :: Reader (ClientIndex, IRnC) RoomInfo
19
let ri = clientRoom rnc ci
20
return $ rnc `room` ri
22
clientNick :: Reader (ClientIndex, IRnC) B.ByteString
23
clientNick = liftM nick thisClient
25
roomOthersChans :: Reader (ClientIndex, IRnC) [ClientChan]
28
let ri = clientRoom rnc ci
29
return $ map (sendChan . client rnc) $ filter (/= ci) (roomClients rnc ri)
31
roomSameClanChans :: Reader (ClientIndex, IRnC) [ClientChan]
32
roomSameClanChans = do
34
let ri = clientRoom rnc ci
35
let otherRoomClients = map (client rnc) . filter (/= ci) $ roomClients rnc ri
36
let cl = rnc `client` ci
37
let sameClanClients = Prelude.filter (\c -> clientClan c == clientClan cl) otherRoomClients
38
return $ map sendChan sameClanClients
40
roomClientsChans :: Reader (ClientIndex, IRnC) [ClientChan]
43
let ri = clientRoom rnc ci
44
return $ map (sendChan . client rnc) (roomClients rnc ri)
46
thisClientChans :: Reader (ClientIndex, IRnC) [ClientChan]
49
return [sendChan (rnc `client` ci)]
51
answerClient :: [B.ByteString] -> Reader (ClientIndex, IRnC) [Action]
52
answerClient msg = liftM ((: []) . flip AnswerClients msg) thisClientChans
54
allRoomInfos :: Reader (a, IRnC) [RoomInfo]
55
allRoomInfos = liftM ((\irnc -> map (room irnc) $ allRooms irnc) . snd) ask
57
clientByNick :: B.ByteString -> Reader (ClientIndex, IRnC) (Maybe ClientIndex)
60
let allClientIDs = allClients rnc
61
return $ find (\clId -> n == nick (client rnc clId)) allClientIDs