diff options
author | Julien Dessaux | 2011-09-30 21:40:23 +0200 |
---|---|---|
committer | Julien Dessaux | 2011-09-30 21:40:23 +0200 |
commit | ac7c0126f39e71022150fadced33c951f1dd52b0 (patch) | |
tree | 43a2f347dc338729ab3c95384556f9e4f4d4f493 | |
parent | Cosmetic. (diff) | |
download | hsbot-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.hs | 11 |
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) |