diff options
author | Teddy Wing | 2017-08-20 14:49:10 +0200 |
---|---|---|
committer | Teddy Wing | 2017-08-20 15:15:15 +0200 |
commit | 6009f91efd3dfd57122d2cf98d7255ec99ba8475 (patch) | |
tree | a90910db88a04b259e796090481c9db6e8b3d311 /src | |
parent | 5d01ba1990e99785b947c2aca71367ea5b21dce2 (diff) | |
download | sorbot-6009f91efd3dfd57122d2cf98d7255ec99ba8475.tar.bz2 |
Plugin: Add `queryOnly` field
A new field that says whether this plugin should only respond via a
private query message to the user instead of responding on the channel
the message was sent from.
This is needed for the Help plugin, which shouldn't flood channels with
lots of extraneous output. Instead, the Help plugin should send the list
of commands directly to the user.
Since most of the time we don't want this behaviour, encode a default of
`False` on the field so that most plugins don't have to define it
manually. This necessitates changing the constructors to use the default
`Plugin` instead.
Diffstat (limited to 'src')
-rw-r--r-- | src/Plugin/Base.hs | 15 | ||||
-rw-r--r-- | src/Plugin/Factorial.hs | 2 | ||||
-rw-r--r-- | src/Plugin/GitHubCommit.hs | 2 | ||||
-rw-r--r-- | src/Plugin/GitRemoteSetOrigin.hs | 2 | ||||
-rw-r--r-- | src/Plugin/Help.hs | 2 |
5 files changed, 18 insertions, 5 deletions
diff --git a/src/Plugin/Base.hs b/src/Plugin/Base.hs index ac67e71..d4194ee 100644 --- a/src/Plugin/Base.hs +++ b/src/Plugin/Base.hs @@ -1,7 +1,10 @@ +{-# LANGUAGE OverloadedStrings #-} + module Plugin.Base ( PluginAction , Plugin(..) + , defaultPlugin ) where import qualified Data.Text as T @@ -17,7 +20,17 @@ data Plugin = Plugin , perform :: PluginAction , command :: T.Text , description :: T.Text + , queryOnly :: Bool } instance Show Plugin where - show (Plugin r _ _ _) = "matchRegex = " ++ r + show (Plugin r _ _ _ _) = "matchRegex = " ++ r + +defaultPlugin :: Plugin +defaultPlugin = Plugin + { matchRegex = "" + , perform = \m -> return (Left "") + , command = "" + , description = "" + , queryOnly = False + } diff --git a/src/Plugin/Factorial.hs b/src/Plugin/Factorial.hs index 796ef14..9284fe7 100644 --- a/src/Plugin/Factorial.hs +++ b/src/Plugin/Factorial.hs @@ -10,7 +10,7 @@ import TextShow (showt) import qualified Message as M import Plugin.Base -factorial = Plugin +factorial = defaultPlugin { matchRegex = "^([0-9]+)!$" , perform = factorialAction , command = "<integer>!" diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs index c10abf6..3d2e490 100644 --- a/src/Plugin/GitHubCommit.hs +++ b/src/Plugin/GitHubCommit.hs @@ -14,7 +14,7 @@ import I18n import qualified Message as M import Plugin.Base -gitHubCommit = Plugin +gitHubCommit = defaultPlugin { matchRegex = "^[0-9a-f]{40}$" , perform = gitHubCommitAction , command = "<git_sha>" diff --git a/src/Plugin/GitRemoteSetOrigin.hs b/src/Plugin/GitRemoteSetOrigin.hs index 8ab86dc..0fdb4ef 100644 --- a/src/Plugin/GitRemoteSetOrigin.hs +++ b/src/Plugin/GitRemoteSetOrigin.hs @@ -13,7 +13,7 @@ import Text.Regex.TDFA ((=~)) import qualified Message as M import Plugin.Base -gitRemoteSetOrigin = Plugin +gitRemoteSetOrigin = defaultPlugin { matchRegex = "^git remote set origin ([^ ]+)$" , perform = gitRemoteSetOriginAction , command = "git remote set origin <url>" diff --git a/src/Plugin/Help.hs b/src/Plugin/Help.hs index ac38dab..258a80a 100644 --- a/src/Plugin/Help.hs +++ b/src/Plugin/Help.hs @@ -9,7 +9,7 @@ import qualified Data.Text as T import qualified PluginList as PL (plugins) import Plugin.Base -help = Plugin +help = defaultPlugin { matchRegex = "^help$" , perform = helpAction , command = "help" |