blob: ebe3760c033568a704f494c39c9d52e67bb89ef0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
{-# LANGUAGE OverloadedStrings #-}
module Plugin.Help
( help
) where
import Control.Monad (sequence)
import qualified Data.Text as T
import Bot (Bot)
import qualified PluginList as PL (plugins)
import Plugin.Base
help :: Bot Plugin
help = do
return defaultPlugin
{ matchRegex = "^help$"
, perform = helpAction
, command = "help"
, description = "Show a list of available bot commands."
, queryOnly = True
}
helpAction :: PluginAction
helpAction _ = do
plugins' <- sequence plugins
return $ Right $ T.intercalate "\n"
[T.justifyRight (longestCommandLen plugins') ' ' (command p)
`T.append` " – "
`T.append` description p
| p <- plugins']
where
longestCommandLen plugins = foldr (max) 0 (map (T.length . command) plugins)
plugins :: [Bot Plugin]
plugins = PL.plugins ++ [help]
|