From 04a9fc75e23f2903d8df07e3cd20e7dba64959b1 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 2 Aug 2017 00:28:28 +0200 Subject: Change `PluginAction` type to `Message -> String` Have `PluginAction` functions take a Message type instead of a plain string. This gives us access to additional fields on the message: channel and nick. sorbot.cabal: Add `Message` to `exposed-modules` in order to be able to use it when building. Lib.hs: Change our test message to be a `Message` data type to conform to the new `PluginAction` interface. Plugin.hs: Use `Message` where appropriate. When calling `perform`, pass it a `Message` instead of a `String`. This means we have to match the regex within the plugin in order to get the match data. The benefit of that change is that now we have access to the full message in the plugin if we need it, not just the regex-filtered part. GitHubCommit.hs: Do a regex match against the Message text in order to get the SHA we want from the message. --- src/Lib.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/Lib.hs') diff --git a/src/Lib.hs b/src/Lib.hs index 0768465..63fd3b8 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -2,10 +2,15 @@ module Lib ( someFunc ) where +import Message import Plugin someFunc :: IO () someFunc = do - let message = "75ac7b18a009ffe7a77a17a61d95c01395f36b44" + let message = Message + { text = "75ac7b18a009ffe7a77a17a61d95c01395f36b44" + , channel = "#a-channel" + , nick = "anon" + } Just plugin = matchPlugin message putStrLn $ performPlugin plugin message -- cgit v1.2.3