summaryrefslogtreecommitdiff
path: root/Plugins/Quote.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-02-04 20:55:54 +0100
committerJulien Dessaux2010-02-04 20:55:54 +0100
commit53870767c32f61f756861d7bf18b5a55cd45a2e2 (patch)
tree2cb6b79ecaa039f472a220b26ce2af44d52b488c /Plugins/Quote.hs
parentImplemented unregisterCommand. (diff)
downloadhsbot-53870767c32f61f756861d7bf18b5a55cd45a2e2.tar.gz
hsbot-53870767c32f61f756861d7bf18b5a55cd45a2e2.tar.bz2
hsbot-53870767c32f61f756861d7bf18b5a55cd45a2e2.zip
Rewrote command handling, added the Quote module and cleaned input handling.
Diffstat (limited to 'Plugins/Quote.hs')
-rw-r--r--Plugins/Quote.hs47
1 files changed, 47 insertions, 0 deletions
diff --git a/Plugins/Quote.hs b/Plugins/Quote.hs
new file mode 100644
index 0000000..6547cd1
--- /dev/null
+++ b/Plugins/Quote.hs
@@ -0,0 +1,47 @@
+module Plugins.Quote
+ ( mainQuote
+ ) where
+
+import Control.Concurrent.Chan
+import Control.Monad.State
+import System.Time (ClockTime)
+
+import Hsbot.Core
+import Hsbot.Types
+import Hsbot.Utils
+
+-- | A quote object
+data Quote = Quote
+ { quoter :: String
+ , quote :: [String]
+ , quoteTime :: ClockTime
+ , votes :: Int
+ } deriving (Show)
+
+-- | A QuoteBot state
+type QuoteDB = [Quote]
+
+-- | The QuoteBot monad
+type QuoteBot a = StateT QuoteDB IO a
+
+-- | The main function of the Quote module
+mainQuote :: Chan BotMsg -> Chan BotMsg -> IO ()
+mainQuote serverChan chan = do
+ writeChan serverChan $ InternalCmd $ IntCmd "REGISTER COMMAND quote Quote" emptyMsg
+ loop
+ where
+ loop = do
+ input <- readChan chan
+ eval input
+ loop
+ eval :: BotMsg -> IO ()
+ eval (InternalCmd intCmd) = do
+ let command' = words $ internalCommand intCmd
+ case command' !! 0 of
+ "runCommand" -> case (command' !! 1) of
+ "quote" -> writeChan serverChan $ OutputMsg $ internalCommandMsg intCmd
+ _ -> trace $ show command' -- TODO : help message
+ _ -> trace $ show command'
+ eval (InputMsg msg) = return ()
+ eval _ = return ()
+