aboutsummaryrefslogtreecommitdiffstats
path: root/src/Lib.hs
diff options
context:
space:
mode:
authorTeddy Wing2017-11-19 19:22:19 +0100
committerTeddy Wing2017-11-19 19:34:56 +0100
commit6961ef49cbcb88e4f3466a5852a4cf90d95a587a (patch)
treea05eca21c0d03407179a141e0289ce15cddfadb7 /src/Lib.hs
parenteb732a97b82f9d03f68247d79301ee26b84b650b (diff)
downloadsorbot-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.hs48
1 files changed, 44 insertions, 4 deletions
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