You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestConfig.cs 913 B

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
123456789101112131415161718192021222324252627
  1. using System;
  2. using System.IO;
  3. using Newtonsoft.Json;
  4. namespace Discord
  5. {
  6. internal class TestConfig
  7. {
  8. [JsonProperty("token")] public string Token { get; private set; }
  9. [JsonProperty("guild_id")] public ulong GuildId { get; private set; }
  10. public static TestConfig LoadFile(string path)
  11. {
  12. if (!File.Exists(path))
  13. return new TestConfig
  14. {
  15. Token = Environment.GetEnvironmentVariable("DNET_TEST_TOKEN"),
  16. GuildId = ulong.Parse(Environment.GetEnvironmentVariable("DNET_TEST_GUILDID"))
  17. };
  18. using (var stream = new FileStream(path, FileMode.Open))
  19. using (var reader = new StreamReader(stream))
  20. using (var jsonReader = new JsonTextReader(reader))
  21. return new JsonSerializer().Deserialize<TestConfig>(jsonReader);
  22. }
  23. }
  24. }