diff --git a/src/Bot.hs b/src/Bot.hs new file mode 100644 index 0000000..af97e04 --- /dev/null +++ b/src/Bot.hs @@ -0,0 +1,13 @@ +module Bot where + +import qualified Data.Text as T + +type Bot s = Event -> Effect s + +data Event = Join + +data Effect s = None + | Say T.Text + +bot :: Bot s +bot Join = Say $ T.pack "Hi!" diff --git a/src/Main.hs b/src/Main.hs index c2e4af9..d2df522 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,4 +1,46 @@ module Main where +import Bot +import Control.Exception +import Hookup +import Irc.RateLimit (RateLimit) +import System.Environment + +data Config = Config { configNick :: String + , configPass :: String + , configRate :: RateLimit + } + +conParamsFromConfig :: Config -> ConnectionParams +conParamsFromConfig config = + ConnectionParams { cpHost = "irc.chat.twitch.tv" + , cpPort = 443 + , cpTls = Just TlsParams { tpClientCertificate = Nothing + , tpClientPrivateKey = Nothing + , tpServerCertificate = Nothing + , tpCipherSuite = "HIGH" + , tpInsecure = False + } + , cpSocks = Nothing + } + +-- TODO(#7): implement Main.configFromFile +configFromFile :: FilePath -> IO Config +configFromFile = undefined + +withConnection :: ConnectionParams -> (Connection -> IO a) -> IO a +withConnection params body = + bracket (connect params) close body + +-- TODO(#8): implement Main.ircTransport +ircTransport :: Bot s -> Config -> Connection -> IO () +ircTransport = undefined + +mainWithArgs :: [String] -> IO () +mainWithArgs [configPath] = + do config <- configFromFile configPath + withConnection (conParamsFromConfig config) $ ircTransport bot config +mainWithArgs _ = error "./tsoder2 " + main :: IO () -main = undefined +main = getArgs >>= mainWithArgs diff --git a/tsoder2.cabal b/tsoder2.cabal index ab06186..a086c10 100644 --- a/tsoder2.cabal +++ b/tsoder2.cabal @@ -54,7 +54,7 @@ executable tsoder2 main-is: Main.hs -- Modules included in this executable, other than Main. - -- other-modules: + other-modules: Bot -- LANGUAGE extensions used by modules in this package. -- other-extensions: @@ -64,11 +64,10 @@ executable tsoder2 , hookup , irc-core , bytestring - , conduit + , text -- Directories containing source files. hs-source-dirs: src -- Base language which the package is written in. - default-language: Haskell2010 - + default-language: Haskell2010 \ No newline at end of file