Skip to content

Commit 48e6817

Browse files
committed
(#649) Restructure the table rendering code
1 parent 48ab167 commit 48e6817

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

src/Bot/Help.hs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,34 +72,29 @@ refreshHelpGistId =
7272
cmapR (const "Scheduled to refresh the Help Gist Page") $
7373
Reaction replyMessage
7474

75-
gistRenderBuiltinCommand :: (T.Text, BuiltinCommand) -> T.Text
76-
gistRenderBuiltinCommand (name, command) =
77-
[qms||{name}|{bcDescription command}|{bcGitHubLocation command}||]
78-
79-
gistRenderCustomCommand :: CustomCommand -> T.Text
80-
gistRenderCustomCommand (CustomCommand name message times) =
81-
[qms||{name}|{message}|{times}||]
82-
8375
gistRenderCommandTable :: CommandTable -> T.Text
8476
gistRenderCommandTable =
85-
("* Builtin Commands \n" <>) .
86-
T.unlines . map gistRenderBuiltinCommand . M.toList
77+
("* Builtin Commands \n" <>) . T.unlines . map renderRow . M.toList
78+
where
79+
renderRow (name, command) =
80+
[qms||{name}|{bcDescription command}|{bcGitHubLocation command}||]
81+
82+
gistRenderCustomCommandsTable :: [Entity CustomCommand] -> T.Text
83+
gistRenderCustomCommandsTable =
84+
("* Custom commands \n" <>) . T.unlines . map (renderRow . entityPayload)
85+
where
86+
renderRow (CustomCommand name message times) =
87+
[qms||{name}|{message}|{times}||]
8788

88-
-- TODO(#649): Help Gist Page does not include CustomCommands
8989
refreshHelpGist :: CommandTable -> GistId -> Effect ()
9090
refreshHelpGist commandTable gistId = do
91-
customsList <- getCustomCommands
92-
let customCommands =
93-
T.unlines $ gistRenderCustomCommand . entityPayload <$> customsList
91+
customsList <- selectEntities Proxy All
9492
updateGistFile
9593
helpGistFileName
96-
(FileContent (gistText <> "\n* Custom commands \n" <> customCommands))
94+
(FileContent
95+
(gistRenderCommandTable commandTable <> "\n" <>
96+
gistRenderCustomCommandsTable customsList))
9797
gistId
98-
where
99-
gistText = gistRenderCommandTable commandTable
100-
101-
getCustomCommands :: Effect [Entity CustomCommand]
102-
getCustomCommands = selectEntities Proxy All
10398

10499
startRefreshHelpGistTimer :: CommandTable -> Effect ()
105100
startRefreshHelpGistTimer commandTable =

0 commit comments

Comments
 (0)