Skip to content

Commit 31752d5

Browse files
committed
(#817) port Help gist rendering to OrgMode module
1 parent 5cde4d2 commit 31752d5

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/Bot/Help.hs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Property
2424
import Reaction
2525
import Text.InterpolatedString.QM
2626
import Transport
27+
import OrgMode
2728

2829
data HelpState = HelpState
2930
{ helpStateGistId :: Maybe GistId
@@ -73,28 +74,31 @@ refreshHelpGistId =
7374
Reaction replyMessage
7475

7576
gistRenderCommandTable :: CommandTable -> T.Text
76-
gistRenderCommandTable =
77-
([qms|* Builtin Commands\n{header}\n|-\n|] <>) .
78-
T.unlines . map renderRow . M.toList
77+
gistRenderCommandTable commandTable = [qms|* Builtin Commands\n{table}\n|]
7978
where
80-
header :: T.Text
81-
header = "|Name|Description|Location|"
82-
renderRow :: (T.Text, BuiltinCommand) -> T.Text
83-
renderRow (name, command) =
84-
[qms||{name}|{bcDescription command}|{location}||]
85-
where
86-
location :: T.Text
87-
location = [qms|[[{bcGitHubLocation command}][Source↗]]|]
79+
table :: T.Text
80+
table =
81+
renderTable ["Name", "Description", "Location"] $
82+
map
83+
(\(name, command) ->
84+
[ name
85+
, bcDescription command
86+
, [qms|[[{bcGitHubLocation command}][Source↗]]|]
87+
]) $
88+
M.toList commandTable
8889

8990
gistRenderCustomCommandsTable :: [Entity CustomCommand] -> T.Text
90-
gistRenderCustomCommandsTable =
91-
([qms|* Custom commands\n{header}\n|-\n|] <>) .
92-
T.unlines . map (renderRow . entityPayload)
91+
gistRenderCustomCommandsTable customCommands =
92+
[qms|* Custom commands\n{table}\n|]
9393
where
94-
header :: T.Text
95-
header = "|Name|Definition|%times|"
96-
renderRow (CustomCommand name message times) =
97-
[qms||{name}|{message}|{times}||]
94+
table :: T.Text
95+
table =
96+
renderTable ["Name", "Definition", "%times"] $
97+
map
98+
((\(CustomCommand name message times) ->
99+
[name, message, T.pack $ show times]) .
100+
entityPayload)
101+
customCommands
98102

99103
refreshHelpGist :: CommandTable -> GistId -> Effect ()
100104
refreshHelpGist commandTable gistId = do

0 commit comments

Comments
 (0)