discord-haskell 0.8.1 → 0.8.2
raw patch · 9 files changed
+164/−36 lines, 9 filesdep ~JuicyPixelsdep ~aesondep ~containersPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: JuicyPixels, aeson, containers, req
API changes (from Hackage documentation)
+ Discord.Types.Gateway: ActivityTypeWatching :: ActivityType
Files
- LICENSE +23/−17
- README.md +104/−0
- changelog.md +8/−1
- discord-haskell.cabal +16/−13
- src/Discord/Rest/Channel.hs +1/−1
- src/Discord/Rest/HTTP.hs +8/−1
- src/Discord/Rest/Prelude.hs +1/−1
- src/Discord/Types/Events.hs +2/−2
- src/Discord/Types/Gateway.hs +1/−0
LICENSE view
@@ -1,20 +1,26 @@-Copyright (c) 2016 Joshua Koike+MIT License -Permission is hereby granted, free of charge, to any person obtaining-a copy of this software and associated documentation files (the-"Software"), to deal in the Software without restriction, including-without limitation the rights to use, copy, modify, merge, publish,-distribute, sublicense, and/or sell copies of the Software, and to-permit persons to whom the Software is furnished to do so, subject to-the following conditions:+Copyright (c) Joshua Koike, 2019 karl -The above copyright notice and this permission notice shall be included-in all copies or substantial portions of the Software.+Copyright for portions of project discord-haskell are held by+Joshua Koike,2016 as part of project discord-hs. All other copyright+for project discord-haskell are held by karl,2019. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ README.md view
@@ -0,0 +1,104 @@+# discord-haskell [](https://travis-ci.org/aquarial/discord-haskell)++Please refer to `Getting Started` and `Notes` when +relevant. A few minutes of reading can save you +hours of debugging.++Recent change: `master` branch has the potentially broken, most+recent commits, `stable` has the most recent working version.+Pull requests are automatically made against `master` and it's+nice to merge pull requests to test them.++## Getting Started++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+(this does not immediately affect anything, hold onto this number)++3 Invite the bot to a server filling in the `<>` information.+Client ID and Permissions come from previous steps.+`https://discordapp.com/oauth2/authorize?client_id=<CLIENT_ID>&scope=bot&permissions=<PERMISSIONS>`++4 Connect to the gateway once in order to send CreateMessage events.+[This is a Discord requirement.](https://discordapp.com/developers/docs/resources/channel#create-message)++5 Look at the examples.+[examples/gateway.hs](./examples/gateway.hs),+[examples/rest.hs](./examples/rest.hs),+[examples/cache.hs](./examples/cache.hs), and+[examples/ping-pong.hs](./examples/ping-pong.hs)++6 Understand what's available to the bot. Rest API calls can modify+[Channels](https://discordapp.com/developers/docs/resources/channel#get-channel),+[Emoji](https://discordapp.com/developers/docs/resources/emoji#list-guild-emojis),+[Guilds](https://discordapp.com/developers/docs/resources/guild#get-guild),+etc. Most endpoints are covered with very similar names. `List Guild Emojis`+becomes `ListGuildEmojis`. You can use `:info` in `ghci` on type constructors to+explore the ADTs.++[Gateway Events](https://discordapp.com/developers/docs/topics/gateway#commands-and-events-gateway-events)+provide the other source of info, using `nextEvent` and `sendCommand`. Use `:info` to explore `Event` and `GatewaySendable` ADTs.++7 Add this library to your dependencies. discord-haskell is on hackage+with strict version bounds to stackage lts-12.10. You can also use+the github repo.++```+# in stack.yaml (if using stack)+resolver: lts-12.10+extra-deps:+- git: git@github.com:aquarial/discord-haskell.git+ commit: <most recent stable commit>+ extra-dep: true++# in project.cabal+ build-depends: base+ , discord-haskell++```++## Notes++`loginRest` allows `restCall`. `loginRestGateway` allows `restCall`,+`nextEvent`, `sendCommand`, and `readCache`. **Use `loginRest` if you don't need the +gateway.**++Use `Control.Exception.finally` with `stopDiscord` to safely+kill background threads when running examples in ghci+(otherwise exit ghci and reopen to kill threads).++The examples will work on the `stable` branch. The `master` branch+has the most recent (potentially) breaking changes.++To get the format to use for Emoji, type `\:emoji:` into +a discord chat. You should copy-paste that into the request. This+can be a bit finicky. The equivalent of `:thumbsup::skin-tone-3:`+is `"👍\127997"` for example, and a custom emoji will look+like `<name:id_number>` or `name:id_number`.++## History++This library was originally forked from+[discord.hs](https://github.com/jano017/Discord.hs).+After rewriting the gateway/rest loops and extending the types+I think it makes more sense to present this library as+separate from the source. The APIs are not compatible.++## TO DO++In roughly the order I'm working on them:++- Finish REST request ADT. Search for `-- todo` pattern+- Add data types for+[permissions](https://discordapp.com/developers/docs/topics/permissions) and+[presences](https://discordapp.com/developers/docs/topics/gateway#presence-update)+- Update channel types (fill out guildcategory)+- Modify cache with Events+- Add gateway ToJSON for events+- Update comments on ADT types+
changelog.md view
@@ -2,7 +2,14 @@ View on github for newest version: https://github.com/aquarial/discord-haskell/blob/master/changelog.md -### master+## master+++### 0.8.2++Hardcode CreateReaction delay so bots can add reactions 4 times faster++[MP2E](https://github.com/aquarial/discord-haskell/pull/14) Fixed parse error on GuildBanAdd + GuildBanRevoke: user\_object instead the whole object ### 0.8.1
discord-haskell.cabal view
@@ -1,23 +1,29 @@ name: discord-haskell -- library version is also noted at src/Discord/Rest/Prelude.hs-version: 0.8.1-synopsis: Write bots for Discord in Haskell+version: 0.8.2 description: Functions and data types to write discord bots. Official discord docs <https://discordapp.com/developers/docs/reference>. . See the project readme for quickstart notes <https://github.com/aquarial/discord-haskell#discord-haskell>+synopsis: Write bots for Discord in Haskell homepage: https://github.com/aquarial/discord-haskell+bug-reports: https://github.com/aquarial/discord-haskell/issues license: MIT license-file: LICENSE author: Karl maintainer: ksfish5@gmail.com--- copyright:+copyright: 2019 Karl category: Network build-type: Simple-extra-source-files: changelog.md-cabal-version: >=1.10+extra-doc-files: README.md+ , changelog.md+cabal-version: 1.18 +source-repository head+ type: git+ location: https://github.com/aquarial/discord-haskell.git+ library ghc-options: -Wall -fno-warn-type-defaults@@ -44,25 +50,22 @@ , Discord.Types.Guild build-depends: base >=4 && <5- , aeson >=1.3.1.1 && <1.4+ , aeson >=1.3.1.1 && <1.5 , async >=2.2.1 && <2.3 , bytestring >=0.10.8.2 && <0.11 , base64-bytestring >=1.0.0.1 && <1.1- , containers >=0.5.11.0 && <0.6+ , containers >=0.5.11.0 && <0.7 , data-default >=0.7.1.1 && <0.8 , http-client >=0.5.13.1 && <0.6 , iso8601-time >=0.1.5 && <0.2 , MonadRandom >=0.5.1.1 && <0.6- , req >=1.1.0 && <1.2- , JuicyPixels >=3.2.9.5 && <3.3+ , req >=1.1.0 && <1.3+ , JuicyPixels >=3.2.9.5 && <3.4 , safe-exceptions >=0.1.7.0 && <0.2 , text >=1.2.3.0 && <1.3 , time >=1.8.0.2 && <1.9 , unordered-containers >=0.2.9.0 && <0.3 , vector >=0.12.0.1 && <0.13 , websockets >=0.12.5.1 && <0.13- , wuss >=1.1.10 && <1.2+ , wuss >=1.1.10 && <1.2 -source-repository head- type : git- location: https://github.com/aquarial/discord-haskell
src/Discord/Rest/Channel.hs view
@@ -182,7 +182,7 @@ (CreateMessage chan _) -> "msg " <> show chan (CreateMessageEmbed chan _ _) -> "msg " <> show chan (CreateMessageUploadFile chan _ _) -> "msg " <> show chan- (CreateReaction (chan, _) _) -> "react " <> show chan+ (CreateReaction (chan, _) _) -> "add_react " <> show chan (DeleteOwnReaction (chan, _) _) -> "react " <> show chan (DeleteUserReaction (chan, _) _ _) -> "react " <> show chan (GetReactions (chan, _) _ _) -> "react " <> show chan
src/Discord/Rest/HTTP.hs view
@@ -19,6 +19,7 @@ import Control.Concurrent.MVar import Control.Concurrent.Chan import Data.Ix (inRange)+import Data.List (isPrefixOf) import Data.Time.Clock.POSIX (POSIXTime, getPOSIXTime) import qualified Data.ByteString.Char8 as Q import qualified Data.ByteString.Lazy.Char8 as QL@@ -68,8 +69,14 @@ <> show ((i - curtime) * 1000)) threadDelay $ round ((i - curtime + 0.1) * 1000) loop ratelocker- PathWait i -> loop $ M.insert route i ratelocker+ PathWait i -> loop $ M.insert route (if isPrefixOf "add_react " route+ then curtime + 0.25 else i)+ ratelocker NoLimit -> loop ratelocker++-- Note: we hardcode delay for CreateReaction ("add_react")+-- why the headers are wrong: https://github.com/discordapp/discord-api-docs/issues/182+-- why I chose to hardcode it: https://github.com/aquarial/discord-haskell/issues/16 data RateLimited = Available | Locked
src/Discord/Rest/Prelude.hs view
@@ -24,7 +24,7 @@ where -- | https://discordapp.com/developers/docs/reference#user-agent -- Second place where the library version is noted- agent = "DiscordBot (https://github.com/aquarial/discord-haskell, 0.8.1)"+ agent = "DiscordBot (https://github.com/aquarial/discord-haskell, 0.8.2)" -- Append to an URL infixl 5 //
src/Discord/Types/Events.hs view
@@ -126,8 +126,8 @@ "GUILD_CREATE" -> GuildCreate <$> reparse o <*> reparse o "GUILD_UPDATE" -> GuildUpdate <$> reparse o "GUILD_DELETE" -> GuildDelete <$> reparse o- "GUILD_BAN_ADD" -> GuildBanAdd <$> o .: "guild_id" <*> reparse o- "GUILD_BAN_REMOVE" -> GuildBanRemove <$> o .: "guild_id" <*> reparse o+ "GUILD_BAN_ADD" -> GuildBanAdd <$> o .: "guild_id" <*> o .: "user"+ "GUILD_BAN_REMOVE" -> GuildBanRemove <$> o .: "guild_id" <*> o .: "user" "GUILD_EMOJI_UPDATE" -> GuildEmojiUpdate <$> o .: "guild_id" <*> o .: "emojis" "GUILD_INTEGRATIONS_UPDATE" -> GuildIntegrationsUpdate <$> o .: "guild_id" "GUILD_MEMBER_ADD" -> GuildMemberAdd <$> o .: "guild_id" <*> reparse o
src/Discord/Types/Gateway.hs view
@@ -71,6 +71,7 @@ data ActivityType = ActivityTypeGame | ActivityTypeStreaming | ActivityTypeListening+ | ActivityTypeWatching deriving (Enum, Show) data UpdateStatusType = UpdateStatusOnline