Archived
1
0
Fork 0

Fixed several stuff.

This commit is contained in:
Julien Dessaux 2010-04-21 20:57:22 +02:00
parent bfc06f1ff1
commit 4c76d3d40b
10 changed files with 25 additions and 21 deletions

View file

@ -58,7 +58,7 @@ dispatchMessage (InputMsg inputMsg) = do
sendRunCommand cmd plugin = do sendRunCommand cmd plugin = do
sendToPlugin (InternalCmd $ IntCmd "RUN" "CORE" (pluginName plugin) cmd) plugin sendToPlugin (InternalCmd $ IntCmd "RUN" "CORE" (pluginName plugin) cmd) plugin
getMsgContent :: String getMsgContent :: String
getMsgContent = (parameters inputMsg) !! 1 getMsgContent = unwords . tail $ parameters inputMsg
dispatchMessage _ = return () dispatchMessage _ = return ()
-- | Processes an internal command -- | Processes an internal command

View file

@ -4,9 +4,9 @@ module Hsbot.Core
) where ) where
import Control.Concurrent import Control.Concurrent
import Control.Concurrent.Chan import Control.Concurrent.Chan()
import Control.Monad.State import Control.Monad.State
import Data.List import Data.List()
import qualified Data.Map as M import qualified Data.Map as M
import Network import Network
import System.IO import System.IO
@ -36,8 +36,8 @@ connectServer server = do
disconnectServer :: IrcBot () disconnectServer :: IrcBot ()
disconnectServer = do disconnectServer = do
bot <- get bot <- get
liftIO $ killThread $ readerThreadId bot
mapM_ unloadPlugin (M.keys $ botPlugins bot) mapM_ unloadPlugin (M.keys $ botPlugins bot)
liftIO $ killThread $ readerThreadId bot
liftIO $ hClose $ botHandle bot liftIO $ hClose $ botHandle bot
return () return ()

View file

@ -23,7 +23,7 @@ initServer = do
-- | Run a server -- | Run a server
runServer :: IrcBot () runServer :: IrcBot ()
runServer = do runServer = forever $ do
chan <- gets botChannel chan <- gets botChannel
let input = readChan chan let input = readChan chan
msg <- liftIO input msg <- liftIO input
@ -31,7 +31,6 @@ runServer = do
InputMsg inputMsg -> dispatchMessage $ InputMsg inputMsg InputMsg inputMsg -> dispatchMessage $ InputMsg inputMsg
OutputMsg outputMsg -> sendstr (serializeIrcMsg outputMsg) OutputMsg outputMsg -> sendstr (serializeIrcMsg outputMsg)
InternalCmd internalCmd -> processInternalCommand $ InternalCmd internalCmd InternalCmd internalCmd -> processInternalCommand $ InternalCmd internalCmd
runServer
-- | Joins a chan -- | Joins a chan
joinChan :: String -> IrcBot () joinChan :: String -> IrcBot ()

View file

@ -24,9 +24,9 @@ pMsg = do
pPrefix :: ParsecT String u Identity [Char] pPrefix :: ParsecT String u Identity [Char]
pPrefix = do pPrefix = do
char ':' _ <- char ':'
pfx <- many1 (noneOf " ") pfx <- many1 (noneOf " ")
space _ <- space
return pfx return pfx
pCommand :: ParsecT String u Identity [Char] pCommand :: ParsecT String u Identity [Char]

View file

@ -5,7 +5,7 @@ module Hsbot.Main
import Control.Exception import Control.Exception
import Control.Monad.State import Control.Monad.State
import Prelude hiding (catch) import Prelude hiding (catch)
import System.IO import System.IO()
import Config import Config
import Hsbot.Core import Hsbot.Core
@ -17,8 +17,8 @@ import Hsbot.Types
imain :: IO () imain :: IO ()
imain = do imain = do
bot <- connectServer $ ircServer config bot <- connectServer $ ircServer config
(execStateT run bot) `catch` (\(ex :: IOException) -> return bot) bot' <- (execStateT run bot) `catch` (\(_ :: IOException) -> return bot)
evalStateT disconnectServer bot evalStateT disconnectServer bot'
-- | The Bot monad main function -- | The Bot monad main function
run :: IrcBot () run :: IrcBot ()

