diff options
| author | LLLL Colonq <llll@colonq> | 2023-11-16 19:06:43 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2023-11-16 19:06:43 -0500 |
| commit | dcef0b65069fb38fd0f6c4382353167f603ebff1 (patch) | |
| tree | 45954ffe308c3dd056e6af4f734e6d2af89e5856 /deps/discord-haskell/docs | |
Initial commit
Diffstat (limited to 'deps/discord-haskell/docs')
| -rw-r--r-- | deps/discord-haskell/docs/applicationcommands.md | 18 | ||||
| -rw-r--r-- | deps/discord-haskell/docs/cache.md | 7 | ||||
| -rw-r--r-- | deps/discord-haskell/docs/components.md | 6 | ||||
| -rw-r--r-- | deps/discord-haskell/docs/contributing.md | 17 | ||||
| -rw-r--r-- | deps/discord-haskell/docs/creating-bot.md | 13 | ||||
| -rw-r--r-- | deps/discord-haskell/docs/debugging.md | 29 | ||||
| -rw-r--r-- | deps/discord-haskell/docs/design.md | 51 | ||||
| -rw-r--r-- | deps/discord-haskell/docs/embeds.md | 21 | ||||
| -rw-r--r-- | deps/discord-haskell/docs/emoji.md | 13 | ||||
| -rw-r--r-- | deps/discord-haskell/docs/installing.md | 97 | ||||
| -rw-r--r-- | deps/discord-haskell/docs/intents.md | 21 | ||||
| -rw-r--r-- | deps/discord-haskell/docs/todo.md | 36 | ||||
| -rw-r--r-- | deps/discord-haskell/docs/voice.md | 5 |
13 files changed, 334 insertions, 0 deletions
diff --git a/deps/discord-haskell/docs/applicationcommands.md b/deps/discord-haskell/docs/applicationcommands.md new file mode 100644 index 0000000..f27e412 --- /dev/null +++ b/deps/discord-haskell/docs/applicationcommands.md @@ -0,0 +1,18 @@ +### Application Commands + +https://discord.com/developers/docs/interactions/application-commands + +There are three steps to application commands. + +1. Register the command with discord. This only needs to be done once, but there is no harm in doing it again/on each reboot, as the creation of commands just overwrites other commands of the same type and name. + 1. This is achieved by sending a `CreateGuildApplicationCommand` event to discord. The easiest way to do this is by capturing and working off of the `Ready` event in the event loop, which is only sent in the initial startup. + 2. Commands can either be global (in which case there is a delay to their addition) or they can be guild (server) specific. + 3. There are other application command requests that can be conducted in this step, so please have a look at the documentation. + 4. Finally, the application id (which is needed to create commands) of the bot is stored in the cache if you need to create, edit, delete, or get application commands later in the program. +2. Receive an interaction + 1. This is achieved by capturing the `Interaction` event in the event loop +3. Respond to the interaction + 1. When you have captured an interaction, you can act on the information within, and send a reply using the appropriate method, creating an `InteractionResponse` and sending that with `CreateInteractionResponse`. + +Now you're ready to create application commands! If you have any questions, please investigate the source and docs first, and then join the discord server and ask questions there. + diff --git a/deps/discord-haskell/docs/cache.md b/deps/discord-haskell/docs/cache.md new file mode 100644 index 0000000..c3f91b5 --- /dev/null +++ b/deps/discord-haskell/docs/cache.md @@ -0,0 +1,7 @@ +### Cache + +The cache (`readCache`) is currently deprecated. + +It's capable of working, but the code to update is not written. + +Current source code is at [Discord.Internal.Gateway.Cache](../src/Discord/Internal/Gateway/Cache.hs) diff --git a/deps/discord-haskell/docs/components.md b/deps/discord-haskell/docs/components.md new file mode 100644 index 0000000..32d3f6e --- /dev/null +++ b/deps/discord-haskell/docs/components.md @@ -0,0 +1,6 @@ + +### Components + +TODO + +https://discord.com/developers/docs/interactions/message-components diff --git a/deps/discord-haskell/docs/contributing.md b/deps/discord-haskell/docs/contributing.md new file mode 100644 index 0000000..56da78f --- /dev/null +++ b/deps/discord-haskell/docs/contributing.md @@ -0,0 +1,17 @@ + +### Contributing + +The library tries to hide as much detail from the user as reasonable. Lean towards making the library code uglier than the user code. The library does not meet this standard yet, but ideals make hypocrits of us all. + +A user should not have to import anything from `Discord.Internal.*` (although they can futz with the internals if they want to) + +#### Formatting + +Some of the code is moldy, and some is merely old. + +The library is somewhat open to code format style. +Try to match the formatting of the code around you. +Planning to use ormolu to autoformat the sourcecode eventually +(see [the formatting tracking issue](https://github.com/aquarial/discord-haskell/issues/87)) + +When in doubt make it look nice. diff --git a/deps/discord-haskell/docs/creating-bot.md b/deps/discord-haskell/docs/creating-bot.md new file mode 100644 index 0000000..93f47ce --- /dev/null +++ b/deps/discord-haskell/docs/creating-bot.md @@ -0,0 +1,13 @@ +1. Create an application at the Developer Portal https://discordapp.com/developers/applications + +2. Add a 'Bot User' using the settings pane on the left. Take note of `CLIENT ID` on this page. + +3. Use the BOT PERMISSIONS tab to compute a Permissions Int + +4. Invite the bot to a server filling in the `<information>` below. + +Client ID and Permissions come from previous steps. + +`https://discordapp.com/oauth2/authorize?client_id=<CLIENT_ID>&scope=bot&permissions=<PERMISSIONS>` + +5. You are ready to run the examples diff --git a/deps/discord-haskell/docs/debugging.md b/deps/discord-haskell/docs/debugging.md new file mode 100644 index 0000000..5576a55 --- /dev/null +++ b/deps/discord-haskell/docs/debugging.md @@ -0,0 +1,29 @@ + +### Debugging + + +```haskell +example :: IO () +example = do userFacingError <- runDiscord $ def + { discordToken = "Bot ZZZZZZZZZZZZZZZZZZZ" + + -- discordOnLog :: T.Text -> IO () + , discordOnLog = \s -> TIO.putStrLn s >> TIO.putStrLn "" + } + + -- userFacingError :: T.Text + TIO.putStrLn userFacingError + +``` + + +1. Always print the `userFacingError` Text returned from `runDiscord`. This is used for errors that cannot be recovered from. + +2. Use the `discordOnLog` handler to print debugging information as it happens. + + +If something else goes wrong with the library please open an issue. It is helpful, +but not always necessary, to attach a log. + +Assign a handler to the `discordOnLog :: Text -> IO ()` to print info as it happens. +Remember to remove sensitive information before posting. diff --git a/deps/discord-haskell/docs/design.md b/deps/discord-haskell/docs/design.md new file mode 100644 index 0000000..a642b93 --- /dev/null +++ b/deps/discord-haskell/docs/design.md @@ -0,0 +1,51 @@ +### Design + +```haskell +~> :info runDiscord +runDiscord :: RunDiscordOpts -> IO T.Text {- Text is user facing error. Print it -} + +~> :info RunDiscordOpts +data RunDiscordOpts = RunDiscordOpts + { discordToken :: T.Text + , discordOnStart :: DiscordHandler () + , discordOnEnd :: IO () + , discordOnEvent :: Event -> DiscordHandler () -- response to action + , discordOnLog :: Text -> IO () + , discordForkThreadForEvents :: Bool + } + +~> :info DiscordHandler +type DiscordHandler = ReaderT DiscordHandle IO + +{- ReaderT for access to the Handle -} + +{- Event handlers and Options for the program + + An exception in discordOnStart exits the program immediately + An exception in discordOnEvent continues loop + +-} + + ~> :info DiscordHandle +data DiscordHandle = DiscordHandle + { --[[ Some internal data that you normally won't use ]] + --[[ Makes sure we don't violate rate-limits! ]] + --[[ Threadsafe access ]] + } + +{- Import Discord.Handle to view the insides -} + +``` + + +#### Internals + +Use `Chan`s to pass data between threads. + +#### Websocket loop + +Make user handle events as they happen + +#### Rest request loop + +Allow executing rest requests without overstepping ratelimits diff --git a/deps/discord-haskell/docs/embeds.md b/deps/discord-haskell/docs/embeds.md new file mode 100644 index 0000000..eec38d9 --- /dev/null +++ b/deps/discord-haskell/docs/embeds.md @@ -0,0 +1,21 @@ + +### Embeds + +Embeds are special messages with boarders and images. [Example embed created by discord-haskell](./examples/embed-photo.jpg) + +The `Embed` record (and sub-records) store embed data received from Discord. + +The `CreateEmbed` record stores data when we want to create an embed. + +`CreateEmbed` has a `Default` instance, so you only need to specify the fields you use: + +```haskell +_ <- restCall (R.CreateMessageEmbed <channel_id> "Pong!" $ + def { createEmbedTitle = "Pong Embed" + , createEmbedImage = Just $ CreateEmbedImageUpload <bytestring> + , createEmbedThumbnail = Just $ CreateEmbedImageUrl + "https://avatars2.githubusercontent.com/u/37496339" + }) +``` + +Uploading a file each time is slow, prefer uploading images to a hosting site like imgur.com, and then referencing them. diff --git a/deps/discord-haskell/docs/emoji.md b/deps/discord-haskell/docs/emoji.md new file mode 100644 index 0000000..ce3d3a9 --- /dev/null +++ b/deps/discord-haskell/docs/emoji.md @@ -0,0 +1,13 @@ + +### Emoji + +For single character Emoji you can use the unicode name ("eyes", "fire", etc). + +For multi-character Emoji you must use the discord format. Type `\:emoji:` into +a discord chat and paste that into the Text + +For example `:thumbsup::skin-tone-3:` is `"👍\127997"`. +A custom emoji will look like `<name:id_number>` or `name:id_number`. + +See [examples/ping-pong.hs](https://github.com/discord-haskell/discord-haskell/blob/master/examples/ping-pong.hs) + for a `CreateReaction` request in use. diff --git a/deps/discord-haskell/docs/installing.md b/deps/discord-haskell/docs/installing.md new file mode 100644 index 0000000..9ded477 --- /dev/null +++ b/deps/discord-haskell/docs/installing.md @@ -0,0 +1,97 @@ +### Installing + +discord-haskell is on hosted on hackage at <https://hackage.haskell.org/package/discord-haskell>, + +use the latest the HACKAGE_VERSION from the changelog +<https://github.com/discord-haskell/discord-haskell/blob/master/changelog.md> + + +#### Stack - Hackage (recommended) + +In `stack.yaml` + +```yaml +extra-deps: +- emoji-0.1.0.2 +- discord-haskell-HACKAGE_VERSION +``` + +In `project.cabal` + +```cabal +executable haskell-bot + main-is: src/Main.hs + default-language: Haskell2010 + ghc-options: -threaded + build-depends: base + , text + , discord-haskell +``` + + + + + + +#### Cabal - Hackage + +In `project.cabal` + +```cabal +cabal-version: 2.0 +name: haskell-bot +version: 0.0.1 +build-type: Simple + +executable haskell-bot + main-is: src/Main.hs + default-language: Haskell2010 + ghc-options: -threaded + build-depends: base + , text + , discord-haskell == HACKAGE_VERSION + -- check hackage for most recent available version: + -- https://hackage.haskell.org/package/discord-haskell +``` + + + + + + +#### Stack - GitHub + +For specific/alternate versions not released on hackage. Only recommended if you're trying out a fork, or trying out a newer version. + +## Stack - GitHub + +In `stack.yaml` +```yaml +resolver: lts-16.20 + +extra-deps: +- git: git@github.com:discord-haskell/discord-haskell.git + commit: SOME_COMMIT_HASH + # go to https://github.com/discord-haskell/discord-haskell/commits/master + # and click on a commit to view the commit hash + # if you don't have a specific hash you're looking for, + # I recommend using the `Stack - Hackage` style installing +- emoji-0.1.0.2 +``` + +In `project.cabal` + +```cabal +cabal-version: 2.0 +name: haskell-bot +version: 0.0.1 +build-type: Simple + +executable haskell-bot + main-is: src/Main.hs + default-language: Haskell2010 + ghc-options: -threaded + build-depends: base + , text + , discord-haskell +``` diff --git a/deps/discord-haskell/docs/intents.md b/deps/discord-haskell/docs/intents.md new file mode 100644 index 0000000..ed0abc2 --- /dev/null +++ b/deps/discord-haskell/docs/intents.md @@ -0,0 +1,21 @@ + +### Intents + +#### Privileged Intents + + +Discord servers are enforcing a rule that bots cannot access Message Content without declaring a Privileged Intent. https://support-dev.discord.com/hc/en-us/articles/4404772028055 + +Bots in fewer than 75 (ie most bots) will need to check a box in the developer docs. Bots in >75 serves will need to be verified to have access to these intents. + +1. Go https://discord.com/developers/applications + +2. Click on the application you want to authorize + +3. In the taskbar on the left, select the 'Bot' tab + +4. Scroll down to "Privileged Gateway Intents" + +5. Enable Presence, Server Members, and Message Content intents. + + diff --git a/deps/discord-haskell/docs/todo.md b/deps/discord-haskell/docs/todo.md new file mode 100644 index 0000000..e555a85 --- /dev/null +++ b/deps/discord-haskell/docs/todo.md @@ -0,0 +1,36 @@ + +### TODO + + +#### Handle eventHandler backpressure + +What happens when discord sends more events than the user can handle? + +Each event forks a new thread at the moment we get it. What happens when the library receives 1000 events very quickly, how many threads do we spawn? + +#### Ensure ratelimiting is minimal + +discord/reest/http.hs implements ratelimiting https://discord.com/developers/docs/topics/rate-limits + +Print out all the headers as we get them and ensure the library is actually sending requests as fast as possible. + + +#### Cache + +Cache is a TODO at the moment. + +A cache is nice for a user to query, and we could do some automatic RestCall response caching for free performance. + +https://github.com/discord-haskell/discord-haskell/issues/44 wants to access the roles (in a `GuildMember` object) of the user who sent a `CreateMessage` event. However it only contains a `User` object. Need a separate RestCall to get the roles. + +https://github.com/discord-haskell/discord-haskell/issues/89 asks that a user can put their own data in the cache and access it. + +#### Higher level bot interface? easier to add state and stuff + +https://github.com/discord-haskell/discord-haskell/blob/master/examples/state-counter.hs + +https://github.com/discord-haskell/discord-haskell/issues/42 and https://github.com/discord-haskell/discord-haskell/issues/81 ask about how to store state in between event handler calls. + +https://github.com/discord-haskell/discord-haskell/issues/63 asks for docs on how to deploy a bot to heroku. + +The [state-counter.hs`](../examples/state-counter.hs) example shows how to increment a count between eventHandlers, and persist state to a file. diff --git a/deps/discord-haskell/docs/voice.md b/deps/discord-haskell/docs/voice.md new file mode 100644 index 0000000..6d44b49 --- /dev/null +++ b/deps/discord-haskell/docs/voice.md @@ -0,0 +1,5 @@ + +### Voice + +Voice & Audio is a separate package developed by +https://github.com/yutotakano/discord-haskell-voice |
