blob: 682d35b48b34d749e8ad6a0c55bff6eeef5e821d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
module Main where
import Fig.Prelude
import Options.Applicative
import Fig.Monitor.Twitch
import Fig.Monitor.Twitch.Utils
data Command
= Monitor
| Chatbot
| LiveChecker
| RedirectServer !Bool
| Validate
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 "live-checker" $ info (pure LiveChecker) (progDesc "Launch the Twitch live status checker")
, command "user-token-server" $ info (pure $ RedirectServer True) (progDesc "Launch a web server to handle authentication redirects")
, command "user-token-server-read-only" $ info (pure $ RedirectServer False) (progDesc "Launch a web server to handle authentication redirects")
, command "validate-endpoint" $ info (pure Validate) (progDesc "Test Twitch authentication")
]
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)
LiveChecker -> twitchChannelLiveMonitor cfg (opts.busHost, opts.busPort)
RedirectServer rw -> userTokenRedirectServer cfg rw
Validate -> twitchEndpointTest cfg
|