Skip to content

Commit c79ec05

Browse files
committed
(#649) Add custom commands to the help page
1 parent 0587308 commit c79ec05

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/Bot/CustomCommand.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Bot.CustomCommand
88
, updateCustomCommand
99
, showCustomCommand
1010
, timesCustomCommand
11+
, CustomCommand(..)
1112
) where
1213

1314
import Bot.Expr

src/Bot/Help.hs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ module Bot.Help
88
, startRefreshHelpGistTimer
99
) where
1010

11+
import Data.Proxy
12+
import Bot.CustomCommand
1113
import Bot.GitHub
1214
import Bot.Replies
1315
import Command
1416
import Data.Bool.Extra
1517
import Data.Functor
1618
import qualified Data.Map as M
1719
import Data.Maybe
18-
import Data.Proxy
1920
import qualified Data.Text as T
2021
import Effect
2122
import Entity
@@ -75,14 +76,28 @@ gistRenderBuiltinCommand :: (T.Text, BuiltinCommand) -> T.Text
7576
gistRenderBuiltinCommand (name, command) =
7677
[qms||{name}|{bcDescription command}|{bcGitHubLocation command}||]
7778

79+
gistRenderCustomCommand :: CustomCommand -> T.Text
80+
gistRenderCustomCommand (CustomCommand name message times) =
81+
[qms||{name}|{message}|{times}||]
82+
7883
gistRenderCommandTable :: CommandTable -> T.Text
79-
gistRenderCommandTable = T.unlines . map gistRenderBuiltinCommand . M.toList
84+
gistRenderCommandTable = ("* Builtin Commands \n" <>) .
85+
T.unlines . map gistRenderBuiltinCommand . M.toList
8086

8187
-- TODO(#649): Help Gist Page does not include CustomCommands
8288
refreshHelpGist :: CommandTable -> GistId -> Effect ()
8389
refreshHelpGist commandTable gistId = do
84-
let gistText = gistRenderCommandTable commandTable
85-
updateGistFile helpGistFileName (FileContent gistText) gistId
90+
customsList <- getCustomCommands
91+
let customCommands = T.unlines $ gistRenderCustomCommand . entityPayload <$> customsList
92+
updateGistFile
93+
helpGistFileName
94+
(FileContent (gistText <> "\n* Custom commands \n" <> customCommands))
95+
gistId
96+
where
97+
gistText = gistRenderCommandTable commandTable
98+
99+
getCustomCommands :: Effect ([Entity CustomCommand])
100+
getCustomCommands = selectEntities Proxy All
86101

87102
startRefreshHelpGistTimer :: CommandTable -> Effect ()
88103
startRefreshHelpGistTimer commandTable =

0 commit comments

Comments
 (0)