|
|
@ -25,15 +25,16 @@ import Data.Time ( addUTCTime |
|
|
|
import Discord ( DiscordHandler |
|
|
|
, restCall |
|
|
|
) |
|
|
|
import Discord.Interactions ( ApplicationCommandOptionValue(..) |
|
|
|
, ApplicationCommandOptions(..) |
|
|
|
import Discord.Interactions ( OptionValue(..) |
|
|
|
, Options(..) |
|
|
|
, Choice(..) |
|
|
|
, CreateApplicationCommand(..) |
|
|
|
, InteractionDataApplicationCommandOptionValue(..) |
|
|
|
, InteractionDataApplicationCommandOptions(..) |
|
|
|
, OptionDataValue(..) |
|
|
|
, OptionsData(..) |
|
|
|
, InteractionResponse |
|
|
|
, MemberOrUser(..) |
|
|
|
, createApplicationCommandChatInput |
|
|
|
, LocalizedText(..) |
|
|
|
, createChatInput |
|
|
|
, interactionResponseBasic |
|
|
|
) |
|
|
|
import Discord.Requests ( ChannelRequest(..) |
|
|
@ -45,6 +46,8 @@ import Discord.Types ( ChannelId |
|
|
|
, Snowflake |
|
|
|
, UTCTime |
|
|
|
, User(..) |
|
|
|
, RoleId(..) |
|
|
|
, DiscordId, |
|
|
|
) |
|
|
|
import UnliftIO ( withRunInIO ) |
|
|
|
|
|
|
@ -52,42 +55,46 @@ groupNames :: Config -> [T.Text] |
|
|
|
groupNames Config {..} = map fst $ Map.toList configGroups |
|
|
|
|
|
|
|
pingCommand :: Maybe CreateApplicationCommand |
|
|
|
pingCommand = createApplicationCommandChatInput "ping" "pong" |
|
|
|
pingCommand = createChatInput "ping" "pong" |
|
|
|
|
|
|
|
pingResponse :: Config -> IO InteractionResponse |
|
|
|
pingResponse _ = return $ interactionResponseBasic "Pong" |
|
|
|
|
|
|
|
edtCommand :: Config -> Maybe CreateApplicationCommand |
|
|
|
edtCommand c = |
|
|
|
createApplicationCommandChatInput "edt" "Gets the planning for a group" |
|
|
|
createChatInput "edt" "Gets the planning for a group" |
|
|
|
>>= \cac -> return $ cac |
|
|
|
{ createApplicationCommandOptions = |
|
|
|
Just $ ApplicationCommandOptionsValues |
|
|
|
[ ApplicationCommandOptionValueString |
|
|
|
{ createOptions = |
|
|
|
Just $ OptionsValues |
|
|
|
[ OptionValueString |
|
|
|
"group" |
|
|
|
Nothing |
|
|
|
"The group for which the planning is requested" |
|
|
|
Nothing |
|
|
|
True |
|
|
|
(Right $ map (\x -> Choice x x) $ groupNames c) |
|
|
|
, ApplicationCommandOptionValueString |
|
|
|
(Right $ map (\x -> Choice x Nothing x) $ groupNames c) |
|
|
|
Nothing Nothing |
|
|
|
, OptionValueString |
|
|
|
"day" |
|
|
|
( "The day(s) for which the planning is requested " |
|
|
|
`T.append` "(today, tomorrow, week or DD/MM/YYYY)" |
|
|
|
) |
|
|
|
Nothing |
|
|
|
"The day(s) for which the planning is requested (today, tomorrow, week or DD/MM/YYYY)" |
|
|
|
Nothing |
|
|
|
False |
|
|
|
(Left False) |
|
|
|
Nothing Nothing |
|
|
|
] |
|
|
|
} |
|
|
|
|
|
|
|
parseOpt :: InteractionDataApplicationCommandOptionValue -> (T.Text, T.Text) |
|
|
|
parseOpt InteractionDataApplicationCommandOptionValueString { interactionDataApplicationCommandOptionValueName = name, interactionDataApplicationCommandOptionValueStringValue = Right val, ..} |
|
|
|
parseOpt :: OptionDataValue -> (T.Text, T.Text) |
|
|
|
parseOpt OptionDataValueString { optionDataValueName = name, optionDataValueString = Right val, ..} |
|
|
|
= (name, val) |
|
|
|
parseOpt _ = ("INVALID Option", "INVALID type") |
|
|
|
|
|
|
|
edtResponse |
|
|
|
:: Config |
|
|
|
-> Maybe InteractionDataApplicationCommandOptions |
|
|
|
-> Maybe OptionsData |
|
|
|
-> IO InteractionResponse |
|
|
|
edtResponse conf@Config {..} (Just (InteractionDataApplicationCommandOptionsValues opts)) |
|
|
|
edtResponse conf@Config {..} (Just (OptionsDataValues opts)) |
|
|
|
= do |
|
|
|
planning <- getEdt conf parsedOpts |
|
|
|
return $ interactionResponseBasic planning |
|
|
@ -99,34 +106,28 @@ edtResponse _ _ = return $ interactionResponseBasic |
|
|
|
|
|
|
|
remindCommand :: Maybe CreateApplicationCommand |
|
|
|
remindCommand = |
|
|
|
createApplicationCommandChatInput "remind" "reminds you of something later on" |
|
|
|
createChatInput "remind" "reminds you of something later on" |
|
|
|
>>= \cac -> return $ cac |
|
|
|
{ createApplicationCommandOptions = |
|
|
|
Just $ ApplicationCommandOptionsValues |
|
|
|
[ ApplicationCommandOptionValueString "delay" |
|
|
|
"delay" |
|
|
|
True |
|
|
|
(Left False) |
|
|
|
, ApplicationCommandOptionValueString "message" |
|
|
|
"message" |
|
|
|
True |
|
|
|
(Left False) |
|
|
|
{ createOptions = |
|
|
|
Just $ OptionsValues |
|
|
|
[ OptionValueString "delay" Nothing "delay" Nothing True (Left False) Nothing Nothing |
|
|
|
, OptionValueString "message" Nothing "message" Nothing True (Left False) Nothing Nothing |
|
|
|
] |
|
|
|
} |
|
|
|
|
|
|
|
remindResponse |
|
|
|
:: Maybe InteractionDataApplicationCommandOptions |
|
|
|
:: Maybe OptionsData |
|
|
|
-> EventSystem |
|
|
|
-> ChannelId |
|
|
|
-> Discord.Types.ChannelId |
|
|
|
-> MemberOrUser |
|
|
|
-> DiscordHandler InteractionResponse |
|
|
|
remindResponse (Just (InteractionDataApplicationCommandOptionsValues opts)) evts ch mou |
|
|
|
remindResponse (Just (OptionsDataValues opts)) evts ch mou |
|
|
|
= do |
|
|
|
let |
|
|
|
userid = case mou of |
|
|
|
MemberOrUser (Left GuildMember { memberUser = Just User { userId = uid } }) |
|
|
|
MemberOrUser (Left Discord.Types.GuildMember { memberUser = Just Discord.Types.User { userId = uid } }) |
|
|
|
-> uid |
|
|
|
MemberOrUser (Right User { userId = uid }) -> uid |
|
|
|
MemberOrUser (Right Discord.Types.User { userId = uid }) -> uid |
|
|
|
_ -> error "Couldnt get user id" |
|
|
|
let d = delay' |
|
|
|
now <- liftIO getCurrentTime |
|
|
@ -166,30 +167,31 @@ remindResponse _ _ _ _ = |
|
|
|
|
|
|
|
groupCommand :: Config -> Maybe CreateApplicationCommand |
|
|
|
groupCommand c = |
|
|
|
createApplicationCommandChatInput "group" "grab your group" >>= \cac -> |
|
|
|
createChatInput "group" "grab your group" >>= \cac -> |
|
|
|
return $ cac |
|
|
|
{ createApplicationCommandOptions = Just $ ApplicationCommandOptionsValues |
|
|
|
[ ApplicationCommandOptionValueString |
|
|
|
"group" |
|
|
|
"Your group" |
|
|
|
{ createOptions = Just $ OptionsValues |
|
|
|
[ OptionValueString |
|
|
|
"group" Nothing |
|
|
|
"Your group" Nothing |
|
|
|
True |
|
|
|
(Right $ map (\x -> Choice x x) $ groupNames c) |
|
|
|
(Right $ map (\x -> Choice x Nothing x) $ groupNames c) |
|
|
|
Nothing Nothing |
|
|
|
] |
|
|
|
} |
|
|
|
|
|
|
|
groupResponse |
|
|
|
:: Config |
|
|
|
-> MemberOrUser |
|
|
|
-> GuildId |
|
|
|
-> Maybe InteractionDataApplicationCommandOptions |
|
|
|
-> Discord.Types.GuildId |
|
|
|
-> Maybe OptionsData |
|
|
|
-> DiscordHandler InteractionResponse |
|
|
|
groupResponse c mou gid (Just (InteractionDataApplicationCommandOptionsValues opts)) |
|
|
|
groupResponse c mou gid (Just (OptionsDataValues opts)) |
|
|
|
= do |
|
|
|
let |
|
|
|
uid = case mou of |
|
|
|
MemberOrUser (Left GuildMember { memberUser = Just User { userId = uid } }) |
|
|
|
MemberOrUser (Left Discord.Types.GuildMember { memberUser = Just Discord.Types.User { userId = uid } }) |
|
|
|
-> uid |
|
|
|
MemberOrUser (Right User { userId = uid }) -> uid |
|
|
|
MemberOrUser (Right Discord.Types.User { userId = uid }) -> uid |
|
|
|
_ -> -1 |
|
|
|
let rid = |
|
|
|
groupRole |
|
|
@ -213,7 +215,7 @@ groupResponse _ _ _ _ = |
|
|
|
"the group command has mandatory params, yet you managed not to give any, WOW" |
|
|
|
|
|
|
|
helpCommand :: Maybe CreateApplicationCommand |
|
|
|
helpCommand = createApplicationCommandChatInput "help" "help" |
|
|
|
helpCommand = createChatInput "help" "help" |
|
|
|
|
|
|
|
helpResponse :: IO InteractionResponse |
|
|
|
helpResponse = |
|
|
|