From c675c92a06761d6b28f8fdda8cc418b64a040c9a Mon Sep 17 00:00:00 2001 From: pb Date: Sat, 15 May 2010 18:03:15 +0000 Subject: renamed Callbacks into Plugins git-svn-id: https://ssl.buetow.org/repos/hsbot/trunk@67 9f8f72e9-4bf4-416e-b76e-7d4203597157 --- HsBot/Base.hs | 4 ++-- HsBot/Callbacks.hs | 28 ---------------------------- HsBot/Callbacks/Base.hs | 13 ------------- HsBot/Callbacks/Dummy.hs | 11 ----------- HsBot/Callbacks/MessageCounter.hs | 16 ---------------- HsBot/Callbacks/PrintMessages.hs | 15 --------------- HsBot/Callbacks/StoreMessages.hs | 12 ------------ HsBot/Plugins.hs | 28 ++++++++++++++++++++++++++++ HsBot/Plugins/Base.hs | 12 ++++++++++++ HsBot/Plugins/Dummy.hs | 11 +++++++++++ HsBot/Plugins/MessageCounter.hs | 16 ++++++++++++++++ HsBot/Plugins/PrintMessages.hs | 15 +++++++++++++++ HsBot/Plugins/StoreMessages.hs | 12 ++++++++++++ hsbot.db | 2 +- 14 files changed, 97 insertions(+), 98 deletions(-) delete mode 100644 HsBot/Callbacks.hs delete mode 100644 HsBot/Callbacks/Base.hs delete mode 100644 HsBot/Callbacks/Dummy.hs delete mode 100644 HsBot/Callbacks/MessageCounter.hs delete mode 100644 HsBot/Callbacks/PrintMessages.hs delete mode 100644 HsBot/Callbacks/StoreMessages.hs create mode 100644 HsBot/Plugins.hs create mode 100644 HsBot/Plugins/Base.hs create mode 100644 HsBot/Plugins/Dummy.hs create mode 100644 HsBot/Plugins/MessageCounter.hs create mode 100644 HsBot/Plugins/PrintMessages.hs create mode 100644 HsBot/Plugins/StoreMessages.hs 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/Callbacks/Base.hs b/HsBot/Callbacks/Base.hs deleted file mode 100644 index 40e9769..0000000 --- a/HsBot/Callbacks/Base.hs +++ /dev/null @@ -1,13 +0,0 @@ -module HsBot.Callbacks.Base where - -import HsBot.Base.Env -import HsBot.Base.State - -type CallbackFunction = String -> SendMessage -> Env -> IO Env - -data Callback a = Callback { - cbPrio :: Integer, - cbFunction :: CallbackFunction -} - - diff --git a/HsBot/Callbacks/Dummy.hs b/HsBot/Callbacks/Dummy.hs deleted file mode 100644 index 3096af5..0000000 --- a/HsBot/Callbacks/Dummy.hs +++ /dev/null @@ -1,11 +0,0 @@ -module HsBot.Callbacks.Dummy (makeDummy) where - -import HsBot.Callbacks.Base - -import HsBot.Base.Env -import HsBot.Base.State - -dummy :: CallbackFunction -dummy str sendMessage env@(Env state _) = return (env) - -makeDummy = Callback 0 dummy diff --git a/HsBot/Callbacks/MessageCounter.hs b/HsBot/Callbacks/MessageCounter.hs deleted file mode 100644 index 18f6dba..0000000 --- a/HsBot/Callbacks/MessageCounter.hs +++ /dev/null @@ -1,16 +0,0 @@ -module HsBot.Callbacks.MessageCounter (makeMessageCounter) where - -import HsBot.Callbacks.Base - -import HsBot.Base.Env -import HsBot.Base.State - -import HsBot.IRC.User - -update user = user { userMessages = 1 + userMessages user } - -messageCounter :: CallbackFunction -messageCounter str sendMessage (Env state conf) = do - return (Env (stateUpdateUser state (currentSender state) update) conf) - -makeMessageCounter = Callback 0 messageCounter diff --git a/HsBot/Callbacks/PrintMessages.hs b/HsBot/Callbacks/PrintMessages.hs deleted file mode 100644 index 2674aa9..0000000 --- a/HsBot/Callbacks/PrintMessages.hs +++ /dev/null @@ -1,15 +0,0 @@ -module HsBot.Callbacks.PrintMessages (makePrintMessages) where - -import HsBot.Callbacks.Base - -import HsBot.Base.Env -import HsBot.Base.State - -printMessages :: CallbackFunction -printMessages str sendMessage env@(Env state _) = do - putStrLn $ (currentChannel state) ++ " " - ++ (currentSender state) ++ ": " - ++ str - return (env) - -makePrintMessages = Callback 0 printMessages diff --git a/HsBot/Callbacks/StoreMessages.hs b/HsBot/Callbacks/StoreMessages.hs deleted file mode 100644 index 0a7ab4d..0000000 --- a/HsBot/Callbacks/StoreMessages.hs +++ /dev/null @@ -1,12 +0,0 @@ -module HsBot.Callbacks.StoreMessages (makeStoreMessages) where - -import HsBot.Callbacks.Base - -import HsBot.Base.Env -import HsBot.Base.State - -storeMessages :: CallbackFunction -storeMessages str sendMessage env@(Env state _) = do - return (env) - -makeStoreMessages = Callback 0 storeMessages 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/Plugins/Base.hs b/HsBot/Plugins/Base.hs new file mode 100644 index 0000000..a8acbfb --- /dev/null +++ b/HsBot/Plugins/Base.hs @@ -0,0 +1,12 @@ +module HsBot.Plugins.Base where + +import HsBot.Base.Env +import HsBot.Base.State + +type CallbackFunction = String -> SendMessage -> Env -> IO Env + +data Plugin a = Plugin { + cbPrio :: Integer, + cbFunction :: CallbackFunction +} + diff --git a/HsBot/Plugins/Dummy.hs b/HsBot/Plugins/Dummy.hs new file mode 100644 index 0000000..dd10c83 --- /dev/null +++ b/HsBot/Plugins/Dummy.hs @@ -0,0 +1,11 @@ +module HsBot.Plugins.Dummy (makeDummy) where + +import HsBot.Plugins.Base + +import HsBot.Base.Env +import HsBot.Base.State + +dummy :: CallbackFunction +dummy str sendMessage env@(Env state _) = return (env) + +makeDummy = Plugin 0 dummy diff --git a/HsBot/Plugins/MessageCounter.hs b/HsBot/Plugins/MessageCounter.hs new file mode 100644 index 0000000..0fa5545 --- /dev/null +++ b/HsBot/Plugins/MessageCounter.hs @@ -0,0 +1,16 @@ +module HsBot.Plugins.MessageCounter (makeMessageCounter) where + +import HsBot.Plugins.Base + +import HsBot.Base.Env +import HsBot.Base.State + +import HsBot.IRC.User + +update user = user { userMessages = 1 + userMessages user } + +messageCounter :: CallbackFunction +messageCounter str sendMessage (Env state conf) = do + return (Env (stateUpdateUser state (currentSender state) update) conf) + +makeMessageCounter = Plugin 0 messageCounter diff --git a/HsBot/Plugins/PrintMessages.hs b/HsBot/Plugins/PrintMessages.hs new file mode 100644 index 0000000..d3bfbc8 --- /dev/null +++ b/HsBot/Plugins/PrintMessages.hs @@ -0,0 +1,15 @@ +module HsBot.Plugins.PrintMessages (makePrintMessages) where + +import HsBot.Plugins.Base + +import HsBot.Base.Env +import HsBot.Base.State + +printMessages :: CallbackFunction +printMessages str sendMessage env@(Env state _) = do + putStrLn $ (currentChannel state) ++ " " + ++ (currentSender state) ++ ": " + ++ str + return (env) + +makePrintMessages = Plugin 0 printMessages diff --git a/HsBot/Plugins/StoreMessages.hs b/HsBot/Plugins/StoreMessages.hs new file mode 100644 index 0000000..a0033f7 --- /dev/null +++ b/HsBot/Plugins/StoreMessages.hs @@ -0,0 +1,12 @@ +module HsBot.Plugins.StoreMessages (makeStoreMessages) where + +import HsBot.Plugins.Base + +import HsBot.Base.Env +import HsBot.Base.State + +storeMessages :: CallbackFunction +storeMessages str sendMessage env@(Env state _) = do + return (env) + +makeStoreMessages = Plugin 0 storeMessages diff --git a/hsbot.db b/hsbot.db index 55934e8..b359f45 100644 --- a/hsbot.db +++ b/hsbot.db @@ -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 -- cgit v1.2.3