Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.
/ Discord.hs Public archive

Have you heard of our lord and savior Haskell?

License

Notifications You must be signed in to change notification settings

TiltMeSenpai/Discord.hs

Repository files navigation

Discord.hs

A Haskell wrapper for the Discord API

Hackage Hackage-Deps Travis

Using in a project

The preferred (and only supported) method of using discord.hs is through stack. Open your stack.yaml and find the extra-deps section. Add the following:

extra-deps:
  - discord-hs-0.2.1

Then open your project.cabal file and add discord-hs to your build-depends.

Alternatively, you can add discord-hs to your project.cabal file, and run stack solver --update-config. This will let stack catch other missing dependencies in your project and is most likely the better option.

PingPong

{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
import Data.Text
import Pipes

import Network.Discord

reply :: Message -> Text -> Effect DiscordM ()
reply Message{messageChannel=chan} cont = fetch' $ CreateMessage chan cont Nothing

main :: IO ()
main = runBot (Bot "TOKEN") $ do
  with ReadyEvent $ \(Init v u _ _ _) ->
    liftIO . putStrLn $ "Connected to gateway v" ++ show v ++ " as user " ++ show u

  with MessageCreateEvent $ \msg@Message{..} -> do
    when ("Ping" `isPrefixOf` messageContent && (not . userIsBot $ messageAuthor)) $
      reply msg "Pong!"

Known issues:

  • Init isn't parsing correctly
  • Client doesn't close correctly
  • Missing voice support

Future goals:

  • Eta compatibility
  • HaLVM compatibility (maybe)
  • Command framework (Posibly through compat layer with marvin?)
  • Ditch wreq (not included in stack lts-8.2)
  • Upload to stackage

About

Have you heard of our lord and savior Haskell?

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published