summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2011-09-30 21:40:23 +0200
committerJulien Dessaux2011-09-30 21:40:23 +0200
commitac7c0126f39e71022150fadced33c951f1dd52b0 (patch)
tree43a2f347dc338729ab3c95384556f9e4f4d4f493
parentCosmetic. (diff)
downloadhsbot-ac7c0126f39e71022150fadced33c951f1dd52b0.tar.gz
hsbot-ac7c0126f39e71022150fadced33c951f1dd52b0.tar.bz2
hsbot-ac7c0126f39e71022150fadced33c951f1dd52b0.zip
Added a transaction for handling the nextQuoteID.
Diffstat (limited to '')
-rw-r--r--Hsbot/Plugin/Quote.hs11
1 files changed, 10 insertions, 1 deletions
diff --git a/Hsbot/Plugin/Quote.hs b/Hsbot/Plugin/Quote.hs
index d849c22..7e52e5b 100644
--- a/Hsbot/Plugin/Quote.hs
+++ b/Hsbot/Plugin/Quote.hs
@@ -101,8 +101,17 @@ setQuote quoteId theQuote = get >>= \db -> put db { quoteBotDB = M.insert quoteI
getLastActiveQuote :: IRC.Channel -> Query QuoteDB (Maybe QuoteID)
getLastActiveQuote channel = fmap (M.lookup channel) (asks lastActive)
+takeNextQuoteID :: IRC.UserName -> IRC.Channel -> UTCTime -> Update QuoteDB (QuoteID)
+takeNextQuoteID requestor channel now = do
+ db <- get
+ let quoteId = nextQuoteId db
+ put db { nextQuoteId = nextQuoteId db + 1
+ , lockedQuotes = M.insert quoteId (requestor, now) (lockedQuotes db)
+ , lastActive = M.insert channel quoteId (lastActive db) }
+ return quoteId
+
$(makeAcidic ''QuoteDB [ 'getQuote, 'getQuoteDB, 'isQuoteLockedFor, 'lockQuoteIdFor, 'deleteQuote, 'setQuote
- , 'getLastActiveQuote ])
+ , 'getLastActiveQuote, 'takeNextQuoteID ])
-- | gets a random quote from the database
getRandomQuote :: AcidState QuoteDB -> IO (Maybe Quote)