publishhelperbot/PublishHelperBot/Environment.fs

32 lines
803 B
Forth
Raw Normal View History

2023-02-07 21:55:46 +03:00
module PublishHelperBot.Environment
open System
open System.IO
open Newtonsoft.Json
2023-02-25 00:04:13 +03:00
open Serilog
[<RequireQualifiedAccess>]
module Logging =
let logger =
let config = LoggerConfiguration()
config.WriteTo.Console().CreateLogger()
2023-02-07 21:55:46 +03:00
type public BotConfig = {
2023-02-25 00:04:13 +03:00
token: string
relayUrl: string
chanelId: int64
adminChatId: int64
YoutubeDlUrl: string
2023-02-07 21:55:46 +03:00
}
2023-02-25 00:04:13 +03:00
let private readConfig =
File.ReadAllText >> JsonConvert.DeserializeObject<BotConfig>
2023-02-07 21:55:46 +03:00
2023-02-25 00:04:13 +03:00
let public createConfig (name: string) =
match Environment.GetEnvironmentVariable(name) with
| null ->
Logging.logger.Error("Missing env")
ApplicationException("Missing config path env") |> raise
| path ->
Logging.logger.Information("Read config from env")
readConfig path