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 1.0 KiB

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