diff options
author | Teddy Wing | 2017-11-19 19:22:19 +0100 |
---|---|---|
committer | Teddy Wing | 2017-11-19 19:34:56 +0100 |
commit | 6961ef49cbcb88e4f3466a5852a4cf90d95a587a (patch) | |
tree | a05eca21c0d03407179a141e0289ce15cddfadb7 /src/Lib.hs | |
parent | eb732a97b82f9d03f68247d79301ee26b84b650b (diff) | |
download | sorbot-6961ef49cbcb88e4f3466a5852a4cf90d95a587a.tar.bz2 |
Lib: Test application of Bot reader
A test to try to get _something_ to compile. And it does!
Here we try to run a plugin with `runReaderT` and `runBot` to pass
`Options` to the plugin, using the "help" plugin as an example. It feeds
hard-coded `Options` to the plugin and outputs its response to STDOUT.
Also get an implementation of `initializePlugins` working that will
allow us to build a list of plugins with `Options` applied to the
reader.
This commit comments out the whole of IRC.hs in order to get the code to
compile. That file still has a bunch of `Bot` monad-related type errors.
To build the final plugin list, I think what we'll want to do is use
something like `initializePlugins` in Lib to apply all our plugins with
the `Options` and then feed that to `connectIRC`. In order to build the
"help" plugin, the plan is to re-apply the `Options` after `ask`ing for
them inside the `PluginAction` for "help" to all plugins, thus enabling
us to get a plugin list with the applied reader for proper localisation
of the help output.
Diffstat (limited to 'src/Lib.hs')
-rw-r--r-- | src/Lib.hs | 48 |
1 files changed, 44 insertions, 4 deletions
@@ -6,12 +6,52 @@ module Lib import Database.SQLite.Simple +import Bot (Bot(runBot)) import CliOptions (Options(language), parseOptions) -import IRC (connectIRC) +-- import IRC (connectIRC) import Message -import Plugin +-- import Plugin +import Plugin.Base (Plugin) +import PluginList as PL (plugins) +-- TODO: tmp test +import Control.Monad.Reader (runReaderT) +import CliOptions (Options(..)) +import Plugin.Help as Help (help) +import I18n (Locale(EN)) +import Plugin (performPlugin) +import qualified Data.Text.IO as TIO someFunc :: IO () someFunc = do - options <- parseOptions - connectIRC "irc.freenode.net" 6697 "test-bot-7890asdf" + -- options <- parseOptions + -- halp <- runReaderT (runBot Help.help) Options + -- { slackApiToken = "booya" + -- , language = EN + -- } + -- case performPlugin halp "hello" of + -- Left s -> TIO.putStrLn s + -- Right s -> TIO.putStrLn s + + -- halp <- performPlugin Help.help "_msg" + hilp <- runReaderT + (runBot + (performPlugin Help.help Message + { text = "_msg" + , channel = "#?" + , nick = "zyx" + })) + Options + { slackApiToken = "booya" + , language = EN + } + case hilp of + Left x -> TIO.putStrLn x + Right x -> TIO.putStrLn x + + -- connectIRC "irc.freenode.net" 6697 "test-bot-7890asdf" + +initializePlugins :: Options -> [IO Plugin] +initializePlugins options = + map + (\p -> runReaderT (runBot p) options) + plugins |