diff options
| author | LLLL Colonq <llll@colonq> | 2023-11-16 19:06:43 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2023-11-16 19:06:43 -0500 |
| commit | dcef0b65069fb38fd0f6c4382353167f603ebff1 (patch) | |
| tree | 45954ffe308c3dd056e6af4f734e6d2af89e5856 /fig-monitor-twitch/main/Main.hs | |
Initial commit
Diffstat (limited to 'fig-monitor-twitch/main/Main.hs')
| -rw-r--r-- | fig-monitor-twitch/main/Main.hs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/fig-monitor-twitch/main/Main.hs b/fig-monitor-twitch/main/Main.hs new file mode 100644 index 0000000..2232a03 --- /dev/null +++ b/fig-monitor-twitch/main/Main.hs @@ -0,0 +1,45 @@ +module Main where + +import Fig.Prelude + +import Options.Applicative + +import Fig.Monitor.Twitch +import Fig.Monitor.Twitch.Utils + +data Command + = Monitor + | Chatbot + | RedirectServer + +parseCommand :: Parser Command +parseCommand = subparser $ mconcat + [ command "monitor" $ info (pure Monitor) (progDesc "Launch the Twitch monitor") + , command "chatbot" $ info (pure Chatbot) (progDesc "Launch the Twitch chatbot") + , command "user-token-server" $ info (pure RedirectServer) (progDesc "Launch a web server to handle authentication redirects") + ] +data Opts = Opts + { busHost :: Text + , busPort :: Text + , config :: FilePath + , command :: Command + } + +parseOpts :: Parser Opts +parseOpts = Opts + <$> strOption (long "bus-host" <> metavar "HOST" <> help "Address of message bus" <> value "localhost") + <*> strOption (long "bus-port" <> metavar "PORT" <> help "Message bus port" <> showDefault <> value "32050") + <*> strOption (long "config" <> metavar "PATH" <> help "Path to config file" <> showDefault <> value "fig-monitor-twitch.toml") + <*> parseCommand + +main :: IO () +main = do + opts <- execParser $ info (parseOpts <**> helper) + ( fullDesc + <> header "fig-monitor-twitch - monitor Twitch.tv stream events" + ) + cfg <- loadConfig opts.config + case opts.command of + Monitor -> twitchEventClient cfg (opts.busHost, opts.busPort) + Chatbot -> twitchChatClient cfg (opts.busHost, opts.busPort) + RedirectServer -> userTokenRedirectServer cfg |
