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