Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed help page parser so that the entire command name is matched b… #143

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Tablebot/Utility/Help.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Tablebot.Internal.Permission (getSenderPermission, userHasPermission)
import Tablebot.Internal.Plugins (changeAction)
import Tablebot.Internal.Types
import Tablebot.Utility.Discord (Message, sendMessage)
import Tablebot.Utility.Parser (skipSpace)
import Tablebot.Utility.Parser (skipSpace, skipSpace1)
import Tablebot.Utility.Permission (requirePermission)
import Tablebot.Utility.Types hiding (helpPages)
import Text.Megaparsec (choice, chunk, eof, try, (<?>), (<|>))
Expand All @@ -38,9 +38,12 @@ handleHelp rootText hp = parseHelpPage root

parseHelpPage :: HelpPage -> Parser (Message -> CompiledDatabaseDiscord ())
parseHelpPage hp = do
_ <- choice (map chunk (helpName hp : helpAliases hp))
skipSpace
(try eof $> displayHelp hp) <|> choice (map parseHelpPage $ helpSubpages hp) <?> "Unknown Subcommand"
t <- choice (map chunk (helpName hp : helpAliases hp))
let subcommands = choice (map parseHelpPage $ helpSubpages hp)

case t of -- if t is empty string, that means that we're in the base case
"" -> subcommands
_ -> (try (skipSpace >> eof) $> displayHelp hp) <|> (skipSpace1 *> subcommands) <?> "Unknown Subcommand"

displayHelp :: HelpPage -> Message -> CompiledDatabaseDiscord ()
displayHelp hp m = changeAction () . requirePermission (helpPermission hp) m $ do
Expand Down