View file

@ -13,7 +13,7 @@ module Hsbot.Types
) where ) where
import Control.Concurrent import Control.Concurrent
import Control.Concurrent.Chan import Control.Concurrent.Chan()
import Control.Monad.State import Control.Monad.State
import qualified Data.Map as M import qualified Data.Map as M
import Network import Network
@ -97,7 +97,7 @@ data IntCmd = IntCmd
, intCmdMsg :: String -- the IrcMsg associated with the command , intCmdMsg :: String -- the IrcMsg associated with the command
} deriving (Show) } deriving (Show)
data BotMsg = InputMsg IrcMsg | OutputMsg IrcMsg | InternalCmd IntCmd data BotMsg = InputMsg IrcMsg | OutputMsg IrcMsg | InternalCmd IntCmd deriving (Show)
-- | A plugin (core side) -- | A plugin (core side)
data Plugin = Plugin data Plugin = Plugin

View file

@ -1,8 +1,14 @@
all: all:
ghc --make -Wall -O2 Main.hs -o hsbot -XScopedTypeVariables ghc --make -Wall -O2 Main.hs -o hsbot -XScopedTypeVariables
listen:
nc -l 127.0.0.1 6667
run:
runghc -XScopedTypeVariables Main
clean: clean:
- rm hsbot - rm hsbot
- find ./ -name \*.o -exec rm {} + - find ./ -name \*.o -exec rm {} \;
- find ./ -name \*.hi -exec rm {} + - find ./ -name \*.hi -exec rm {} \;

View file

@ -2,7 +2,7 @@ module Plugins.Core
( mainCore ( mainCore
) where ) where
import Control.Concurrent.Chan import Control.Concurrent.Chan(Chan)
import Control.Exception import Control.Exception
import Control.Monad.State import Control.Monad.State
import Prelude hiding (catch) import Prelude hiding (catch)
@ -16,8 +16,8 @@ mainCore :: Chan BotMsg -> Chan BotMsg -> IO ()
mainCore serverChan chan = do mainCore serverChan chan = do
let plugin = PluginInstance "Core" serverChan chan let plugin = PluginInstance "Core" serverChan chan
evalStateT (mapM_ sendRegisterCommand ["list", "load", "reload", "unload"]) plugin evalStateT (mapM_ sendRegisterCommand ["list", "load", "reload", "unload"]) plugin
(execStateT run plugin) `catch` (\(ex :: AsyncException) -> return plugin) plugin' <- (execStateT run plugin) `catch` (\(_ :: AsyncException) -> return plugin)
evalStateT (mapM_ sendUnregisterCommand ["list", "load", "reload", "unload"]) plugin evalStateT (mapM_ sendUnregisterCommand ["list", "load", "reload", "unload"]) plugin'
-- | The IrcPlugin monad main function -- | The IrcPlugin monad main function
run :: IrcPlugin () run :: IrcPlugin ()

View file

@ -14,7 +14,7 @@ import Hsbot.Types
mainPing :: Chan BotMsg -> Chan BotMsg -> IO () mainPing :: Chan BotMsg -> Chan BotMsg -> IO ()
mainPing serverChan chan = do mainPing serverChan chan = do
let plugin = PluginInstance "Ping" serverChan chan let plugin = PluginInstance "Ping" serverChan chan
(execStateT run plugin) `catch` (\(ex :: AsyncException) -> return plugin) _ <- (execStateT run plugin) `catch` (\(_ :: AsyncException) -> return plugin)
return () return ()
-- | The IrcPlugin monad main function -- | The IrcPlugin monad main function

3
TODO
View file

@ -1,13 +1,12 @@
:julien!~julien@ogu21.corp PRIVMSG #shbot :@quote graou snif :julien!~julien@ogu21.corp PRIVMSG #shbot :@quote graou snif
* Solve the catching that never happen in main
* throwto exception to main thread * throwto exception to main thread
* list plugins * list plugins
* write a safe reload : try reload before unloading * write a safe reload : try reload before unloading
* discard all trace with a color param and replace those with functions info/warn/error/debug * discard all trace with a color param and replace those with functions info/warn/error/debug
* clean the plugin module * clean the plugin module
* kill threads
* plugin reload
* list modules command * list modules command
* part chan * part chan