discord-haskell 1.12.3 → 1.12.4
raw patch · 7 files changed
+30/−16 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +6/−1
- changelog.md +4/−0
- discord-haskell.cabal +1/−1
- examples/ping-pong.hs +3/−1
- src/Discord.hs +6/−4
- src/Discord/Internal/Gateway/EventLoop.hs +9/−8
- src/Discord/Internal/Rest/Prelude.hs +1/−1
README.md view
@@ -23,7 +23,10 @@ pingpongExample = do userFacingError <- runDiscord $ def { discordToken = "Bot ZZZZZZZZZZZZZZZZZZZ"- , discordOnEvent = eventHandler }+ , discordOnEvent = eventHandler+ , discordOnLog = \s -> TIO.putStrLn s >> TIO.putStrLn ""+ } -- if you see OnLog error, post in the discord / open an issue+ TIO.putStrLn userFacingError -- userFacingError is an unrecoverable error -- put normal 'cleanup' code in discordOnEnd (see examples)@@ -54,6 +57,8 @@ ### [todo](./docs/todo.md) ### [contributing](./docs/contributing.md)++### [intents](./docs/intents.md) ### [applicationcommands](./docs/applicationcommands.md)
changelog.md view
@@ -6,6 +6,10 @@ ## master +## 1.12.4++Library won't crash if something fails to parse. Errors are printed to the log+ ## 1.12.3 Add another CreateMessage flag option, stop crashing on unknown flags.
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.12.3+version: 1.12.4 description: Functions and data types to write discord bots. Official discord docs <https://discord.com/developers/docs/reference>. .
examples/ping-pong.hs view
@@ -33,7 +33,7 @@ -- open ghci and run [[ :info RunDiscordOpts ]] to see available fields err <- runDiscord $ def { discordToken = tok , discordOnStart = startHandler- , discordOnEnd = liftIO $ putStrLn "Ended"+ , discordOnEnd = liftIO $ threadDelay (round (0.4 * 10^6)) >> putStrLn "Ended" , discordOnEvent = eventHandler , discordOnLog = \s -> TIO.putStrLn s >> TIO.putStrLn "" , discordGatewayIntent = def {gatewayIntentMembers = True, gatewayIntentPrecenses =True}@@ -47,6 +47,8 @@ -- Use place to execute commands you know you want to complete startHandler :: DiscordHandler () startHandler = do+ liftIO $ putStrLn "Started ping-pong bot"+ let activity = def { activityName = "ping-pong" , activityType = ActivityTypeGame }
src/Discord.hs view
@@ -105,6 +105,7 @@ (readChan (gatewayHandleEvents (discordHandleGateway handle))) case next of Left err -> libError err+ Right (Left err) -> libError (T.pack (show err)) Right (Right event) -> do let userEvent = userFacingEvent event let action = if discordForkThreadForEvents opts then void . forkIO@@ -112,10 +113,10 @@ action $ do me <- liftIO . runReaderT (try $ discordOnEvent opts userEvent) $ handle case me of Left (e :: SomeException) -> writeChan (discordHandleLog handle)- ("discord-haskell stopped on an exception:\n\n" <> T.pack (show e))+ ("eventhandler - crashed on [" <> T.pack (show userEvent) <> "] "+ <> " with error: " <> T.pack (show e)) Right _ -> pure () loop- Right (Left err) -> libError (T.pack (show err)) data RestCallErrorCode = RestCallErrorCode Int T.Text T.Text@@ -136,9 +137,10 @@ Left (RestCallInternalHttpException _) -> threadDelay (10 * 10^(6 :: Int)) >> restCall r Left (RestCallInternalNoParse err dat) -> do- let formaterr = T.pack ("Parse Exception " <> err <> " for " <> show dat)+ let formaterr = T.pack ("restcall - parse exception [" <> err <> "]"+ <> " while handling" <> show dat) writeChan (discordHandleLog h) formaterr- pure (Left (RestCallErrorCode 400 "Library Stopped Working" formaterr))+ pure (Left (RestCallErrorCode 400 "Library Parse Exception" formaterr)) -- | Send a user GatewaySendable sendCommand :: GatewaySendable -> DiscordHandler ()
src/Discord/Internal/Gateway/EventLoop.hs view
@@ -152,9 +152,9 @@ Right (Reconnect) -> pure LoopReconnect Right (InvalidSession retry) -> pure $ if retry then LoopReconnect else LoopStart Right (HeartbeatAck) -> loop- Right (ParseError e) -> do writeChan eventChan (Left (GatewayExceptionEventParseError e- "Normal event loop"))- pure LoopClosed+ Right (ParseError _e) -> -- getPayload logs the parse error. nothing to do here+ loop+ Left (CloseRequest code str) -> case code of -- see Discord and MDN documentation on gateway close event codes -- https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-close-event-codes@@ -167,11 +167,12 @@ 4014 -> do writeChan eventChan (Left (GatewayExceptionUnexpected (Hello 0) $ "Tried to declare an unauthorized GatewayIntent. " <> "Use the discord app manager to authorize by following: " <>- "https://github.com/aquarial/discord-haskell/issues/76"))+ "https://github.com/aquarial/discord-haskell/blob/master/docs/intents.md")) pure LoopClosed- _ -> do writeChan eventChan (Left (GatewayExceptionConnection (CloseRequest code str)- "Unknown close code. Closing connection. Consider opening an issue with discord-haskell"))- pure LoopClosed+ _ -> do writeChan log ("gateway - unknown websocket close code " <> T.pack (show code)+ <> " [" <> TE.decodeUtf8 (BL.toStrict str) <> "]. Consider opening an issue "+ <> "https://github.com/aquarial/discord-haskell/issues")+ pure LoopStart Left _ -> pure LoopReconnect @@ -197,7 +198,7 @@ msg' <- receiveData conn case eitherDecode msg' of Right msg -> pure msg- Left err -> do writeChan log ("gateway - received parse Error - " <> T.pack err+ Left err -> do writeChan log ("gateway - received exception [" <> T.pack err <> "]" <> " while decoding " <> TE.decodeUtf8 (BL.toStrict msg')) pure (ParseError (T.pack err))
src/Discord/Internal/Rest/Prelude.hs view
@@ -34,7 +34,7 @@ where -- | https://discord.com/developers/docs/reference#user-agent -- Second place where the library version is noted- agent = "DiscordBot (https://github.com/aquarial/discord-haskell, 1.12.3)"+ agent = "DiscordBot (https://github.com/aquarial/discord-haskell, 1.12.4)" -- Append to an URL infixl 5 //