discord-haskell 1.0.0 → 1.1.0
raw patch · 5 files changed
+102/−13 lines, 5 filesdep ~http-clientdep ~reqPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: http-client, req
API changes (from Hackage documentation)
Files
- README.md +83/−2
- changelog.md +6/−0
- discord-haskell.cabal +3/−3
- examples/ping-pong.hs +8/−5
- src/Discord/Internal/Rest/Prelude.hs +2/−3
README.md view
@@ -1,7 +1,5 @@ # discord-haskell [](https://travis-ci.org/aquarial/discord-haskell) -## Go to the [Wiki](https://github.com/aquarial/discord-haskell/wiki) for more information- ```haskell {-# LANGUAGE OverloadedStrings #-} -- allows "string literals" to be Text @@ -36,3 +34,86 @@ isPing :: Text -> Bool isPing = ("ping" `isPrefixOf`) . toLower ```+++### Installing++discord-haskell is on hosted on hackage at https://hackage.haskell.org/package/discord-haskell, ++In `stack.yaml`++```yaml+extra-deps:+- discord-haskell-1.0.0+- emoji-0.1.0.2+```++In `project.cabal`++```cabal+executable haskell-bot+ main-is: src/Main.hs+ default-language: Haskell2010+ ghc-options: -threaded+ build-depends: base+ , text+ , discord-haskell+```++For a more complete example with various options go to +[Installing the Library](https://github.com/aquarial/discord-haskell/wiki/Installing-the-Library) wiki page++Also take a look at +[Creating your first Bot](https://github.com/aquarial/discord-haskell/wiki/Creating-your-first-Bot)+for some help setting up your bot token+++### 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/aquarial/discord-haskell/blob/master/examples/ping-pong.hs)+ for a `CreateReaction` request in use.+ ++### Debugging++Always print the userFacingError Text returned from `runDiscord`. I use this to record+errors that cannot be recovered from.++If something else goes wrong with the library please open an issue. It is helpful,+but not always necessary, to attach a log of what's going on when the library+crashes.++Assign a handler to the `discordOnLog :: Text -> IO ()` to print info as it happens.+Remember to remove sensitive information before posting.++### Getting Help++#### Official discord docs++For a list of rest requests, gateway events, and gateway sendables go to the +[official discord documentation](https://discordapp.com/developers/docs/intro)++The rest requests line up very closely. The documentation lists +[Get Channel](https://discordapp.com/developers/docs/resources/channel#get-channel)+and discord-haskell has `GetChannel :: ChannelId -> ChannelRequest Channel`. Same for gateway `Event`s.++#### Examples++The [examples](https://github.com/aquarial/discord-haskell/tree/master/examples) were crafted+to display a variety of use cases. Read them with care.++#### Open an Issue++For deeper questions about how the library functions, feel free to open an issue.++#### Discord server++Coming sometime!
changelog.md view
@@ -4,6 +4,12 @@ ## master +## 1.1.0++Upgrade req to 2.x major version.++## 1.0.0+ Going through some major updates to the library. Expect types to change and things to break. Compare the [old ping-pong](https://github.com/aquarial/discord-haskell/blob/20f7f8556823a754c76d01484118a5abf336530b/examples/ping-pong.hs)
discord-haskell.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.0 name: discord-haskell -- library version is also noted at src/Discord/Rest/Prelude.hs-version: 1.0.0+version: 1.1.0 description: Functions and data types to write discord bots. Official discord docs <https://discordapp.com/developers/docs/reference>. .@@ -72,10 +72,10 @@ , containers >=0.5.11.0 && <0.7 , data-default >=0.7.1.1 && <0.8 , emoji == 0.1.0.2- , http-client >=0.5.13.1 && <0.6+ , http-client >=0.6.4 && <0.7 , iso8601-time >=0.1.5 && <0.2 , MonadRandom >=0.5.1.1 && <0.6- , req >=1.1.0 && <1.3+ , req >=2.1.0 && <2.2 , JuicyPixels >=3.2.9.5 && <3.4 , safe-exceptions >=0.1.7.0 && <0.2 , text >=1.2.3.0 && <1.3
examples/ping-pong.hs view
@@ -10,6 +10,7 @@ import Discord.Types import qualified Discord.Requests as R +-- Allows this code to be an executable. See discord-haskell.cabal main :: IO () main = pingpongExample @@ -18,7 +19,7 @@ pingpongExample = do tok <- TIO.readFile "./examples/auth-token.secret" - -- open ghci and run [[ def :: RunDiscordOpts ]] to see default Opts+ -- open ghci and run [[ :info RunDiscordOpts ]] to see available fields t <- runDiscord $ def { discordToken = tok , discordOnStart = startHandler , discordOnEnd = putStrLn "Ended"@@ -28,7 +29,8 @@ threadDelay (1 `div` 10 * 10^6) TIO.putStrLn t --- If a handler throws an exception, discord-haskell will gracefully shutdown+-- If the start handler throws an exception, discord-haskell will gracefully shutdown+-- Use place to execute commands you know you want to complete startHandler :: DiscordHandle -> IO () startHandler dis = do Right partialGuilds <- restCall dis R.GetCurrentUserGuilds@@ -41,9 +43,10 @@ pure () _ -> pure () +-- If an event handler throws an exception, discord-haskell will continue to run eventHandler :: DiscordHandle -> Event -> IO () eventHandler dis event = case event of- MessageCreate m -> when (not (fromBot m) && isPing (messageText m)) $ do+ MessageCreate m -> when (not (fromBot m) && isPing m) $ do _ <- restCall dis (R.CreateReaction (messageChannel m, messageId m) "eyes") threadDelay (4 * 10^6) _ <- restCall dis (R.CreateMessage (messageChannel m) "Pong!")@@ -57,5 +60,5 @@ fromBot :: Message -> Bool fromBot m = userIsBot (messageAuthor m) -isPing :: T.Text -> Bool-isPing = ("ping" `T.isPrefixOf`) . T.map toLower+isPing :: Message -> Bool+isPing = ("ping" `T.isPrefixOf`) . T.map toLower . messageText
src/Discord/Internal/Rest/Prelude.hs view
@@ -7,7 +7,6 @@ module Discord.Internal.Rest.Prelude where import Prelude hiding (log)-import Data.Default (def) import Control.Exception.Safe (throwIO) import Control.Monad.IO.Class (MonadIO, liftIO) import Data.Monoid ((<>))@@ -26,7 +25,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, 1.0.0)"+ agent = "DiscordBot (https://github.com/aquarial/discord-haskell, 1.1.0)" -- Append to an URL infixl 5 //@@ -54,4 +53,4 @@ -- | Throw actual exceptions handleHttpException = liftIO . throwIO -- | Don't throw exceptions on http error codes like 404- getHttpConfig = pure $ def { R.httpConfigCheckResponse = \_ _ _ -> Nothing }+ getHttpConfig = pure $ R.defaultHttpConfig { R.httpConfigCheckResponse = \_ _ _ -> Nothing }