diff options
| author | pb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157> | 2010-05-15 18:03:15 +0000 |
|---|---|---|
| committer | pb <pb@9f8f72e9-4bf4-416e-b76e-7d4203597157> | 2010-05-15 18:03:15 +0000 |
| commit | c675c92a06761d6b28f8fdda8cc418b64a040c9a (patch) | |
| tree | ab99e34875ca832a867a73cc4fc0dc94cd5be6f4 | |
| parent | d80cee1ecddeb75e54de767c35f04a9a004eed12 (diff) | |
renamed Callbacks into Plugins
git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@67 9f8f72e9-4bf4-416e-b76e-7d4203597157
| -rw-r--r-- | HsBot/Base.hs | 4 | ||||
| -rw-r--r-- | HsBot/Callbacks.hs | 28 | ||||
| -rw-r--r-- | HsBot/Plugins.hs | 28 | ||||
| -rw-r--r-- | HsBot/Plugins/Base.hs (renamed from HsBot/Callbacks/Base.hs) | 5 | ||||
| -rw-r--r-- | HsBot/Plugins/Dummy.hs (renamed from HsBot/Callbacks/Dummy.hs) | 6 | ||||
| -rw-r--r-- | HsBot/Plugins/MessageCounter.hs (renamed from HsBot/Callbacks/MessageCounter.hs) | 6 | ||||
| -rw-r--r-- | HsBot/Plugins/PrintMessages.hs (renamed from HsBot/Callbacks/PrintMessages.hs) | 6 | ||||
| -rw-r--r-- | HsBot/Plugins/StoreMessages.hs (renamed from HsBot/Callbacks/StoreMessages.hs) | 6 | ||||
| -rw-r--r-- | hsbot.db | 2 |
9 files changed, 45 insertions, 46 deletions
diff --git a/HsBot/Base.hs b/HsBot/Base.hs index 1c3d4a4..15f794e 100644 --- a/HsBot/Base.hs +++ b/HsBot/Base.hs @@ -8,7 +8,7 @@ import HsBot.Base.Env import HsBot.Base.State import HsBot.General.Tools import HsBot.IRC -import HsBot.Callbacks +import HsBot.Plugins startBase :: IO () startBase = do @@ -27,7 +27,7 @@ dispatch msg sendMessage env@(Env state conf) = dispatch' msg cmdAction state return (env) Nothing -> return (env) - dispatch' _ = callbacksRun msg sendMessage env + dispatch' _ = pluginsTrigger msg sendMessage env commands = [ Cmd "!h" "Prints help" printHelp, Cmd "!i" "Prints infos" printInfos, diff --git a/HsBot/Callbacks.hs b/HsBot/Callbacks.hs deleted file mode 100644 index 0bbf08f..0000000 --- a/HsBot/Callbacks.hs +++ /dev/null @@ -1,28 +0,0 @@ -module HsBot.Callbacks (callbacksRun) where - -import HsBot.Base.Env -import HsBot.Base.State - -import HsBot.Callbacks.Base -import HsBot.Callbacks.MessageCounter -import HsBot.Callbacks.PrintMessages -import HsBot.Callbacks.StoreMessages -import HsBot.Callbacks.Dummy - -registeredCallbacks = [ - makeMessageCounter, - makePrintMessages, - makeStoreMessages, - makeDummy - ] - -callbacksRun :: String -> SendMessage -> Env -> IO Env -callbacksRun str sendMessage env@(Env state _) - | isReady state = callbackAll registeredCallbacks env - | otherwise = do { putStrLn str; return (env) } - where - callbackAll [] env = return (env) - callbackAll (callback:restCallbacks) env = do - env' <- (cbFunction callback) str sendMessage env - callbackAll restCallbacks env' - diff --git a/HsBot/Plugins.hs b/HsBot/Plugins.hs new file mode 100644 index 0000000..28e1de2 --- /dev/null +++ b/HsBot/Plugins.hs @@ -0,0 +1,28 @@ +module HsBot.Plugins (pluginsTrigger) where + +import HsBot.Base.Env +import HsBot.Base.State + +import HsBot.Plugins.Base +import HsBot.Plugins.MessageCounter +import HsBot.Plugins.PrintMessages +import HsBot.Plugins.StoreMessages +import HsBot.Plugins.Dummy + +registeredPlugins = [ + makeMessageCounter, + makePrintMessages, + makeStoreMessages, + makeDummy + ] + +pluginsTrigger :: String -> SendMessage -> Env -> IO Env +pluginsTrigger str sendMessage env@(Env state _) + | isReady state = pluginsAll registeredPlugins env + | otherwise = do { putStrLn str; return (env) } + where + pluginsAll [] env = return (env) + pluginsAll (plugin:restPlugins) env = do + env' <- (cbFunction plugin) str sendMessage env + pluginsAll restPlugins env' + diff --git a/HsBot/Callbacks/Base.hs b/HsBot/Plugins/Base.hs index 40e9769..a8acbfb 100644 --- a/HsBot/Callbacks/Base.hs +++ b/HsBot/Plugins/Base.hs @@ -1,13 +1,12 @@ -module HsBot.Callbacks.Base where +module HsBot.Plugins.Base where import HsBot.Base.Env import HsBot.Base.State type CallbackFunction = String -> SendMessage -> Env -> IO Env -data Callback a = Callback { +data Plugin a = Plugin { cbPrio :: Integer, cbFunction :: CallbackFunction } - diff --git a/HsBot/Callbacks/Dummy.hs b/HsBot/Plugins/Dummy.hs index 3096af5..dd10c83 100644 --- a/HsBot/Callbacks/Dummy.hs +++ b/HsBot/Plugins/Dummy.hs @@ -1,6 +1,6 @@ -module HsBot.Callbacks.Dummy (makeDummy) where +module HsBot.Plugins.Dummy (makeDummy) where -import HsBot.Callbacks.Base +import HsBot.Plugins.Base import HsBot.Base.Env import HsBot.Base.State @@ -8,4 +8,4 @@ import HsBot.Base.State dummy :: CallbackFunction dummy str sendMessage env@(Env state _) = return (env) -makeDummy = Callback 0 dummy +makeDummy = Plugin 0 dummy diff --git a/HsBot/Callbacks/MessageCounter.hs b/HsBot/Plugins/MessageCounter.hs index 18f6dba..0fa5545 100644 --- a/HsBot/Callbacks/MessageCounter.hs +++ b/HsBot/Plugins/MessageCounter.hs @@ -1,6 +1,6 @@ -module HsBot.Callbacks.MessageCounter (makeMessageCounter) where +module HsBot.Plugins.MessageCounter (makeMessageCounter) where -import HsBot.Callbacks.Base +import HsBot.Plugins.Base import HsBot.Base.Env import HsBot.Base.State @@ -13,4 +13,4 @@ messageCounter :: CallbackFunction messageCounter str sendMessage (Env state conf) = do return (Env (stateUpdateUser state (currentSender state) update) conf) -makeMessageCounter = Callback 0 messageCounter +makeMessageCounter = Plugin 0 messageCounter diff --git a/HsBot/Callbacks/PrintMessages.hs b/HsBot/Plugins/PrintMessages.hs index 2674aa9..d3bfbc8 100644 --- a/HsBot/Callbacks/PrintMessages.hs +++ b/HsBot/Plugins/PrintMessages.hs @@ -1,6 +1,6 @@ -module HsBot.Callbacks.PrintMessages (makePrintMessages) where +module HsBot.Plugins.PrintMessages (makePrintMessages) where -import HsBot.Callbacks.Base +import HsBot.Plugins.Base import HsBot.Base.Env import HsBot.Base.State @@ -12,4 +12,4 @@ printMessages str sendMessage env@(Env state _) = do ++ str return (env) -makePrintMessages = Callback 0 printMessages +makePrintMessages = Plugin 0 printMessages diff --git a/HsBot/Callbacks/StoreMessages.hs b/HsBot/Plugins/StoreMessages.hs index 0a7ab4d..a0033f7 100644 --- a/HsBot/Callbacks/StoreMessages.hs +++ b/HsBot/Plugins/StoreMessages.hs @@ -1,6 +1,6 @@ -module HsBot.Callbacks.StoreMessages (makeStoreMessages) where +module HsBot.Plugins.StoreMessages (makeStoreMessages) where -import HsBot.Callbacks.Base +import HsBot.Plugins.Base import HsBot.Base.Env import HsBot.Base.State @@ -9,4 +9,4 @@ storeMessages :: CallbackFunction storeMessages str sendMessage env@(Env state _) = do return (env) -makeStoreMessages = Callback 0 storeMessages +makeStoreMessages = Plugin 0 storeMessages @@ -1 +1 @@ -State {isReady = False, currentSender = "", currentChannel = "#buetow.org", line = "!w\DELs", users = []} +State {isReady = True, currentSender = "ranti|haskell", currentChannel = "#buetow.org", line = "!w\DELs", users = [User {userName = "ranti|haskell", userMessages = 4, userPts = 0}]}
\ No newline at end of file |
