You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.9 KiB

3 years ago
3 years ago
3 years ago
  1. {-# LANGUAGE OverloadedStrings #-}
  2. {-# LANGUAGE RecordWildCards #-}
  3. module Commands where
  4. import Discord
  5. import Discord.Types
  6. import Discord.Interactions
  7. import qualified Discord.Requests as R
  8. import qualified Data.Text as T
  9. import qualified Data.Map.Strict as Map
  10. import Commands.EDT
  11. pingCommand :: CreateApplicationCommand
  12. pingCommand =
  13. CreateApplicationCommand
  14. "ping"
  15. "pong"
  16. (Just [])
  17. Nothing
  18. Nothing
  19. pingResponse :: InteractionResponse
  20. pingResponse = interactionResponseBasic "Pong"
  21. edtCommand :: CreateApplicationCommand
  22. edtCommand = CreateApplicationCommand
  23. "edt"
  24. "Gets the planning for a group"
  25. (Just $ toInternal <$>
  26. [ ApplicationCommandOptionValueString
  27. "group"
  28. "Group to get the planning for"
  29. (Just True)
  30. Nothing
  31. Nothing
  32. , ApplicationCommandOptionValueString
  33. "day"
  34. "The day you want the planning for as DD/MM(/YYYY)"
  35. Nothing Nothing Nothing
  36. ])
  37. Nothing
  38. Nothing
  39. edtResponse :: Maybe InteractionDataApplicationCommandOptions -> InteractionResponse
  40. edtResponse (Just (InteractionDataApplicationCommandOptionsValues opts)) =
  41. interactionResponseBasic $
  42. "You gave:\n```hs\n" `T.append` T.pack (show parsedOpts) `T.append` "\n```"
  43. where
  44. parsedOpts :: Map.Map T.Text T.Text
  45. parsedOpts = Map.fromList $ map parseOpt opts
  46. parseOpt :: InteractionDataApplicationCommandOptionValue -> (T.Text, T.Text)
  47. parseOpt (InteractionDataApplicationCommandOptionValue
  48. { interactionDataApplicationCommandOptionValueName = name
  49. , interactionDataApplicationCommandOptionValueValue =
  50. ApplicationCommandInteractionDataValueString val
  51. , ..}
  52. ) = (name, val)
  53. parseOpt _ = ("INVALID FORMAT", "INVALID FORMAT")
  54. edtResponse _ = interactionResponseBasic
  55. "The edt command should have params yet you managed not to give any: wow"