tellbot 0.4.0.1 → 0.4.0.2
raw patch · 3 files changed
+26/−11 lines, 3 files
Files
- CHANGELOG.md +4/−0
- src/Main.hs +19/−10
- tellbot.cabal +3/−1
CHANGELOG.md view
@@ -1,6 +1,10 @@ tellbot CHANGELOG ================= +### 0.4.0.2++- bug fix; nickname case sensitivity removed.+ ### 0.4.0.1 - changed the format of *author* and *maintainer* fields in the cabal file;
src/Main.hs view
@@ -5,7 +5,8 @@ import Control.Monad.Identity import Control.Monad.Trans import Control.Monad.Trans.RWS-import Data.Bifunctor ( second )+import Data.Bifunctor ( bimap, second )+import Data.Char ( toLower ) import Data.List ( intersperse ) import Data.List.Split ( chunksOf, splitOn ) import Data.Time.Clock ( getCurrentTime, utctDay )@@ -16,7 +17,7 @@ import System.IO version :: Version-version = Version [0,4,0,1] ["Grolsch"]+version = Version [0,4,0,2] ["Chouffe"] type Failable = EitherT String Identity type FailableIO = EitherT String IO@@ -37,6 +38,14 @@ , conPwd :: String } +newtype Nick = Nick { unNick :: String }++instance Eq Nick where+ Nick a == Nick b = map toLower a == map toLower b++instance Show Nick where+ show (Nick a) = map toLower a+ -- for each individual dudes, keep a list of stories to tell type Stories = M.Map String [String] @@ -174,7 +183,7 @@ treatMsg msg = do nick <- asks conNick liftIO . putStrLn $ "from: " ++ fromNick ++ ", to: " ++ to ++ ": " ++ content- unless ( null content || fromNick == nick ) $ do+ unless ( null content || Nick fromNick == Nick nick ) $ do tellStories fromNick when ( head content == '!') $ do onCmd fromNick to (tail content)@@ -183,7 +192,7 @@ treatJoin :: String -> Session () treatJoin _ = do- return ()+ return () {- nick <- asks conNick unless (from == nick) $ tellStories from@@ -237,7 +246,7 @@ where treat chan | length arg > 1 && not (null msg) = do- nick <- asks conNick+ nick <- fmap Nick (asks conNick) if fromNick == nick then msgIRC chan "I'll tell myself for sure pal!" else do@@ -253,11 +262,11 @@ else do -} now <- liftIO $ utctDay `liftM` getCurrentTime- modify . M.insertWith (flip (++)) fromNick $- [show now ++ ", " ++ from ++ " told " ++ fromNick ++ ": " ++ msg]+ modify . M.insertWith (flip (++)) (show fromNick) $+ [show now ++ ", " ++ from ++ " told " ++ (unNick fromNick) ++ ": " ++ msg] msgIRC from "\\_o<" | otherwise = msgIRC chan "nope!"- (fromNick,msg) = second tailSafe . break (==' ') $ arg+ (fromNick,msg) = bimap Nick tailSafe . break (==' ') $ arg doCmd :: String -> String -> String -> Session () doCmd from to arg = do@@ -268,7 +277,7 @@ where treatDo chan myNick pwd | to == chan = msgIRC from "I'm sorry, I feel naked in public ;)"- | to == myNick && length args >= 3 = executeDo chan pwd+ | Nick to == Nick myNick && length args >= 3 = executeDo chan pwd | otherwise = msgIRC from "huhu, something went terribly wrong!" args = words arg userPwd:action:actionParams = args@@ -300,7 +309,7 @@ -- FIXME: host & ident tellStories :: String -> Session () tellStories nick = do- stories <- gets (maybeToList . M.lookup nick)+ stories <- gets (maybeToList . M.lookup (show $ Nick nick)) let cstories = concat stories chunks = map (mapM_ $ msgIRC nick) . chunksOf floodThreshold $ cstories
tellbot.cabal view
@@ -1,5 +1,5 @@ name: tellbot-version: 0.4.0.1+version: 0.4.0.2 synopsis: IRC tellbot description: An IRC bot that can be used to create queuing message. It also offers a simple administration IRC bot interface.@@ -19,6 +19,8 @@ executable tellbot main-is: Main.hs++ default-extensions: FlexibleInstances build-depends: base >= 4.5 && < 4.8 , network == 2.4.*