From bbb1bc28fe10f1b1fdc433ecf9502e2821f024f8 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 15 Oct 2011 23:04:49 +0200 Subject: initial mysql support --- HsBot/Base/Database.hs | 22 ++++++++++++++++++++++ HsBot/Base/State.hs | 5 +++-- HsBot/Plugins/StoreMessages.hs | 7 +------ 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 HsBot/Base/Database.hs (limited to 'HsBot') diff --git a/HsBot/Base/Database.hs b/HsBot/Base/Database.hs new file mode 100644 index 0000000..ae633e8 --- /dev/null +++ b/HsBot/Base/Database.hs @@ -0,0 +1,22 @@ +module HsBot.Base.Database where + +import HsBot.Base.Conf + +import qualified Database.HSQL.MySQL as MySQL +import qualified Database.HSQL.Types as Types + +data Database = Database { + connection :: IO Types.Connection + } + +databaseMake conf = Database { + connection = databaseMakeConnection conf + } + +databaseMakeConnection :: Conf -> IO Types.Connection +databaseMakeConnection conf = do + dbHost <- get "dbHost" conf + dbUser <- get "dbUser" conf + dbSchema <- get "dbSchema" conf + dbPass <- get "dbPass" conf + MySQL.connect dbHost dbUser dbSchema dbPass diff --git a/HsBot/Base/State.hs b/HsBot/Base/State.hs index 9c38e42..a0cc664 100644 --- a/HsBot/Base/State.hs +++ b/HsBot/Base/State.hs @@ -9,13 +9,14 @@ import qualified Data.Map as M import List import HsBot.IRC.User +import HsBot.Base.Database data State = State { isReady :: Bool, currentSender :: String, currentChannel :: String, line :: String, - users :: [User] + users :: [User], } deriving (Show, Read) makeDefaultState :: State @@ -24,7 +25,7 @@ makeDefaultState = State { currentSender = "", currentChannel = "", line = "", - users = [] + users = [], } stateNumUsers :: State -> Int diff --git a/HsBot/Plugins/StoreMessages.hs b/HsBot/Plugins/StoreMessages.hs index 47aa5dd..d5f1ace 100644 --- a/HsBot/Plugins/StoreMessages.hs +++ b/HsBot/Plugins/StoreMessages.hs @@ -1,8 +1,6 @@ module HsBot.Plugins.StoreMessages (makeStoreMessages) where import Control.Exception -import Database.HDBC --- import Database.HDBC.MySQL import HsBot.Plugins.Base @@ -11,10 +9,7 @@ import HsBot.Base.State storeMessages :: CallbackFunction storeMessages str sendMessage env@(Env state _) = do - -- connectTest - return (env) + return (env) makeStoreMessages = Plugin 0 storeMessages - -connectTest = "" -- cgit v1.2.3