aboutsummaryrefslogtreecommitdiffstats
path: root/src/Plugin
diff options
context:
space:
mode:
authorTeddy Wing2017-08-02 00:28:28 +0200
committerTeddy Wing2017-08-02 00:28:28 +0200
commit04a9fc75e23f2903d8df07e3cd20e7dba64959b1 (patch)
tree69db6927b53d48e59b856c077e4ee36eaed13f41 /src/Plugin
parent2fb79b3ddf26cb099bc4a5daebeb873d77989516 (diff)
downloadsorbot-04a9fc75e23f2903d8df07e3cd20e7dba64959b1.tar.bz2
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.
Diffstat (limited to 'src/Plugin')
-rw-r--r--src/Plugin/Base.hs4
-rw-r--r--src/Plugin/GitHubCommit.hs6
2 files changed, 8 insertions, 2 deletions
diff --git a/src/Plugin/Base.hs b/src/Plugin/Base.hs
index 329c21a..c85f53a 100644
--- a/src/Plugin/Base.hs
+++ b/src/Plugin/Base.hs
@@ -4,7 +4,9 @@ module Plugin.Base
, Plugin(..)
) where
-type PluginAction = String -> String
+import Message
+
+type PluginAction = Message -> String
data Plugin = Plugin
{ matchRegex :: String
diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs
index 24c4831..8fa8d0a 100644
--- a/src/Plugin/GitHubCommit.hs
+++ b/src/Plugin/GitHubCommit.hs
@@ -2,6 +2,9 @@ module Plugin.GitHubCommit
( gitHubCommit
) where
+import Text.Regex.TDFA
+
+import qualified Message as M
import Plugin.Base
gitHubCommit = Plugin
@@ -10,4 +13,5 @@ gitHubCommit = Plugin
}
gitHubCommitAction :: PluginAction
-gitHubCommitAction match = "https://github.com/" ++ match
+gitHubCommitAction message =
+ "https://github.com/" ++ M.text message =~ matchRegex gitHubCommit