discord-haskell: Write bots for Discord in Haskell

[ library, mit, network, program ] [ Propose Tags ]
Versions [RSS] 0.5.0, 0.5.1, 0.6.0, 0.7.0, 0.7.1, 0.8.0, 0.8.1, 0.8.2, 0.8.3, 0.8.4, 1.0.0, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.6.1, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.9.0, 1.9.1, 1.9.2, 1.10.0, 1.11.0, 1.12.0, 1.12.1, 1.12.2, 1.12.3, 1.12.4, 1.12.5, 1.13.0, 1.14.0, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.15.5, 1.15.6, 1.16.0, 1.16.1
Change log changelog.md
Dependencies aeson (>=1.3.1.1 && <1.5), async (>=2.2.1 && <2.3), base (>=4 && <5), base64-bytestring (>=1.0.0.1 && <1.1), bytestring (>=0.10.8.2 && <0.11), containers (>=0.5.11.0 && <0.7), data-default (>=0.7.1.1 && <0.8), discord-haskell, emoji (==0.1.0.2), http-client (>=0.5.13.1 && <0.6), iso8601-time (>=0.1.5 && <0.2), JuicyPixels (>=3.2.9.5 && <3.4), MonadRandom (>=0.5.1.1 && <0.6), req (>=1.1.0 && <1.3), safe-exceptions (>=0.1.7.0 && <0.2), text (>=1.2.3.0 && <1.3), time (>=1.8.0.2 && <1.9), unordered-containers (>=0.2.9.0 && <0.3), vector (>=0.12.0.1 && <0.13), websockets (>=0.12.5.1 && <0.13), wuss (>=1.1.10 && <1.2) [details]
License MIT
Copyright 2019 Karl
Author Karl
Maintainer ksfish5@gmail.com
Category Network
Home page https://github.com/aquarial/discord-haskell
Bug tracker https://github.com/aquarial/discord-haskell/issues
Source repo head: git clone https://github.com/aquarial/discord-haskell.git
Uploaded by Aquarial at 2019-07-22T05:57:26Z
Distributions NixOS:1.16.1
Reverse Dependencies 2 direct, 0 indirect [details]
Executables ping-pong
Downloads 18058 total (157 in the last 30 days)
Rating 2.5 (votes: 6) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-07-22 [all 1 reports]

Readme for discord-haskell-1.0.0

[back to package description]

discord-haskell Build Status

Go to the Wiki for more information

{-# LANGUAGE OverloadedStrings #-}  -- allows "string literals" to be Text

import Control.Monad (when)
import Data.Text (isPrefixOf, toLower, Text)
import Control.Concurrent (threadDelay)
import qualified Data.Text.IO as TIO

import Discord
import Discord.Types
import qualified Discord.Requests as R

-- | Replies "pong" to every message that starts with "ping"
pingpongExample :: IO ()
pingpongExample = do userFacingError <- runDiscord $ def
                                            { discordToken = "Bot ZZZZZZZZZZZZZZZZZZZ"
                                            , discordOnEvent = eventHandler }
                     TIO.putStrLn userFacingError

eventHandler :: DiscordHandle -> Event -> IO ()
eventHandler dis event = case event of
       MessageCreate m -> when (not (fromBot m) && isPing (messageText m)) $ do
               _ <- restCall dis (R.CreateReaction (messageChannel m, messageId m) "eyes")
               threadDelay (4 * 10^6)
               _ <- restCall dis (R.CreateMessage (messageChannel m) "Pong!")
               pure ()
       _ -> pure ()

fromBot :: Message -> Bool
fromBot m = userIsBot (messageAuthor m)

isPing :: Text -> Bool
isPing = ("ping" `isPrefixOf`) . toLower