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.
75 lines
2.7 KiB
75 lines
2.7 KiB
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# LANGUAGE RecordWildCards #-}
|
|
|
|
module Main where
|
|
|
|
import Control.Monad (when, void)
|
|
import qualified Data.Text as T
|
|
import qualified Data.Text.IO as TIO
|
|
import UnliftIO (liftIO)
|
|
import Discord
|
|
import Discord.Types
|
|
import Discord.Interactions
|
|
import qualified Discord.Requests as R
|
|
import Commands
|
|
import Discord.Internal.Rest.Guild (ModifyGuildOpts(modifyGuildOptsIcon))
|
|
import UnliftIO.Directory (renameDirectory)
|
|
|
|
testServer :: Snowflake
|
|
testServer = 740862954454646814
|
|
|
|
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 = do
|
|
let activity = Activity { activityName = "Doing stuff"
|
|
, activityType = ActivityTypeGame
|
|
, activityUrl = Nothing
|
|
}
|
|
let opts = UpdateStatusOpts { updateStatusOptsSince = Nothing
|
|
, updateStatusOptsGame = Just activity
|
|
, updateStatusOptsNewStatus = UpdateStatusOnline
|
|
, updateStatusOptsAFK = False
|
|
}
|
|
sendCommand (UpdateStatus opts)
|
|
|
|
|
|
onDiscordEvent :: Event -> DiscordHandler ()
|
|
onDiscordEvent (Ready _ _ _ _ _ _ (PartialApplication i _)) =
|
|
mapM_ (maybe ( return () )
|
|
( void
|
|
. restCall
|
|
. R.CreateGuildApplicationCommand i testServer
|
|
)
|
|
)
|
|
[ Just pingCommand
|
|
, Just edtCommand
|
|
]
|
|
onDiscordEvent ( InteractionCreate InteractionApplicationCommand
|
|
{ interactionDataApplicationCommand =
|
|
Just InteractionDataApplicationCommandChatInput
|
|
{ interactionDataApplicationCommandName = name
|
|
, interactionDataApplicationCommandOptions = opts
|
|
, ..
|
|
}
|
|
, ..
|
|
}
|
|
) = do
|
|
void $ restCall
|
|
(R.CreateInteractionResponse interactionId interactionToken response)
|
|
where
|
|
response = case name of
|
|
"ping" -> pingResponse
|
|
_ -> interactionResponseBasic $ "Unhandled Command: " `T.append` name
|
|
onDiscordEvent _ = return ()
|
|
|