diff options
Diffstat (limited to 'HsBot/IRC/User.hs')
| -rw-r--r-- | HsBot/IRC/User.hs | 27 |
1 files changed, 26 insertions, 1 deletions
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) + + + + |
