summaryrefslogtreecommitdiff
path: root/Hsbot/Plugin.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-05-24 23:50:59 +0200
committerJulien Dessaux2010-05-24 23:52:47 +0200
commit8b33600f3818edd9aa9dedfa7a9a03d6e2af3276 (patch)
tree50a8ae73d0c67df2f9349d96fd47b65a10244185 /Hsbot/Plugin.hs
parentImplemented ircbot update messages. (diff)
downloadhsbot-8b33600f3818edd9aa9dedfa7a9a03d6e2af3276.tar.gz
hsbot-8b33600f3818edd9aa9dedfa7a9a03d6e2af3276.tar.bz2
hsbot-8b33600f3818edd9aa9dedfa7a9a03d6e2af3276.zip
Implemented update message handling in the bot's core.
Diffstat (limited to 'Hsbot/Plugin.hs')
-rw-r--r--Hsbot/Plugin.hs35
1 files changed, 22 insertions, 13 deletions
diff --git a/Hsbot/Plugin.hs b/Hsbot/Plugin.hs
index 47dd0f5..aafa495 100644
--- a/Hsbot/Plugin.hs
+++ b/Hsbot/Plugin.hs
@@ -1,23 +1,32 @@
module Hsbot.Plugin
- ( Plugin
- , PluginState (..)
+ ( spawnIrcPlugins
) where
import Control.Concurrent
import Control.Concurrent.Chan ()
import Control.Monad.State
import qualified Data.Map as M
-import IO (Handle)
-import Hsbot.Message
+import Hsbot.Config
+import Hsbot.Irc.Config
+import Hsbot.Irc.Core
+import Hsbot.Types
--- | The Plugin monad
-type Plugin = StateT PluginState IO
-
--- | A plugin state
-data PluginState = PluginState
- { pluginName :: String -- The plugin's name
- , pluginChan :: Chan BotMsg -- The plugin chan
- , pluginHandles :: M.Map String Handle -- the plugins's handles
- }
+-- | spawns IrcPlugins
+spawnIrcPlugins :: Bot ()
+spawnIrcPlugins = do
+ config <- gets botConfig
+ mapM_ (spawnIrcPlugin) (ircConfigs config)
+ where
+ spawnIrcPlugin :: IrcConfig -> Bot ()
+ spawnIrcPlugin config = do
+ bot <- get
+ let chan = botChan bot
+ pchan <- liftIO (newChan :: IO (Chan BotMsg))
+ threadId <- liftIO $ forkIO (startIrcbot config chan pchan)
+ let plugin = PluginState { pluginName = ircConfigName config
+ , pluginChan = pchan
+ , pluginHandles = M.empty }
+ plugins = botPlugins bot
+ put $ bot { botPlugins = M.insert (pluginName plugin) (plugin, threadId) plugins }