summaryrefslogtreecommitdiff
path: root/Hsbot/Irc/Plugin
diff options
context:
space:
mode:
authorJulien Dessaux2010-05-16 17:58:38 +0200
committerJulien Dessaux2010-05-16 17:58:38 +0200
commit738ad9e9bbbefb43a7889a458ff1c326a324eb9a (patch)
treef8337cc73ffdfa6956dc9425a8338fe496eafec7 /Hsbot/Irc/Plugin
parentRewrote nearly everything! (diff)
downloadhsbot-738ad9e9bbbefb43a7889a458ff1c326a324eb9a.tar.gz
hsbot-738ad9e9bbbefb43a7889a458ff1c326a324eb9a.tar.bz2
hsbot-738ad9e9bbbefb43a7889a458ff1c326a324eb9a.zip
Removed thread ids from plugins data structure.
Diffstat (limited to '')
-rw-r--r--Hsbot/Irc/Plugin.hs15
-rw-r--r--Hsbot/Irc/Plugin/Core.hs4
-rw-r--r--Hsbot/Irc/Plugin/Dummy.hs3
-rw-r--r--Hsbot/Irc/Plugin/Ping.hs3
-rw-r--r--Hsbot/Irc/Plugin/Quote.hs3
-rw-r--r--Hsbot/Irc/PluginCommons.hs1
6 files changed, 8 insertions, 21 deletions
diff --git a/Hsbot/Irc/Plugin.hs b/Hsbot/Irc/Plugin.hs
index b12d922..525ab8f 100644
--- a/Hsbot/Irc/Plugin.hs
+++ b/Hsbot/Irc/Plugin.hs
@@ -48,14 +48,13 @@ loadIrcPlugin pluginName = do
let oldPlugins = ircBotPlugins ircbot
-- We check for unicity
case M.lookup pluginName oldPlugins of
- Just plugin -> return ()
- Nothing -> do
+ Just _ -> return ()
+ Nothing -> do
threadId <- liftIO $ forkIO (entryPoint pluginChan masterChan)
let plugin = IrcPluginState { ircPluginName = pluginName
- , ircPluginThreadId = threadId
, ircPluginChan = pluginChan
, ircPluginMasterChan = masterChan }
- put $ ircbot { ircBotPlugins = M.insert pluginName plugin oldPlugins }
+ put $ ircbot { ircBotPlugins = M.insert pluginName (plugin, threadId) oldPlugins }
-- | Sends a list of loaded plugins
listPlugins :: IrcMsg -> String -> IrcBot ()
@@ -63,8 +62,8 @@ listPlugins originalRequest dest = do
plugins <- gets ircBotPlugins
let listing = unwords $ M.keys plugins
case M.lookup dest plugins of
- Just plugin -> sendToPlugin (IntIrcCmd $ IrcCmd "ANSWER" "CORE" dest listing originalRequest) plugin
- Nothing -> return ()
+ Just (plugin, _) -> sendToPlugin (IntIrcCmd $ IrcCmd "ANSWER" "CORE" dest listing originalRequest) plugin
+ Nothing -> return ()
-- | Unloads a plugin
unloadPlugin :: String -> IrcBot ()
@@ -72,9 +71,9 @@ unloadPlugin name = do
bot <- get
let oldPlugins = ircBotPlugins bot
case M.lookup name oldPlugins of
- Just plugin -> do
+ Just (_, threadId) -> do
let newPlugins = M.delete name oldPlugins
- liftIO $ throwTo (ircPluginThreadId plugin) UserInterrupt
+ liftIO $ throwTo threadId UserInterrupt
put $ bot { ircBotPlugins = newPlugins }
Nothing -> return ()
diff --git a/Hsbot/Irc/Plugin/Core.hs b/Hsbot/Irc/Plugin/Core.hs
index 5d69ca3..9987a89 100644
--- a/Hsbot/Irc/Plugin/Core.hs
+++ b/Hsbot/Irc/Plugin/Core.hs
@@ -2,7 +2,7 @@ module Hsbot.Irc.Plugin.Core
( ircBotPluginCore
) where
-import Control.Concurrent (Chan, myThreadId)
+import Control.Concurrent (Chan)
import Control.Exception
import Control.Monad.State
import Prelude hiding (catch)
@@ -13,9 +13,7 @@ import Hsbot.Irc.PluginCommons
-- | The plugin's main entry point
ircBotPluginCore :: Chan IrcBotMsg -> Chan IrcBotMsg -> IO ()
ircBotPluginCore myChan masterChan = do
- threadId <- myThreadId
let plugin = IrcPluginState { ircPluginName = "Core"
- , ircPluginThreadId = threadId
, ircPluginChan = myChan
, ircPluginMasterChan = masterChan }
evalStateT (mapM_ sendRegisterCommand ["list", "load", "reload", "unload"]) plugin
diff --git a/Hsbot/Irc/Plugin/Dummy.hs b/Hsbot/Irc/Plugin/Dummy.hs
index 48515ce..c543b90 100644
--- a/Hsbot/Irc/Plugin/Dummy.hs
+++ b/Hsbot/Irc/Plugin/Dummy.hs
@@ -2,7 +2,6 @@ module Hsbot.Irc.Plugin.Dummy
( ircBotPluginDummy
) where
-import Control.Concurrent (myThreadId)
import Control.Concurrent.Chan
import Control.Exception
import Control.Monad.State
@@ -14,9 +13,7 @@ import Hsbot.Irc.PluginCommons
-- | The plugin's main entry point
ircBotPluginDummy :: Chan IrcBotMsg -> Chan IrcBotMsg -> IO ()
ircBotPluginDummy myChan masterChan = do
- threadId <- myThreadId
let plugin = IrcPluginState { ircPluginName = "Dummy"
- , ircPluginThreadId = threadId
, ircPluginChan = myChan
, ircPluginMasterChan = masterChan }
_ <- (execStateT run plugin) `catch` (\(_ :: AsyncException) -> return plugin)
diff --git a/Hsbot/Irc/Plugin/Ping.hs b/Hsbot/Irc/Plugin/Ping.hs
index 6a38f0d..90579c4 100644
--- a/Hsbot/Irc/Plugin/Ping.hs
+++ b/Hsbot/Irc/Plugin/Ping.hs
@@ -2,7 +2,6 @@ module Hsbot.Irc.Plugin.Ping
( ircBotPluginPing
) where
-import Control.Concurrent (myThreadId)
import Control.Concurrent.Chan
import Control.Exception
import Control.Monad.State
@@ -14,9 +13,7 @@ import Hsbot.Irc.PluginCommons
-- | The plugin's main entry point
ircBotPluginPing :: Chan IrcBotMsg -> Chan IrcBotMsg -> IO ()
ircBotPluginPing myChan masterChan = do
- threadId <- myThreadId
let plugin = IrcPluginState { ircPluginName = "Ping"
- , ircPluginThreadId = threadId
, ircPluginChan = myChan
, ircPluginMasterChan = masterChan }
_ <- (execStateT run plugin) `catch` (\(_ :: AsyncException) -> return plugin)
diff --git a/Hsbot/Irc/Plugin/Quote.hs b/Hsbot/Irc/Plugin/Quote.hs
index ff037c7..31eaeaf 100644
--- a/Hsbot/Irc/Plugin/Quote.hs
+++ b/Hsbot/Irc/Plugin/Quote.hs
@@ -2,7 +2,6 @@ module Hsbot.Irc.Plugin.Quote
( ircBotPluginQuote
) where
-import Control.Concurrent (myThreadId)
import Control.Concurrent.Chan
import Control.Exception
import Control.Monad.State
@@ -61,9 +60,7 @@ ircBotPluginQuote myChan masterChan = do
txtQuoteBot <- TIO.readFile $ dbfile
let quoteBot = read (T.unpack txtQuoteBot) :: QuoteBotState
-- The plugin main loop
- threadId <- myThreadId
let plugin = IrcPluginState { ircPluginName = "Quote"
- , ircPluginThreadId = threadId
, ircPluginChan = myChan
, ircPluginMasterChan = masterChan }
evalStateT (mapM_ sendRegisterCommand ["quote"]) plugin
diff --git a/Hsbot/Irc/PluginCommons.hs b/Hsbot/Irc/PluginCommons.hs
index 71f00a4..51f9473 100644
--- a/Hsbot/Irc/PluginCommons.hs
+++ b/Hsbot/Irc/PluginCommons.hs
@@ -23,7 +23,6 @@ type IrcPlugin = StateT IrcPluginState IO
-- | A plugin state
data IrcPluginState = IrcPluginState
{ ircPluginName :: String -- The plugin's name
- , ircPluginThreadId :: ThreadId -- The plugin thread
, ircPluginChan :: Chan IrcBotMsg -- The plugin chan
, ircPluginMasterChan :: Chan IrcBotMsg -- The master's chan
}