blob: 15f794ea6ae1bab39c684db3f625410486ffe183 (
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
48
49
50
51
|
module HsBot.Base (startBase) where
import System
import HsBot.Base.Cmd
import HsBot.Base.Conf
import HsBot.Base.Env
import HsBot.Base.State
import HsBot.General.Tools
import HsBot.IRC
import HsBot.Plugins
startBase :: IO ()
startBase = do
let conf = makeConf
databaseFile <- get "databaseFile" conf
let state = stateLoad databaseFile
state' <- state -- Extract State from the IO Monad
ircStart (DispatchEnv state' conf dispatch)
dispatch :: DispatchFunction
dispatch msg sendMessage env@(Env state conf) = dispatch' msg
where
dispatch' ('!':_) =
case cmdGet msg commands of
Just (Cmd _ _ cmdAction) -> do
cmdAction state
return (env)
Nothing -> return (env)
dispatch' _ = pluginsTrigger msg sendMessage env
commands = [
Cmd "!h" "Prints help" printHelp,
Cmd "!i" "Prints infos" printInfos,
Cmd "!p" "Prints current state" printState,
Cmd "!s" "Stores current state to file" storeState,
Cmd "!q" "quits" quit
]
printHelp _ = printHelp' commands
where printHelp' = sendMessage . concat . showL
printInfos _ = do
sendMessage $ (envGet "name" env)
++ " " ++ (envGet "version" env)
++ " (try !h)"
printState = sendMessage . show
storeState state = do
sendMessage "Storing current state"
stateSave (envGet "databaseFile" env) state
quit state = do
sendMessage "Good bye"
stateSave (envGet "databaseFile" env) state
exitWith ExitSuccess
|