Browse Source

Did more work

master
Antoine COMBET 3 years ago
parent
commit
b7565417cf
  1. 1
      .gitignore
  2. 4
      README.org
  3. 25
      app/Commands.hs
  4. 0
      app/Commands.hsCommands.hs
  5. 5
      app/Commands/EDT.hs
  6. 25
      app/Main.hs
  7. 7
      botiut.cabal

1
.gitignore

@ -4,3 +4,4 @@ dist-newstyle
*.secret *.secret
*# *#
.#* .#*
conf.yaml

4
README.org

@ -1,8 +1,8 @@
#+title: botiut #+title: botiut
#+author: Annwan #+author: Annwan
** TODO List [0/3]
- [ ] Framework
** TODO List [1/3]
- [X] Framework
- [ ] Time table [0/2] - [ ] Time table [0/2]
- [ ] =edt= command - [ ] =edt= command
- [ ] Messages in channel - [ ] Messages in channel

25
app/Commands.hs

@ -1,12 +1,16 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Commands where module Commands where
import Discord import Discord
import Discord.Types import Discord.Types
import Discord.Interactions import Discord.Interactions
import qualified Discord.Requests as R import qualified Discord.Requests as R
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.Map.Strict as Map
import Commands.EDT
pingCommand :: CreateApplicationCommand pingCommand :: CreateApplicationCommand
pingCommand = pingCommand =
@ -38,3 +42,22 @@ edtCommand = CreateApplicationCommand
]) ])
Nothing Nothing
Nothing Nothing
edtResponse :: Maybe InteractionDataApplicationCommandOptions -> InteractionResponse
edtResponse (Just (InteractionDataApplicationCommandOptionsValues opts)) =
interactionResponseBasic $
"You gave:\n```hs\n" `T.append` T.pack (show parsedOpts) `T.append` "\n```"
where
parsedOpts :: Map.Map T.Text T.Text
parsedOpts = Map.fromList $ map parseOpt opts
parseOpt :: InteractionDataApplicationCommandOptionValue -> (T.Text, T.Text)
parseOpt (InteractionDataApplicationCommandOptionValue
{ interactionDataApplicationCommandOptionValueName = name
, interactionDataApplicationCommandOptionValueValue =
ApplicationCommandInteractionDataValueString val
, ..}
) = (name, val)
parseOpt _ = ("INVALID FORMAT", "INVALID FORMAT")
edtResponse _ = interactionResponseBasic
"The edt command should have params yet you managed not to give any: wow"

0
app/Commands.hsCommands.hs

5
app/Commands/EDT.hs

@ -0,0 +1,5 @@
module Commands.EDT where
import qualified Data.Map.Strict as Map
import qualified Text.ICalendar.Parser as IP
import qualified Text.ICalendar.Types as IT

25
app/Main.hs

@ -12,8 +12,9 @@ import Discord.Types
import Discord.Interactions import Discord.Interactions
import qualified Discord.Requests as R import qualified Discord.Requests as R
import Commands import Commands
import Discord.Internal.Rest.Guild (ModifyGuildOpts(modifyGuildOptsIcon))
import UnliftIO.Directory (renameDirectory)
import qualified Data.ByteString as BS
import qualified Data.Yaml as YAML
import qualified Data.HashMap.Strict as Map
testServer :: Snowflake testServer :: Snowflake
testServer = 740862954454646814 testServer = 740862954454646814
@ -21,17 +22,19 @@ testServer = 740862954454646814
main :: IO () main :: IO ()
main = do main = do
tok <- TIO.readFile "./auth.secret" tok <- TIO.readFile "./auth.secret"
conf <- YAML.decodeFileThrow "./conf.yaml" :: IO YAML.Value
putStrLn $ show conf
err <- runDiscord $ def { discordToken = tok err <- runDiscord $ def { discordToken = tok
, discordOnStart = onDiscordStart
, discordOnStart = onDiscordStart conf
, discordOnEnd = liftIO $ putStrLn "Ended" , discordOnEnd = liftIO $ putStrLn "Ended"
, discordOnEvent = onDiscordEvent
, discordOnEvent = onDiscordEvent conf
, discordOnLog = , discordOnLog =
\s -> TIO.putStrLn s >> TIO.putStrLn "" \s -> TIO.putStrLn s >> TIO.putStrLn ""
} }
TIO.putStrLn err TIO.putStrLn err
onDiscordStart :: DiscordHandler ()
onDiscordStart = do
onDiscordStart :: YAML.Value -> DiscordHandler ()
onDiscordStart conf = do
let activity = Activity { activityName = "Doing stuff" let activity = Activity { activityName = "Doing stuff"
, activityType = ActivityTypeGame , activityType = ActivityTypeGame
, activityUrl = Nothing , activityUrl = Nothing
@ -44,8 +47,8 @@ onDiscordStart = do
sendCommand (UpdateStatus opts) sendCommand (UpdateStatus opts)
onDiscordEvent :: Event -> DiscordHandler ()
onDiscordEvent (Ready _ _ _ _ _ _ (PartialApplication i _)) =
onDiscordEvent :: YAML.Value -> Event -> DiscordHandler ()
onDiscordEvent conf (Ready _ _ _ _ _ _ (PartialApplication i _)) =
mapM_ (maybe ( return () ) mapM_ (maybe ( return () )
( void ( void
. restCall . restCall
@ -55,7 +58,8 @@ onDiscordEvent (Ready _ _ _ _ _ _ (PartialApplication i _)) =
[ Just pingCommand [ Just pingCommand
, Just edtCommand , Just edtCommand
] ]
onDiscordEvent ( InteractionCreate InteractionApplicationCommand
onDiscordEvent conf
( InteractionCreate InteractionApplicationCommand
{ interactionDataApplicationCommand = { interactionDataApplicationCommand =
Just InteractionDataApplicationCommandChatInput Just InteractionDataApplicationCommandChatInput
{ interactionDataApplicationCommandName = name { interactionDataApplicationCommandName = name
@ -70,6 +74,7 @@ onDiscordEvent ( InteractionCreate InteractionApplicationCommand
where where
response = case name of response = case name of
"ping" -> pingResponse "ping" -> pingResponse
"edt" -> edtResponse opts
_ -> interactionResponseBasic $ "Unhandled Command: " `T.append` name _ -> interactionResponseBasic $ "Unhandled Command: " `T.append` name
onDiscordEvent _ = return ()
onDiscordEvent _ _ = return ()

7
botiut.cabal

@ -25,7 +25,8 @@ executable botiut
-- Modules included in this executable, other than Main. -- Modules included in this executable, other than Main.
other-modules: other-modules:
Commands
Commands
, Commands.EDT
-- LANGUAGE extensions used by modules in this package. -- LANGUAGE extensions used by modules in this package.
-- other-extensions: -- other-extensions:
@ -35,6 +36,10 @@ executable botiut
, control-event , control-event
, text , text
, unliftio , unliftio
, containers
, unordered-containers
, iCalendar , iCalendar
, bytestring
, yaml
hs-source-dirs: app hs-source-dirs: app
default-language: Haskell2010 default-language: Haskell2010
Loading…
Cancel
Save