summaryrefslogtreecommitdiff
path: root/Hsbot
diff options
context:
space:
mode:
authorJulien Dessaux2011-04-24 23:08:06 +0200
committerJulien Dessaux2011-05-01 03:28:22 +0200
commit864a364da99a0ec05f08d7cfbad4abde416a0b06 (patch)
tree40e92cdd6913aaa0121584c3c3e7436cdf38d926 /Hsbot
parentContinue refactoring, worked on the core loop and the plugin infrastructure. (diff)
downloadhsbot-864a364da99a0ec05f08d7cfbad4abde416a0b06.tar.gz
hsbot-864a364da99a0ec05f08d7cfbad4abde416a0b06.tar.bz2
hsbot-864a364da99a0ec05f08d7cfbad4abde416a0b06.zip
Some API refactoring.
I can't say how I hate the Types.hs thing in Haskell!
Diffstat (limited to '')
-rw-r--r--Hsbot.hs1
-rw-r--r--Hsbot/Config.hs27
-rw-r--r--Hsbot/Core.hs1
-rw-r--r--Hsbot/Message.hs20
-rw-r--r--Hsbot/Plugin/Ping.hs1
-rw-r--r--Hsbot/Types.hs32
-rw-r--r--Hsbot/Utils.hs16
7 files changed, 47 insertions, 51 deletions
diff --git a/Hsbot.hs b/Hsbot.hs
index bf87df7..76e1ba6 100644
--- a/Hsbot.hs
+++ b/Hsbot.hs
@@ -7,7 +7,6 @@ import Config.Dyre.Relaunch
import Control.Monad.Reader
import System.Log.Logger
-import Hsbot.Config
import Hsbot.Core
import Hsbot.Types
diff --git a/Hsbot/Config.hs b/Hsbot/Config.hs
index 1f9329b..d51387b 100644
--- a/Hsbot/Config.hs
+++ b/Hsbot/Config.hs
@@ -1,28 +1,14 @@
module Hsbot.Config
- ( Config (..)
- , TLSConfig (..)
- , defaultConfig
+ ( defaultConfig
, defaultTLSConfig
, noSSL
) where
-import Control.Concurrent.Chan
import Network
-import qualified Network.IRC as IRC
import Network.TLS
import Network.TLS.Extra
-import Hsbot.Message
-data Config = Config
- { configErrors :: Maybe String
- , configTLS :: TLSConfig
- , configAddress :: String
- , configPort :: PortID
- , configChannels :: [String]
- , configNicknames :: [String]
- , configRealname :: String
- , configPlugins :: [(String, Chan Message -> Chan Message -> IO ())]
- }
+import Hsbot.Types
defaultConfig :: Config
defaultConfig = Config
@@ -35,15 +21,6 @@ defaultConfig = Config
, configRealname = "The One True bot, with it's haskell soul."
, configPlugins = [] }
-data TLSConfig = TLSConfig
- { sslOn :: Bool
- , sslCert :: String
- , sslKey :: String
- , sslVersions :: [Network.TLS.Version]
- , sslCiphers :: [Network.TLS.Cipher]
- , sslVerify :: Bool
- } deriving (Show)
-
defaultTLSConfig :: TLSConfig
defaultTLSConfig = TLSConfig
{ sslOn = True
diff --git a/Hsbot/Core.hs b/Hsbot/Core.hs
index d11f211..8eb4643 100644
--- a/Hsbot/Core.hs
+++ b/Hsbot/Core.hs
@@ -19,7 +19,6 @@ import Prelude hiding (catch)
import System.IO
import System.Log.Logger
-import Hsbot.Config
import Hsbot.Types
import Hsbot.Utils
diff --git a/Hsbot/Message.hs b/Hsbot/Message.hs
index 5ec35ed..067a740 100644
--- a/Hsbot/Message.hs
+++ b/Hsbot/Message.hs
@@ -1,9 +1,21 @@
module Hsbot.Message
- ( Message (..)
+ ( readMsg
+ , writeMsg
) where
-import qualified Network.IRC as IRC
+import Control.Concurrent
+import Control.Monad.State
-data Message = IncomingMsg IRC.Message
- | OutgoingMsg IRC.Message
+import Hsbot.Types
+
+-- Plugin Utils
+readMsg :: Plugin IO (Message)
+readMsg = do
+ chan <- gets pluginChan
+ liftIO $ readChan chan >>= return
+
+writeMsg :: Message -> Plugin IO ()
+writeMsg msg = do
+ chan <- gets pluginMaster
+ liftIO $ writeChan chan msg
diff --git a/Hsbot/Plugin/Ping.hs b/Hsbot/Plugin/Ping.hs
index b020359..192bab4 100644
--- a/Hsbot/Plugin/Ping.hs
+++ b/Hsbot/Plugin/Ping.hs
@@ -11,7 +11,6 @@ import Prelude hiding (catch)
import Hsbot.Message
import Hsbot.Types
-import Hsbot.Utils
pingId :: PluginId
pingId = PluginId
diff --git a/Hsbot/Types.hs b/Hsbot/Types.hs
index 28ad430..e906a10 100644
--- a/Hsbot/Types.hs
+++ b/Hsbot/Types.hs
@@ -3,23 +3,24 @@ module Hsbot.Types
, BotState (..)
, BotStatus (..)
, BotEnv (..)
+ , Config (..)
, Env
, Message (..)
, Plugin
, PluginId (..)
, PluginState (..)
+ , TLSConfig (..)
) where
import Control.Concurrent
import qualified Data.Map as M
import Control.Monad.Reader
import Control.Monad.State
+import Network
+import qualified Network.IRC as IRC
import Network.TLS
import System.IO
-import Hsbot.Config
-import Hsbot.Message
-
-- The bot environment
type Env = ReaderT BotEnv
@@ -57,5 +58,30 @@ data PluginId = PluginId
, pluginEp :: PluginState -> IO ()
}
+-- Messaging
+data Message = IncomingMsg IRC.Message
+ | OutgoingMsg IRC.Message
+
data BotStatus = BotContinue | BotExit | BotReload | BotRestart deriving (Show)
+-- Config
+data Config = Config
+ { configErrors :: Maybe String
+ , configTLS :: TLSConfig
+ , configAddress :: String
+ , configPort :: PortID
+ , configChannels :: [String]
+ , configNicknames :: [String]
+ , configRealname :: String
+ , configPlugins :: [(String, Chan Message -> Chan Message -> IO ())]
+ }
+
+data TLSConfig = TLSConfig
+ { sslOn :: Bool
+ , sslCert :: String
+ , sslKey :: String
+ , sslVersions :: [Network.TLS.Version]
+ , sslCiphers :: [Network.TLS.Cipher]
+ , sslVerify :: Bool
+ } deriving (Show)
+
diff --git a/Hsbot/Utils.hs b/Hsbot/Utils.hs
index 6b7f85e..0b32fa6 100644
--- a/Hsbot/Utils.hs
+++ b/Hsbot/Utils.hs
@@ -4,16 +4,13 @@ module Hsbot.Utils
, first
, initTLSEnv
, readCertificate
- , readMsg
, readPrivateKey
, sendStr
, setGlobalQuitMVar
- , writeMsg
) where
import Control.Concurrent
import Control.Monad.Reader
-import Control.Monad.State
import qualified Crypto.Cipher.RSA as RSA
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C
@@ -25,8 +22,6 @@ import Data.List
import Network.TLS
import System.IO
-import Hsbot.Config
-import Hsbot.Message
import Hsbot.Types
-- utility functions
@@ -53,17 +48,6 @@ sendStr :: Handle -> Maybe TLSCtx -> String -> IO ()
sendStr _ (Just ctx) msg = sendData ctx $ L.fromChunks [C.pack msg]
sendStr handle Nothing msg = hPutStrLn handle msg
--- Plugin Utils
-readMsg :: Plugin IO (Message)
-readMsg = do
- chan <- gets pluginChan
- liftIO $ readChan chan >>= return
-
-writeMsg :: Message -> Plugin IO ()
-writeMsg msg = do
- chan <- gets pluginMaster
- liftIO $ writeChan chan msg
-
-- TLS utils
initTLSEnv :: TLSConfig -> IO (TLSParams)
initTLSEnv ssl = do