packages feed

discord-haskell 1.5.1 → 1.5.2

raw patch · 4 files changed

+21/−17 lines, 4 files

Files

changelog.md view
@@ -4,6 +4,7 @@  ## master +## 1.5.2  ## 1.5.1 
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.1+version:             1.5.2 description:         Functions and data types to write discord bots.                      Official discord docs <https://discordapp.com/developers/docs/reference>.                      .
examples/ping-pong.hs view
@@ -4,7 +4,6 @@ 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@@ -24,7 +23,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)@@ -35,27 +34,31 @@ 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 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+      (c:_) -> do _ <- restCall dis $ R.CreateMessage (channelId c) "Hello! I will reply to pings with pongs"                   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/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.1)"+  agent = "DiscordBot (https://github.com/aquarial/discord-haskell, 1.5.2)"  -- Append to an URL infixl 5 //