summaryrefslogtreecommitdiff
path: root/HsBot/Base/State.hs
diff options
context:
space:
mode:
authorpb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157>2010-03-28 11:09:30 +0000
committerpb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157>2010-03-28 11:09:30 +0000
commit80ff91aa5d6cda6adc1c97dc39b950dd7daed9d5 (patch)
tree4b1ad4310067e9ee9b5dcbae027844ed596e015f /HsBot/Base/State.hs
parent7a7302c5b86e89f3fc2fbc3476db731dfd6ed11b (diff)
git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@50 9f8f72e9-4bf4-416e-b76e-7d4203597157
Diffstat (limited to 'HsBot/Base/State.hs')
-rw-r--r--HsBot/Base/State.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/HsBot/Base/State.hs b/HsBot/Base/State.hs
new file mode 100644
index 0000000..abcf479
--- /dev/null
+++ b/HsBot/Base/State.hs
@@ -0,0 +1,32 @@
+module HsBot.Base.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')
+