{-# LANGUAGE OverloadedStrings #-} module Main where import Control.Monad import qualified Data.Text as T import qualified Data.Text.IO as TIO import UnliftIO (liftIO) import Discord import Discord.Types import qualified Discord.Requests as R cmdPrefix :: T.Text cmdPrefix = "%" main :: IO () main = do tok <- TIO.readFile "./auth.secret" err <- runDiscord $ def { discordToken = tok , discordOnStart = onDiscordStart , discordOnEnd = liftIO $ putStrLn "Ended" , discordOnEvent = onDiscordEvent , discordOnLog = \s -> TIO.putStrLn s >> TIO.putStrLn "" } TIO.putStrLn err onDiscordStart :: DiscordHandler () onDiscordStart = undefined onDiscordEvent :: Event -> DiscordHandler () onDiscordEvent (MessageCreate m) = when (not (fromBot m) && isCommand m) $ do let content = messageContent m let elements = T.words content case head elements of _ -> unknownCommand m elements return () onDiscordEvent _ = return () fromBot :: Message -> Bool fromBot = userIsBot . messageAuthor unknownCommand :: Message -> [Text] -> DiscordHandler () unknownCommand = isCommand :: Message ->Bool isCommand = (cmdPrefix `T.isPrefixOf`) . messageContent