summaryrefslogtreecommitdiff
path: root/HsBot/State.hs
blob: 9d1fa875e1a5d93a2845df277fa399a9c95d95f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module HsBot.State where

import qualified Data.Map as M

import List
import HsBot.IRC.User

data State = State { 
      currentChannel :: String, 
      line :: String, 
      users :: [User]
   } deriving (Show, Read)

stateNumUsers :: State -> Int
stateNumUsers state = length $ users state

stateSortedUsers :: State -> [User]
stateSortedUsers state = sort $ users state

stateLoad :: String -> IO State
stateLoad databaseFile = do
   file <- readFile databaseFile
   return ( read file :: State )

stateSave :: String -> State -> IO ()
stateSave databaseFile = writeFile databaseFile . show

stateSaveIO :: String -> IO State -> IO ()
stateSaveIO databaseFile state = do
   state' <- state
   writeFile databaseFile (show state')