From eb0ca70a636183fea73d884e20a48ac6120066bc Mon Sep 17 00:00:00 2001 From: pb Date: Sun, 28 Mar 2010 13:32:02 +0000 Subject: git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@54 9f8f72e9-4bf4-416e-b76e-7d4203597157 --- HsBot/IRC/User.hs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'HsBot/IRC') diff --git a/HsBot/IRC/User.hs b/HsBot/IRC/User.hs index 422f910..375e55e 100644 --- a/HsBot/IRC/User.hs +++ b/HsBot/IRC/User.hs @@ -6,9 +6,18 @@ import HsBot.General.Render data User = User { userName :: String, + userMessages :: Int, userPts :: Int } deriving (Show, Read) +userMakeDefault :: String -> User +userMakeDefault name = + User { + userName = name, + userMessages = 0, + userPts = 0 + } + instance Eq User where x == y = (userPts x) == (userPts y) @@ -20,8 +29,24 @@ instance Ord User where instance Render User where render user = userName user ++ ": " ++ - (show $ userPts user) ++ "pts" + (show $ userPts user) ++ "pts; " ++ + (show $ userMessages user) ++ "msgs" userEquals :: User -> User -> Bool userEquals x y = (userName x) == (userName y) +userGetIfExists :: String -> [User] -> Maybe User +userGetIfExists name [] = Nothing +userGetIfExists name (x:xs) + | userName x == name = Just x + | otherwise = userGetIfExists name xs + +userGet :: String -> [User] -> (User, [User]) +userGet name xs = + case userGetIfExists name xs of + Just user -> (user, xs) + Nothing -> let user = userMakeDefault name in (user, user : xs) + + + + -- cgit v1.2.3