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.

75 lines
2.7 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. {-# LANGUAGE OverloadedStrings #-}
  2. {-# LANGUAGE RecordWildCards #-}
  3. module Main where
  4. import Control.Monad (when, void)
  5. import qualified Data.Text as T
  6. import qualified Data.Text.IO as TIO
  7. import UnliftIO (liftIO)
  8. import Discord
  9. import Discord.Types
  10. import Discord.Interactions
  11. import qualified Discord.Requests as R
  12. import Commands
  13. import Discord.Internal.Rest.Guild (ModifyGuildOpts(modifyGuildOptsIcon))
  14. import UnliftIO.Directory (renameDirectory)
  15. testServer :: Snowflake
  16. testServer = 740862954454646814
  17. main :: IO ()
  18. main = do
  19. tok <- TIO.readFile "./auth.secret"
  20. err <- runDiscord $ def { discordToken = tok
  21. , discordOnStart = onDiscordStart
  22. , discordOnEnd = liftIO $ putStrLn "Ended"
  23. , discordOnEvent = onDiscordEvent
  24. , discordOnLog =
  25. \s -> TIO.putStrLn s >> TIO.putStrLn ""
  26. }
  27. TIO.putStrLn err
  28. onDiscordStart :: DiscordHandler ()
  29. onDiscordStart = do
  30. let activity = Activity { activityName = "Doing stuff"
  31. , activityType = ActivityTypeGame
  32. , activityUrl = Nothing
  33. }
  34. let opts = UpdateStatusOpts { updateStatusOptsSince = Nothing
  35. , updateStatusOptsGame = Just activity
  36. , updateStatusOptsNewStatus = UpdateStatusOnline
  37. , updateStatusOptsAFK = False
  38. }
  39. sendCommand (UpdateStatus opts)
  40. onDiscordEvent :: Event -> DiscordHandler ()
  41. onDiscordEvent (Ready _ _ _ _ _ _ (PartialApplication i _)) =
  42. mapM_ (maybe ( return () )
  43. ( void
  44. . restCall
  45. . R.CreateGuildApplicationCommand i testServer
  46. )
  47. )
  48. [ Just pingCommand
  49. , Just edtCommand
  50. ]
  51. onDiscordEvent ( InteractionCreate InteractionApplicationCommand
  52. { interactionDataApplicationCommand =
  53. Just InteractionDataApplicationCommandChatInput
  54. { interactionDataApplicationCommandName = name
  55. , interactionDataApplicationCommandOptions = opts
  56. , ..
  57. }
  58. , ..
  59. }
  60. ) = do
  61. void $ restCall
  62. (R.CreateInteractionResponse interactionId interactionToken response)
  63. where
  64. response = case name of
  65. "ping" -> pingResponse
  66. _ -> interactionResponseBasic $ "Unhandled Command: " `T.append` name
  67. onDiscordEvent _ = return ()