discord-haskell 1.5.0 → 1.5.1
raw patch · 5 files changed
+25/−22 lines, 5 files
Files
- changelog.md +4/−0
- discord-haskell.cabal +1/−1
- examples/ping-pong.hs +15/−18
- src/Discord/Internal/Rest/Channel.hs +4/−2
- src/Discord/Internal/Rest/Prelude.hs +1/−1
changelog.md view
@@ -5,6 +5,10 @@ ## master +## 1.5.1++Fix `EditMessage` rest request, send JSON+ ## 1.5.0 [rexim](https://github.com/aquarial/discord-haskell/pull/35) Add `Read` instance for `Snowflake`
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.5.0+version: 1.5.1 description: Functions and data types to write discord bots. Official discord docs <https://discordapp.com/developers/docs/reference>. .
examples/ping-pong.hs view
@@ -4,6 +4,7 @@ import Control.Concurrent (threadDelay) import Data.Char (toLower) import qualified Data.Text as T+import qualified Data.ByteString as B import qualified Data.Text.IO as TIO import Discord@@ -23,7 +24,7 @@ t <- runDiscord $ def { discordToken = tok , discordOnStart = startHandler , discordOnEnd = putStrLn "Ended"- , discordOnEvent = eventHandler+ -- , discordOnEvent = eventHandler , discordOnLog = \s -> TIO.putStrLn s >> TIO.putStrLn "" } threadDelay (1 `div` 10 * 10^6)@@ -34,31 +35,27 @@ startHandler :: DiscordHandle -> IO () startHandler dis = do Right partialGuilds <- restCall dis R.GetCurrentUserGuilds+ bs <- B.readFile "./examples/embed-photo.jpg"+ bs2 <- B.readFile "./examples/blart.jpg" forM_ partialGuilds $ \pg -> do Right guild <- restCall dis $ R.GetGuild (partialGuildId pg) Right chans <- restCall dis $ R.GetGuildChannels (guildId guild) case filter isTextChannel chans of- (c:_) -> do _ <- restCall dis $ R.CreateMessage (channelId c) "Hello! I will reply to pings with pongs"+ (c:_) -> do Right m <- restCall dis $ R.CreateMessageEmbed (channelId c) "Hello! I will reply to pings with pongs" $def { createEmbedTitle = "BEFORE"+ , createEmbedImage = Just $ CreateEmbedImageUpload bs}+ print m+ print ()+ threadDelay $ 5 * 10^6+ e <- restCall dis $ R.EditMessage (messageChannel m, messageId m) "New " $+ Just $ def { createEmbedTitle = "asdf"+ , createEmbedThumbnail = Just $ CreateEmbedImageUpload bs+ , createEmbedFooterIcon = Just $ CreateEmbedImageUpload bs2+ }+ print e 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 m) $ do- _ <- restCall dis (R.CreateReaction (messageChannel m, messageId m) "eyes")- threadDelay (4 * 10^6)- _ <- restCall dis (R.CreateMessage (messageChannel m) "Pong!")- pure ()- _ -> pure ()- isTextChannel :: Channel -> Bool isTextChannel (ChannelText {}) = True isTextChannel _ = False--fromBot :: Message -> Bool-fromBot m = userIsBot (messageAuthor m)--isPing :: Message -> Bool-isPing = ("ping" `T.isPrefixOf`) . T.map toLower . messageText
src/Discord/Internal/Rest/Channel.hs view
@@ -296,8 +296,10 @@ Delete (channels // chan /: "messages" // msgid /: "reactions" ) mempty (EditMessage (chan, msg) new embed) ->- let partJson = partBS "payload_json" $ BL.toStrict $ encode $ toJSON $ object ["content" .= new]- body = R.reqBodyMultipart (partJson : maybeEmbed embed)+ let partJson = toJSON $ object $ ["content" .= new] ++ case embed of+ Just e -> ["embed" .= createEmbed e]+ Nothing -> []+ body = pure (R.ReqBodyJson partJson) in Patch (channels // chan /: "messages" // msg) body mempty (DeleteMessage (chan, msg)) ->
src/Discord/Internal/Rest/Prelude.hs view
@@ -25,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.5.0)"+ agent = "DiscordBot (https://github.com/aquarial/discord-haskell, 1.5.1)" -- Append to an URL infixl 5 //