summaryrefslogtreecommitdiff
path: root/Hsbot
diff options
context:
space:
mode:
authorJulien Dessaux2011-10-01 00:29:18 +0200
committerJulien Dessaux2011-10-01 00:29:18 +0200
commitf0c95c5c28989b7869ff7d9c31b0ba91900c7ddb (patch)
treefaef742446820bde0b845e3fb644f7c3fd9827cb /Hsbot
parentAdded back the setLastActiveQuote transaction. (diff)
downloadhsbot-f0c95c5c28989b7869ff7d9c31b0ba91900c7ddb.tar.gz
hsbot-f0c95c5c28989b7869ff7d9c31b0ba91900c7ddb.tar.bz2
hsbot-f0c95c5c28989b7869ff7d9c31b0ba91900c7ddb.zip
Added quote show.
Diffstat (limited to 'Hsbot')
-rw-r--r--Hsbot/Plugin/Quote.hs30
1 files changed, 30 insertions, 0 deletions
diff --git a/Hsbot/Plugin/Quote.hs b/Hsbot/Plugin/Quote.hs
index 33c29cc..b52137b 100644
--- a/Hsbot/Plugin/Quote.hs
+++ b/Hsbot/Plugin/Quote.hs
@@ -180,6 +180,16 @@ theQuote = do
answerMsg msg $ "Usage: quote { [start] QUOTEE [QUOTE] | append [QUOTEID] QUOTEE QUOTE | "
++ "delete QUOTEID [ELTID] | show { QUOTEID | random [MIN_SCORE] } | stat }"
"quote":"help":_ -> answerMsg msg "Invalid help topic."
+ "quote":"show":"random":[] -> showRandomQuote
+ "quote":"show":quoteID:[] ->
+ case reads quoteID :: [(Int, String)] of
+ (qid,_):_ -> do
+ thisQuote <- query' quoteDB (GetQuote qid)
+ case thisQuote of
+ Just this -> quoteShow quoteDB msg qid this
+ Nothing -> answerMsg msg $ (getSender msg) ++ ": Invalid quoteID or empty database."
+ _ -> answerMsg msg $ getSender msg ++ " : Invalid quoteID."
+ "quote":"show":[] -> showRandomQuote
"quote":"start":quotee:[phrase] -> quoteStart quoteDB msg quotee phrase
"quote":quotee:[phrase] -> quoteStart quoteDB msg quotee phrase
"quote":_ -> answerMsg msg "Invalid quote command."
@@ -192,6 +202,13 @@ theQuote = do
"vote":_ -> answerMsg msg "Invalid vote command."
_ -> return ()
| otherwise = return ()
+ where
+ showRandomQuote :: Plugin (Env IO) ()
+ showRandomQuote = do
+ rquote <- liftIO (getRandomQuote quoteDB)
+ case rquote of
+ Just (that, qid) -> quoteShow quoteDB msg qid that
+ Nothing -> answerMsg msg $ (getSender msg) ++ ": the quote database is empty."
eval _ _ = return ()
quoteAppend :: AcidState QuoteDB -> IRC.Message -> QuoteID -> IRC.UserName -> String -> Plugin (Env IO) ()
@@ -250,6 +267,19 @@ quoteDeleteElt quoteDB msg quoteID eltID = do
| otherwise = let (l, r) = splitAt eltID elts
in l ++ tail r
+quoteShow :: AcidState QuoteDB -> IRC.Message -> QuoteID -> Quote -> Plugin (Env IO) ()
+quoteShow quoteDB msg quoteID thatQuote = do
+ mapM_ (answerMsg msg) $ formatQuote
+ update' quoteDB (SetLastActiveQuote channel quoteID)
+ where
+ channel = getChannel msg
+ formatQuote :: [String]
+ formatQuote = ("+-- [" ++ show quoteID ++ "] --- Reported by " ++ quoter thatQuote ++ " on " ++ quoteFrom thatQuote)
+ : map formatElt (quotE thatQuote)
+ ++ [ "+-- Added on " ++ show (quoteTime thatQuote) ++ " --- Score : " ++ show (votes thatQuote) ]
+ formatElt :: QuoteElt -> String
+ formatElt this = "| " ++ eltQuotee this ++ ": " ++ eltQuote this
+
quoteStart :: AcidState QuoteDB -> IRC.Message -> IRC.UserName -> String -> Plugin (Env IO) ()
quoteStart quoteDB msg quotee phrase =
case phrase of