From 6009f91efd3dfd57122d2cf98d7255ec99ba8475 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 20 Aug 2017 14:49:10 +0200 Subject: 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. --- src/Plugin/Base.hs | 15 ++++++++++++++- src/Plugin/Factorial.hs | 2 +- src/Plugin/GitHubCommit.hs | 2 +- src/Plugin/GitRemoteSetOrigin.hs | 2 +- src/Plugin/Help.hs | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) (limited to 'src') 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 = "!" 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 = "" 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 " 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" -- cgit v1.2.3