Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some warnings #50

Merged
merged 4 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/cache.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}

import Data.Monoid ((<>))
import qualified Data.Text.IO as TIO

import Discord
Expand Down
1 change: 0 additions & 1 deletion examples/gateway.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}

import Data.Monoid ((<>))
import Control.Monad (void, forever)
import Control.Concurrent (forkIO, killThread)
import Control.Concurrent.Chan
Expand Down
8 changes: 4 additions & 4 deletions examples/ping-pong.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pingpongExample = do
, discordOnEvent = eventHandler
, discordOnLog = \s -> TIO.putStrLn s >> TIO.putStrLn ""
}
threadDelay (1 `div` 10 * 10^6)
threadDelay (1 `div` 10 * 10^(6 :: Int))
TIO.putStrLn t

-- If the start handler throws an exception, discord-haskell will gracefully shutdown
Expand All @@ -48,9 +48,9 @@ startHandler = do
eventHandler :: Event -> DiscordHandler ()
eventHandler event = case event of
MessageCreate m -> when (not (fromBot m) && isPing m) $ do
_ <- restCall (R.CreateReaction (messageChannel m, messageId m) "eyes")
threadDelay (4 * 10^6)
_ <- restCall (R.CreateMessage (messageChannel m) "Pong!")
_ <- restCall dis (R.CreateReaction (messageChannel m, messageId m) "eyes")
threadDelay (4 * 10^(6 :: Int))
_ <- restCall dis (R.CreateMessage (messageChannel m) "Pong!")
pure ()
_ -> pure ()

Expand Down
4 changes: 2 additions & 2 deletions src/Discord.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ restCall r = do h <- ask
Left (RestCallInternalErrorCode c e1 e2) ->
pure (Left (RestCallErrorCode c (TE.decodeUtf8 e1) (TE.decodeUtf8 e2)))
Left (RestCallInternalHttpException _) ->
threadDelay (10 * 10^6) >> restCall r
threadDelay (10 * 10^(6 :: Int)) >> restCall r
Left (RestCallInternalNoParse err dat) -> do
let formaterr = T.pack ("Parse Exception " <> err <> " for " <> show dat)
writeChan (discordHandleLog h) formaterr
Expand Down Expand Up @@ -165,7 +165,7 @@ readCache = do
-- | Stop all the background threads
stopDiscord :: MonadIO m => DiscordHandle -> m ()
stopDiscord h = do _ <- tryPutMVar (discordHandleLibraryError h) "Library has closed"
threadDelay (10^6 `div` 10)
threadDelay (10^(6 :: Int) `div` 10)
mapM_ (killThread . toId) (discordHandleThreads h)
where toId t = case t of
DiscordHandleThreadIdRest a -> a
Expand Down
1 change: 0 additions & 1 deletion src/Discord/Internal/Gateway/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
module Discord.Internal.Gateway.Cache where

import Prelude hiding (log)
import Data.Monoid ((<>))
import Control.Monad (forever)
import Control.Concurrent.MVar
import Control.Concurrent.Chan
Expand Down
9 changes: 4 additions & 5 deletions src/Discord/Internal/Gateway/EventLoop.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Control.Concurrent.Async (race)
import Control.Concurrent.Chan
import Control.Concurrent (threadDelay, killThread, forkIO)
import Control.Exception.Safe (try, finally, handle, SomeException)
import Data.Monoid ((<>))
import Data.IORef
import Data.Aeson (eitherDecode, encode)
import qualified Data.Text as T
Expand Down Expand Up @@ -90,7 +89,7 @@ connectionLoop auth (events, userSend) log = loop ConnStart 0
startEventStream (ConnData conn seshID auth events) interval seqID userSend log
Right (InvalidSession retry) -> do
t <- getRandomR (1,5)
threadDelay (t * 10^6)
threadDelay (t * (10^(6 :: Int)))
pure $ if retry
then ConnReconnect (Auth tok) seshID seqID
else ConnStart
Expand All @@ -104,7 +103,7 @@ connectionLoop auth (events, userSend) log = loop ConnStart 0
pure ConnClosed
case next :: Either SomeException ConnLoopState of
Left _ -> do t <- getRandomR (3,20)
threadDelay (t * 10^6)
threadDelay (t * (10^(6 :: Int)))
writeChan log ("gateway - trying to reconnect after " <> T.pack (show retries)
<> " failures")
loop (ConnReconnect (Auth tok) seshID seqID) (retries + 1)
Expand All @@ -130,7 +129,7 @@ getPayload conn log = try $ do

