diff options
-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) |