From 6961ef49cbcb88e4f3466a5852a4cf90d95a587a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 19 Nov 2017 19:22:19 +0100 Subject: 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. --- src/Lib.hs | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'src/Lib.hs') diff --git a/src/Lib.hs b/src/Lib.hs index 3d875ef..821a49b 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -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 -- cgit v1.2.3