diff options
| author | pb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157> | 2009-12-17 02:55:53 +0000 |
|---|---|---|
| committer | pb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157> | 2009-12-17 02:55:53 +0000 |
| commit | 00b8ee91f63a7dc768931c051e87e2562de57575 (patch) | |
| tree | da303611f4419557a7348555713f0482074e30bf /HsBot.hs | |
| parent | 22b946cf3885885e42e1cb510bd58232377a5c6f (diff) | |
git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@14 9f8f72e9-4bf4-416e-b76e-7d4203597157
Diffstat (limited to 'HsBot.hs')
| -rw-r--r-- | HsBot.hs | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -106,6 +106,9 @@ userRank = userRank' 1 sortedUsers | userEquals x user = rank | otherwise = userRank' (rank+1) xs user +getUser :: String -> Conf -> User +getUser name = head . filter (\x -> userName x == name) . users + userPerc :: User -> Float userPerc user = let rank = userRank user @@ -115,7 +118,7 @@ userPerc user = | otherwise = let userWeight = 100 / (fromIntegral numUsers) in 100 - userWeight * (fromIntegral rank) - in userPerc' + in userPerc' userKarma :: User -> String userKarma user = userKarma' (userPts user) (userPerc user) @@ -123,6 +126,9 @@ userKarma user = userKarma' (userPts user) (userPerc user) let cands = sort $ filter (\x -> minPts x <= pts && minPerc x <= perc) (karmas makeConf) in karmaName $ cands !! 0 -- Best posible karma +addUserKarma :: Int -> User -> User +addUserKarma add user = user { userPts = userPts user + add } + -- Sorts a list sort :: (Ord a) => [a] -> [a] sort [] = [] @@ -148,8 +154,8 @@ split (c:cs) delim -- Returns a list of all strings to increase or decrease the karma of matches :: String -> String -> [String] -matches search string = uniq $ - case m' $ occ search string of +matches search string = + uniq $ case m' $ occ search string of (list, "") -> list (list, rest) -> list ++ (matches search rest) where occ :: String -> String -> Maybe (String, String) @@ -157,7 +163,6 @@ matches search string = uniq $ where o' pred [] str = Just (init . init $ reverse pred, str) o' pred occ [] = Nothing o' pred (m:occ) (s:str) - | m == s = o' (s:pred) occ str | otherwise = o' (s:pred) search str extr extrF = extrF . filter (\x -> (x /= '-') && (x /= '+')) extrL str -- extract left side @@ -170,10 +175,15 @@ matches search string = uniq $ m' Nothing = ([], []) processInput :: Conf -> Conf -processInput conf = loggMessage "foo" conf - where plus = matches "++" (line conf) +processInput conf = addAll --loggMessage "foo" conf + where add :: [User] -> [User] + add [] = [] + add (u:[]) = addUserKarma 1 u : [] + add (u:us) = addUserKarma 1 u : (add us) + addAll = conf { users = add (users conf) } + plus = matches "++" (line conf) minus = matches "--" (line conf) - + help :: IO () help = do putStrLn "\t!h - Print help" |
