diff --git a/.gitignore b/.gitignore index 70ea238..21a3a6c 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,4 @@ Thumbs.db dist-newstyle *.o *.hi +*.conf \ No newline at end of file diff --git a/GypsFulvus.cabal b/GypsFulvus.cabal index 6d00b4f..c5ccd07 100644 --- a/GypsFulvus.cabal +++ b/GypsFulvus.cabal @@ -36,7 +36,8 @@ library network-conduit-tls >= 1.3.2, tls >= 1.5.4, x509-validation >= 1.6.11, - bytestring + bytestring, + ini extra-libraries: tcl8.6 Includes: /usr/include/tcl.h, @@ -68,7 +69,8 @@ executable GypsFulvus network-conduit-tls >= 1.3.2, tls >= 1.5.4, x509-validation >= 1.6.11, - bytestring + bytestring, + ini ghc-options: -O2 diff --git a/exquisiterobot.conf.example b/exquisiterobot.conf.example new file mode 100644 index 0000000..37cc19d --- /dev/null +++ b/exquisiterobot.conf.example @@ -0,0 +1,4 @@ +[Server] +hostname= "chat.freenode.org" +port= 6697 +channels = "##politics" \ No newline at end of file diff --git a/src/Carrion/Plugin/IO/IRC/Client.hs b/src/Carrion/Plugin/IO/IRC/Client.hs index d843e98..f5522fe 100644 --- a/src/Carrion/Plugin/IO/IRC/Client.hs +++ b/src/Carrion/Plugin/IO/IRC/Client.hs @@ -12,7 +12,7 @@ import Network.TLS.Extra import Data.X509.Validation import Control.Monad.IO.Class (MonadIO, liftIO) import Data.ByteString (ByteString) -import Data.Text.Encoding (decodeUtf8) +import Data.Text.Encoding (decodeUtf8, encodeUtf8) import Control.Lens import Control.Concurrent(threadDelay,forkIO) import qualified Data.Text as T @@ -21,9 +21,12 @@ import Control.Monad(liftM,forever) import Data.Monoid import qualified Data.Map as M import Data.ByteString(ByteString) +import qualified Data.ByteString as BS import Network.IRC.CTCP(CTCPByteString(..)) import Control.Applicative ((<$>), (<|>)) import Data.List(nub,(\\)) +import Data.Ini +import qualified Data.Text.IO as TIO type MyNicknames = M.Map (T.Text) ([T.Text]) @@ -39,8 +42,8 @@ tellCommands = ["tcl"] privateBotCommands = ["!join","!part","!kick","!op","!cycle","!reconnect","!ostracise","tcl"] myOwners = ["hastur"] -myChannels :: [T.Text] -myChannels = ["#exquisitebot"] +--myChannels :: [T.Text] +--myChannels = ["#exquisitebot"] -- this dogshit irc library doesnt seem to have a concept of 'people in the channel(s)' rPL_NAMREPLY :: Int @@ -97,8 +100,6 @@ matchNumeric' n intruder ev = case _message ev of Numeric num args | n == num -> Just (intruder,args) _ -> Nothing - - matchType' :: Getting (First b) (Message a1) b -> a2 -> Event a1 -> Maybe (a2, b) @@ -159,19 +160,30 @@ detectCommandHandler (nns,mh) = huntAlligators (matchType' _Privmsg (nns,mh)) $ Left _ -> return () stripCommandLocal :: T.Text -> Manhole -> IO (Maybe T.Text) stripCommandLocal c m = stripCommandPrefix' c tellCommands m mySignature - + +getIRCConfig = do + c <- TIO.readFile "./exquisiterobot.conf" >>= return . parseIni + case c of + Left _ -> return (T.pack "",0,T.pack "") + Right i -> do + let host = lookupValue "Server" "hostname" i + port = lookupValue "Server" "port" i + channels = lookupValue "Server" "channels" i + case (host,port,channels) of + (Right h, Right p, Right cs) -> return (h,(read . T.unpack $ p),cs) + _ -> return ("",0,"") initPlugin :: Manhole -> IO InitStatus initPlugin mh = do - let myHost = "darkarmy.chat" - myPort = 6697 - myNickname = "ExquisiteRobot" - cpara = defaultParamsClient (unpack $ decodeUtf8 myHost) "" + (myHost,myPort,myChannels') <- getIRCConfig + let myChannels = T.splitOn " " myChannels' + let myNickname = "ExquisiteRobot" + cpara = defaultParamsClient (unpack myHost) "" validate cs vc sid cc = do -- First validate with the standard function res <- (onServerCertificate $ clientHooks cpara) cs vc sid cc -- Then strip out non-issues return $ filter (`notElem` [UnknownCA, SelfSigned]) res - myClientConfig = (tlsClientConfig myPort myHost) { tlsClientTLSSettings = TLSSettings cpara + myClientConfig = (tlsClientConfig myPort (encodeUtf8 myHost)) { tlsClientTLSSettings = TLSSettings cpara { clientHooks = (clientHooks cpara) { onServerCertificate = validate } , clientSupported = (clientSupported cpara) diff --git a/state b/state index 45e92f9..15247c3 160000 --- a/state +++ b/state @@ -1 +1 @@ -Subproject commit 45e92f9730be1928fec14edcf5a653dec05a265c +Subproject commit 15247c3a2941d6993f6734de0153e6e1758ee370