heartbeat :: Chan GatewaySendable -> Int -> IORef Integer -> IO ()
heartbeat send interval seqKey = do
threadDelay (1 * 10^6)
threadDelay (1 * 10^(6 :: Int))
forever $ do
num <- readIORef seqKey
writeChan send (Heartbeat num)
Expand Down Expand Up @@ -208,7 +207,7 @@ data Sendables = Sendables { -- | Things the user wants to send. Doesn't reset o
sendableLoop :: Connection -> Sendables -> IO ()
sendableLoop conn sends = forever $ do
-- send a ~120 events a min by delaying
threadDelay (round (10^6 * (62 / 120)))
threadDelay $ round ((10^(6 :: Int)) * (62 / 120) :: Double)
let e :: Either GatewaySendable GatewaySendable -> GatewaySendable
e = either id id
payload <- e <$> race (readChan (userSends sends)) (readChan (gatewaySends sends))
Expand Down
1 change: 0 additions & 1 deletion src/Discord/Internal/Rest/Channel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module Discord.Internal.Rest.Channel

import Data.Aeson
import Data.Emoji (unicodeByName)
import Data.Monoid (mempty, (<>))
import qualified Data.Text as T
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
Expand Down
1 change: 0 additions & 1 deletion src/Discord/Internal/Rest/Emoji.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module Discord.Internal.Rest.Emoji
) where

import Data.Aeson
import Data.Monoid (mempty, (<>))
import Codec.Picture
import Network.HTTP.Req ((/:))
import qualified Network.HTTP.Req as R
Expand Down
1 change: 0 additions & 1 deletion src/Discord/Internal/Rest/Guild.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module Discord.Internal.Rest.Guild


import Data.Aeson
import Data.Monoid (mempty, (<>))
import Network.HTTP.Req ((/:))
import qualified Network.HTTP.Req as R
import qualified Data.Text as T
Expand Down
5 changes: 2 additions & 3 deletions src/Discord/Internal/Rest/HTTP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module Discord.Internal.Rest.HTTP
) where

import Prelude hiding (log)
import Data.Semigroup ((<>))

import Control.Monad.IO.Class (liftIO)
import Control.Concurrent (threadDelay)
Expand Down Expand Up @@ -101,8 +100,8 @@ tryRequest _log action = do
let body = R.responseBody resp
code = R.responseStatusCode resp
status = R.responseStatusMessage resp
global = (Just "true" ==) $ readMaybeBS =<< R.responseHeader resp "X-RateLimit-Global"
remain = fromMaybe 1 $ readMaybeBS =<< R.responseHeader resp "X-RateLimit-Remaining"
global = (Just ("true" :: String) ==) $ readMaybeBS =<< R.responseHeader resp "X-RateLimit-Global"
remain = fromMaybe 1 $ readMaybeBS =<< R.responseHeader resp "X-RateLimit-Remaining" :: Integer
reset = withDelta . fromMaybe 10 $ readMaybeBS =<< R.responseHeader resp "X-RateLimit-Reset-After"

withDelta :: Double -> POSIXTime
Expand Down
1 change: 0 additions & 1 deletion src/Discord/Internal/Rest/Invite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Discord.Internal.Rest.Invite
( InviteRequest(..)
) where

import Data.Monoid (mempty)
import Network.HTTP.Req ((/:))
import qualified Network.HTTP.Req as R
import qualified Data.Text as T
Expand Down
1 change: 0 additions & 1 deletion src/Discord/Internal/Rest/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module Discord.Internal.Rest.Prelude where
import Prelude hiding (log)
import Control.Exception.Safe (throwIO)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.Monoid ((<>))
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE

Expand Down
1 change: 0 additions & 1 deletion src/Discord/Internal/Rest/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module Discord.Internal.Rest.User

import Data.Aeson
import Codec.Picture
import Data.Monoid (mempty, (<>))
import Network.HTTP.Req ((/:))
import qualified Network.HTTP.Req as R
import qualified Data.Text as T
Expand Down
1 change: 0 additions & 1 deletion src/Discord/Internal/Rest/Webhook.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module Discord.Internal.Rest.Webhook
) where

import Data.Aeson
import Data.Monoid (mempty, (<>))
import qualified Data.Text as T
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL
Expand Down
1 change: 0 additions & 1 deletion src/Discord/Internal/Types/Channel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module Discord.Internal.Types.Channel where
import Control.Applicative (empty)
import Data.Aeson
import Data.Aeson.Types (Parser)
import Data.Monoid ((<>))
import Data.Text (Text)
import Data.Time.Clock
import qualified Data.Text as T
Expand Down
1 change: 0 additions & 1 deletion src/Discord/Internal/Types/Gateway.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module Discord.Internal.Types.Gateway where
import System.Info

import qualified Data.Text as T
import Data.Monoid ((<>))
import Data.Time (UTCTime)
import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds)
import Data.Aeson
Expand Down
1 change: 0 additions & 1 deletion src/Discord/Internal/Types/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Data.Aeson.Types
import Data.Time.Clock
import qualified Data.Text as T
import Data.Time.Clock.POSIX
import Data.Monoid ((<>))
import Control.Monad (mzero)

import Data.Functor.Compose (Compose(Compose, getCompose))
Expand Down