blob: 6547cd16274563da6f55154ee76750d9fd048ae9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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 ()
|