aboutsummaryrefslogtreecommitdiffstats
path: root/src/Plugin
diff options
context:
space:
mode:
Diffstat (limited to 'src/Plugin')
-rw-r--r--src/Plugin/Base.hs8
-rw-r--r--src/Plugin/GitHubCommit.hs2
-rw-r--r--src/Plugin/GitRemoteSetOrigin.hs2
-rw-r--r--src/Plugin/Help.hs25
-rw-r--r--src/Plugin/PluginList.hs15
5 files changed, 49 insertions, 3 deletions
diff --git a/src/Plugin/Base.hs b/src/Plugin/Base.hs
index 62900c7..ac67e71 100644
--- a/src/Plugin/Base.hs
+++ b/src/Plugin/Base.hs
@@ -13,9 +13,11 @@ import Message
type PluginAction = Message -> IO (Either T.Text T.Text)
data Plugin = Plugin
- { matchRegex :: String
- , perform :: PluginAction
+ { matchRegex :: String
+ , perform :: PluginAction
+ , command :: T.Text
+ , description :: T.Text
}
instance Show Plugin where
- show (Plugin r p) = "matchRegex = " ++ r
+ show (Plugin r _ _ _) = "matchRegex = " ++ r
diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs
index 8b43b57..c4dd2ca 100644
--- a/src/Plugin/GitHubCommit.hs
+++ b/src/Plugin/GitHubCommit.hs
@@ -17,6 +17,8 @@ import Plugin.Base
gitHubCommit = Plugin
{ matchRegex = "^[0-9a-f]{40}$"
, perform = gitHubCommitAction
+ , command = "GIT_SHA"
+ , description = "Generate a commit URL based on the given SHA."
}
gitHubCommitAction :: PluginAction
diff --git a/src/Plugin/GitRemoteSetOrigin.hs b/src/Plugin/GitRemoteSetOrigin.hs
index 208ab9f..5b2aad2 100644
--- a/src/Plugin/GitRemoteSetOrigin.hs
+++ b/src/Plugin/GitRemoteSetOrigin.hs
@@ -16,6 +16,8 @@ import Plugin.Base
gitRemoteSetOrigin = Plugin
{ matchRegex = "^git remote set origin ([^ ]+)$"
, perform = gitRemoteSetOriginAction
+ , command = "git remote set origin URL"
+ , description = "Set the git remote URL for this channel."
}
gitRemoteSetOriginAction :: PluginAction
diff --git a/src/Plugin/Help.hs b/src/Plugin/Help.hs
new file mode 100644
index 0000000..57e106d
--- /dev/null
+++ b/src/Plugin/Help.hs
@@ -0,0 +1,25 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Plugin.Help
+ ( help
+ ) where
+
+import qualified Data.Text as T
+
+import qualified Plugin.PluginList as PL (plugins)
+import Plugin.Base
+
+help = Plugin
+ { matchRegex = "^help$"
+ , perform = helpAction
+ , command = "help"
+ , description = "Show a list of available bot commands."
+ }
+
+helpAction :: PluginAction
+helpAction _ = do
+ return $ Right $ T.concat
+ [command p `T.append` "\t" `T.append` description p | p <- plugins]
+
+plugins :: [Plugin]
+plugins = PL.plugins ++ [help]
diff --git a/src/Plugin/PluginList.hs b/src/Plugin/PluginList.hs
new file mode 100644
index 0000000..21f3893
--- /dev/null
+++ b/src/Plugin/PluginList.hs
@@ -0,0 +1,15 @@
+module Plugin.PluginList
+ ( plugins
+ ) where
+
+import Plugin.Base (Plugin)
+import Plugin.GitHubCommit
+import Plugin.GitRemoteSetOrigin
+
+-- | The list of plugins to load, minus the Help plugin, which would otherwise
+-- cause a circular import.
+plugins :: [Plugin]
+plugins =
+ [ gitHubCommit
+ , gitRemoteSetOrigin
+ ]