hunk ./Bot.hs 162 +-- * GetShapr + +$(deriveAll [''Read, ''Show, ''Eq, ''Ord, ''Default, ''Enum, ''Num] + [d| + newtype GetShapr = GetShapr { shaprCount :: Integer } + |]) +instance Version GetShapr +$(deriveSerialize ''GetShapr) + +instance Component GetShapr where + type Dependencies GetShapr = End + initialValue = 0 + +incGetShapr :: Update GetShapr Integer +incGetShapr = + do (GetShapr c) <- get + let c' = c + 1 + put (GetShapr c') + return c' + +$(mkMethods ''GetShapr ['incGetShapr]) + +-- if you privmsg the bot, it only sends to the shapr!! message to you. + + +getShapr :: String -> String -> (String -> IO ()) -> IO () +getShapr _ "get-shapr" printer = + do c <- update IncGetShapr + let msg = (" shapr!! (get-shapr has been used " ++ show c ++ if (c == 1) then " time.)" else " times.)") + printer msg +getShapr _ _ _ = return () + + +-- * Bot State + hunk ./Bot.hs 206 - type Dependencies BotState = Friends :+: End + type Dependencies BotState = Friends :+: GetShapr :+: End hunk ./Bot.hs 214 + + + hunk ./Bot.hs 230 - writeChan outgoingChan (joinChan "#happs") + writeChan outgoingChan (joinChan "#haskell-blah") hunk ./Bot.hs 251 - , hello botName + , toBot botName hello + , toBot botName getShapr hunk ./Bot.hs 259 - +{- hunk ./Bot.hs 278 +-} + +hello :: String -> String -> (String -> IO ()) -> IO () +hello senderNick "hello" printer = + do (ConversationCount c) <- update (IncFriend (FriendName senderNick)) + let msg = (" hello " ++ senderNick ++ ". We have now talked " ++ show c ++ " " ++ if (c == 1) then "time." else "times.") + printer msg +hello _ _ _ = return () hunk ./Bot.hs 297 +toBot :: String -> (String -> String -> (String -> IO ()) -> IO ()) -> BotPart () +toBot botName handle = + cmd "PRIVMSG" + [ withParam $ \receiver -> + [ withParam $ \msg -> + [ withSenderNick $ \senderNick -> + [ withChan $ \outChan -> + if receiver == botName + then handle senderNick msg (\m -> writeChan outChan (privmsg senderNick m)) + else if ((botName ++ ": ") `isPrefixOf` msg) + then handle senderNick (drop 2 (dropWhile (/= ':') msg)) (\m -> writeChan outChan (privmsg receiver m)) + else noHandle + ] + ] + ] + ]