diff options
author | Julien Dessaux | 2011-09-19 00:35:41 +0200 |
---|---|---|
committer | Julien Dessaux | 2011-09-19 00:35:41 +0200 |
commit | 9bbb6228a04dc983a810c44c62cc891e11e63b4d (patch) | |
tree | e5f00f2486d7f8b8f0aba37dea1ee9d2814841fe /Hsbot | |
parent | Finished the quote append function. (diff) | |
download | hsbot-9bbb6228a04dc983a810c44c62cc891e11e63b4d.tar.gz hsbot-9bbb6228a04dc983a810c44c62cc891e11e63b4d.tar.bz2 hsbot-9bbb6228a04dc983a810c44c62cc891e11e63b4d.zip |
Improved last active quote handling.
Diffstat (limited to '')
-rw-r--r-- | Hsbot/Plugin/Quote.hs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/Hsbot/Plugin/Quote.hs b/Hsbot/Plugin/Quote.hs index 2736157..30db0c3 100644 --- a/Hsbot/Plugin/Quote.hs +++ b/Hsbot/Plugin/Quote.hs @@ -86,8 +86,9 @@ isQuoteLockedFor quoteId requestor now = do Nothing -> return $ Just True Nothing -> return Nothing -lockQuoteIdFor :: QuoteID -> IRC.UserName -> UTCTime -> Update QuoteDB () -lockQuoteIdFor quoteId requestor now = get >>= \db -> put db { lockedQuotes = M.insert quoteId (requestor, now) (lockedQuotes db) } +lockQuoteIdFor :: QuoteID -> IRC.UserName -> IRC.Channel -> UTCTime -> Update QuoteDB () +lockQuoteIdFor quoteId requestor channel now = get >>= \db -> put db { lockedQuotes = M.insert quoteId (requestor, now) (lockedQuotes db) + , lastActive = M.insert channel quoteId (lastActive db) } setQuote :: QuoteID -> Quote -> Update QuoteDB () setQuote quoteId theQuote = get >>= \db -> put db { quoteBotDB = M.insert quoteId theQuote (quoteBotDB db) } @@ -95,11 +96,8 @@ setQuote quoteId theQuote = get >>= \db -> put db { quoteBotDB = M.insert quoteI getLastActiveQuote :: IRC.Channel -> Query QuoteDB (Maybe QuoteID) getLastActiveQuote channel = asks lastActive >>= return . M.lookup channel -setLastActiveQuote :: QuoteID -> IRC.Channel -> Update QuoteDB () -setLastActiveQuote quoteId channel = get >>= \db -> put db { lastActive = M.insert channel quoteId (lastActive db)} - $(makeAcidic ''QuoteDB [ 'getQuote, 'getQuoteDB, 'isQuoteLockedFor, 'lockQuoteIdFor, 'setQuote - , 'getLastActiveQuote, 'setLastActiveQuote ]) + , 'getLastActiveQuote ]) -- | gets a random quote from the database getRandomQuote :: AcidState QuoteDB -> IO (Maybe Quote) @@ -173,12 +171,11 @@ quoteAppend quoteDB msg quoteID quotee text = do activeLock <- query' quoteDB (IsQuoteLockedFor quoteID sender now) case activeLock of Just True -> do - _ <- update' quoteDB (LockQuoteIdFor quoteID sender now) + _ <- update' quoteDB (LockQuoteIdFor quoteID sender channel now) mQuote <- query' quoteDB (GetQuote quoteID) let newQuote = fromMaybe emptyQuote mQuote newQuote' = newQuote { quotE = quotE newQuote ++ [ QuoteElt { eltQuotee = quotee, eltQuote = text } ] } _ <- update' quoteDB (SetQuote quoteID newQuote') - _ <- update' quoteDB (SetLastActiveQuote quoteID (getChannel msg)) answerMsg msg $ sender ++ ": Appended to quote " ++ show quoteID Just False -> answerMsg msg $ sender ++ ": Someone else is editing this quote right now." Nothing -> answerMsg msg $ sender ++ ":quoteId not found." |