|
|
@ -26,7 +26,10 @@ import Discord.Interactions ( interactionResponseBasic |
|
|
|
import qualified Discord.Requests as R |
|
|
|
import Commands ( edtResponse, edtCommand |
|
|
|
, pingResponse, pingCommand |
|
|
|
, remindResponse, remindCommand, groupCommand, groupResponse |
|
|
|
, remindResponse, remindCommand |
|
|
|
, groupCommand, groupResponse |
|
|
|
, helpCommand, helpResponse |
|
|
|
, Remind(..) |
|
|
|
) |
|
|
|
import Conf ( Config(..), Group(..), readConfig ) |
|
|
|
import qualified System.Cron.Schedule as Cron |
|
|
@ -34,16 +37,17 @@ import qualified Data.Map.Strict as Map |
|
|
|
import Commands.EDT (getEdt) |
|
|
|
import qualified Control.Concurrent |
|
|
|
import qualified Control.Event as E |
|
|
|
|
|
|
|
import UnliftIO.Directory (doesFileExist, removeFile) |
|
|
|
|
|
|
|
main :: IO () |
|
|
|
main = do |
|
|
|
tok <- TIO.readFile "./auth.secret" |
|
|
|
conf <- readConfig "./conf.yaml" |
|
|
|
eventSystem <- E.initEventSystem |
|
|
|
print conf |
|
|
|
|
|
|
|
|
|
|
|
err <- runDiscord $ def { discordToken = tok |
|
|
|
, discordOnStart = onDiscordStart conf |
|
|
|
, discordOnStart = onDiscordStart conf eventSystem |
|
|
|
, discordOnEnd = liftIO $ putStrLn "Ended" |
|
|
|
, discordOnEvent = onDiscordEvent conf eventSystem |
|
|
|
, discordOnLog = |
|
|
@ -51,8 +55,8 @@ main = do |
|
|
|
} |
|
|
|
TIO.putStrLn err |
|
|
|
|
|
|
|
onDiscordStart :: Config -> DiscordHandler () |
|
|
|
onDiscordStart conf = do |
|
|
|
onDiscordStart :: Config -> E.EventSystem -> DiscordHandler () |
|
|
|
onDiscordStart conf eventSystem = do |
|
|
|
let |
|
|
|
activity :: Activity |
|
|
|
activity = def { activityName = "Doing stuff" |
|
|
@ -66,6 +70,26 @@ onDiscordStart conf = do |
|
|
|
, updateStatusOptsAFK = False |
|
|
|
} |
|
|
|
sendCommand (UpdateStatus opts) |
|
|
|
remindDataExist <- liftIO $ doesFileExist "reminds.data" |
|
|
|
when remindDataExist $ do |
|
|
|
remindfile <- liftIO $ readFile "reminds.data" |
|
|
|
let reminddata :: [Remind] |
|
|
|
reminddata = map read $ lines remindfile |
|
|
|
mapM_ (\r -> do |
|
|
|
withRunInIO $ \runInIO -> |
|
|
|
E.addEvent eventSystem (rmdWhen r) |
|
|
|
( do |
|
|
|
runInIO ( restCall |
|
|
|
$ R.CreateMessage (rmdWhere r) |
|
|
|
$ "<@" |
|
|
|
`T.append` T.pack (show $rmdWho r) |
|
|
|
`T.append` "> **Reminder**\n" |
|
|
|
`T.append` rmdWhat r |
|
|
|
) |
|
|
|
return () |
|
|
|
) |
|
|
|
) reminddata |
|
|
|
liftIO $ removeFile "reminds.data" |
|
|
|
|
|
|
|
|
|
|
|
onDiscordEvent :: Config -> E.EventSystem -> Event -> DiscordHandler () |
|
|
@ -80,6 +104,7 @@ onDiscordEvent conf@Config{..} eventSystem (Ready _ _ _ _ _ _ (PartialApplicatio |
|
|
|
, edtCommand conf |
|
|
|
, remindCommand |
|
|
|
, groupCommand conf |
|
|
|
, helpCommand |
|
|
|
] |
|
|
|
let glist = Map.toList configGroups |
|
|
|
withRunInIO $ \runInIO -> Cron.execSchedule $ do |
|
|
@ -113,6 +138,7 @@ onDiscordEvent conf@Config{..} eventSystem |
|
|
|
"edt" -> liftIO $ edtResponse conf opts |
|
|
|
"remind" -> remindResponse opts eventSystem channel user |
|
|
|
"group" -> groupResponse conf user guild opts |
|
|
|
"help" -> liftIO helpResponse |
|
|
|
_ -> return $ interactionResponseBasic $ "Unhandled Command: " `T.append` name |
|
|
|
onDiscordEvent _ _ _ = return () |
|
|
|
|
|
|
|