2023-02-07 21:55:46 +03:00
|
|
|
module PublishHelperBot.Environment
|
|
|
|
|
|
|
|
open System
|
|
|
|
open System.IO
|
2023-02-27 22:31:40 +03:00
|
|
|
open System.Text.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
|
2023-02-27 23:03:31 +03:00
|
|
|
youtubeDlUrl: string
|
2023-03-07 01:08:26 +03:00
|
|
|
tmpYtdlSavePath: string Option
|
2023-02-07 21:55:46 +03:00
|
|
|
}
|
|
|
|
|
2023-02-25 00:04:13 +03:00
|
|
|
let private readConfig =
|
2023-02-27 22:31:40 +03:00
|
|
|
File.ReadAllText >> JsonSerializer.Deserialize<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
|