diff options
| author | pb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157> | 2010-02-28 16:30:04 +0000 |
|---|---|---|
| committer | pb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157> | 2010-02-28 16:30:04 +0000 |
| commit | 392435d3c8f1eb985f449279bbc40f84309d8452 (patch) | |
| tree | 3354fd285371a0aee5e6f5a7bff4518112004efd /HsBot.hs | |
| parent | 5d200f007352e21c113b1cadaddcfb2b32f948c1 (diff) | |
git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@17 9f8f72e9-4bf4-416e-b76e-7d4203597157
Diffstat (limited to 'HsBot.hs')
| -rw-r--r-- | HsBot.hs | 50 |
1 files changed, 28 insertions, 22 deletions
@@ -6,7 +6,7 @@ module Main where import IO import System --- Start configuration +-- Static configurations version :: String version = "0.0" @@ -14,7 +14,10 @@ version = "0.0" database :: String database = "hsbot.db" --- End configuration +-- logfile :: String +-- logfile = "hsbot.log" + +-- End of static configurations data Karma = Karma { karmaName :: String, @@ -76,7 +79,7 @@ printLoggs :: Conf -> IO () printLoggs conf = printLoggs' $ reverse (loggs conf) where printLoggs' [] = return () printLoggs' (l:logg) = do { putStrLn l; printLoggs' logg } - + numUsers :: Int numUsers = length $ users makeConf @@ -110,7 +113,7 @@ userKarma :: User -> String userKarma user = userKarma' (userPts user) (userPerc user) where userKarma' pts perc = let cands = sort $ filter (\x -> minPts x <= pts && minPerc x <= perc) (karmas makeConf) - in karmaName $ cands !! 0 -- Best posible karma + in karmaName $ cands !! 0 -- Best posible karma addUserKarma :: Int -> User -> User addUserKarma add user = user { userPts = userPts user + add } @@ -124,17 +127,17 @@ uniq :: (Eq a) => [a] -> [a] uniq list = let r = u' list 0 u' [] _ = [] - u' (x:list) n - | member x r n = u' list n - | otherwise = x:(u' list (n + 1)) + u' (x:list) n + | member x r n = u' list n + | otherwise = x:(u' list (n + 1)) member e list 0 = False member y (x:list) n = x == y || member y list (n - 1) - in r + in r split :: String -> Char -> [String] split [] delim = [""] split (c:cs) delim - | c == delim = "" : rest + | c == delim = "" : rest | otherwise = (c : head rest) : tail rest where rest = split cs delim @@ -173,22 +176,23 @@ loop :: IO Conf -> IO () loop conf = let loop' :: Conf -> IO () loop' conf = do - line <- readInput - getLambda line conf + line <- readInput + getLambda line conf -- Executing the specific lambda function of 'commands' + printHelp = putStr . foldr (++) "" . map (\(a,b,_) -> "\t" ++ a ++ " - " ++ b ++ "\n") + getLambda x = let (_, _, c) = getCommand x in c + getDescr x = let (_, b, _) = getCommand x in b getCommand x = let command = [ (a, b, c) | (a, b, c) <- commands, a == x ] in if length command == 0 - then getCommand "!h" + then getCommand "!h" -- If there is no such command print out the help else head command where commands = [ ("!h", "Prints help ", (\x -> do { printHelp commands; loop' x } ) ), ("!l", "Prints loggs", (\x -> do { printLoggs x; loop' x } ) ), ("!p", "Prints configuration", (\x -> do { putStrLn $ show x; loop' x } ) ), ("!s", "Saves configuration", (\x -> do { putStrLn "Saving current xiguration"; save x; loop' x } ) ), - ("!q", "Quits", (\x -> do { putStrLn "Good bye"; exitWith ExitSuccess } ) )] - getLambda x = let (_, _, c) = getCommand x in c - getDescr x = let (_, b, _) = getCommand x in b - printHelp = putStr . foldr (++) "" . map (\(a,b,_) -> "\t" ++ a ++ " - " ++ b ++ "\n") + ("!q", "Quits", (\x -> do { putStrLn "Good bye"; save x; exitWith ExitSuccess } ) )] + -- Extract the Conf from the IO Monad and run the loop in do conf' <- conf loop' conf' @@ -214,6 +218,14 @@ load = do file <- readFile database return ( read file :: Conf ) +makeConf :: Conf +makeConf = makeTestConf + +makeIOConf :: IO Conf +makeIOConf = return (makeConf) + +-- This will be removed once + makeTestConf :: Conf makeTestConf = Conf { line = "", @@ -245,9 +257,3 @@ makeTestConf = Conf { Karma "Cool dude" 0 0 ] } -makeConf :: Conf -makeConf = makeTestConf - -makeIOConf :: IO Conf -makeIOConf = return (makeConf) - |
