You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
{-# 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
|