diff --git a/.gitignore b/.gitignore index 7296f36..03c8b5e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore config.json +launchSettings.json # User-specific files *.rsuser diff --git a/Bot_Discord_CSharp/Bot.cs b/Bot_Discord_CSharp/Bot.cs index 605aa32..f6c8eba 100644 --- a/Bot_Discord_CSharp/Bot.cs +++ b/Bot_Discord_CSharp/Bot.cs @@ -1,18 +1,16 @@ using DSharpPlus; using DSharpPlus.CommandsNext; using DSharpPlus.EventArgs; -using Newtonsoft.Json; using System; -using System.Collections.Generic; -using System.IO; -using System.Text; using System.Threading.Tasks; -using Bot_Discord_CSharp.Dto; using Bot_Discord_CSharp.Commands; using Microsoft.Extensions.Logging; using DSharpPlus.Interactivity; using DSharpPlus.Interactivity.Extensions; using DSharpPlus.Entities; +using Microsoft.Extensions.Configuration; +using Newtonsoft.Json; +using Bot_Discord_CSharp.Dto; namespace Bot_Discord_CSharp { @@ -25,22 +23,18 @@ namespace Bot_Discord_CSharp public async Task RunAsync() { string token, prefix; - if (!Environment.GetEnvironmentVariables().Contains("TOKEN")) - { - var json = string.Empty; - - using (var fs = File.OpenRead(@"E:\Proyectos Visual Studio\Bot_Discord_CSharp\Bot_Discord_CSharp\config.json")) - using (var sr = new StreamReader(fs, new UTF8Encoding(false))) - json = await sr.ReadToEndAsync().ConfigureAwait(false); - - var configJson = JsonConvert.DeserializeObject(json); - token = configJson.Token; - prefix = configJson.Prefix; - } - else + if (Environment.GetEnvironmentVariable("TOKEN") != null) { token = Environment.GetEnvironmentVariable("TOKEN"); prefix = Environment.GetEnvironmentVariable("PREFIX"); + Console.WriteLine(0); + } else + { + ProfilesDto profiles = JsonConvert.DeserializeObject(System.IO.File.ReadAllText("./launchSettings.json")); + SecretsDto secrets = profiles.Bot_Discord_CSharp.EnvironmentVariables.Secrets; + token = secrets.Token; + prefix = secrets.Prefix; + Console.WriteLine(System.IO.File.ReadAllText("./launchSettings.json")); } var config = new DiscordConfiguration diff --git a/Bot_Discord_CSharp/Bot_Discord_CSharp.csproj b/Bot_Discord_CSharp/Bot_Discord_CSharp.csproj index e0d6185..7931638 100644 --- a/Bot_Discord_CSharp/Bot_Discord_CSharp.csproj +++ b/Bot_Discord_CSharp/Bot_Discord_CSharp.csproj @@ -1,4 +1,4 @@ - + Exe @@ -6,14 +6,18 @@ - - - + + + - + + + + + diff --git a/Bot_Discord_CSharp/Dockerfile.txt b/Bot_Discord_CSharp/Dockerfile similarity index 91% rename from Bot_Discord_CSharp/Dockerfile.txt rename to Bot_Discord_CSharp/Dockerfile index c53d659..fe8c97b 100644 --- a/Bot_Discord_CSharp/Dockerfile.txt +++ b/Bot_Discord_CSharp/Dockerfile @@ -15,4 +15,6 @@ WORKDIR /app COPY --from=build-env /app/out . #COPY config.json ./ +COPY Properties/launchSettings.json ./ + ENTRYPOINT ["dotnet", "Bot_Discord_CSharp.dll"] \ No newline at end of file diff --git a/Bot_Discord_CSharp/Dto/ConfigDto.cs b/Bot_Discord_CSharp/Dto/ConfigDto.cs index 9913bb7..d94445f 100644 --- a/Bot_Discord_CSharp/Dto/ConfigDto.cs +++ b/Bot_Discord_CSharp/Dto/ConfigDto.cs @@ -5,11 +5,29 @@ using System.Text; namespace Bot_Discord_CSharp.Dto { - class ConfigDto + class ProfilesDto { - [JsonProperty("token")] + [JsonProperty("profiles")] + public Bot_Discord_CSharpDto Bot_Discord_CSharp { get; private set; } +} + + class Bot_Discord_CSharpDto + { + [JsonProperty("Bot_Discord_CSharp")] + public EnvironmentVariablesDto EnvironmentVariables { get; private set; } + } + + class EnvironmentVariablesDto + { + [JsonProperty("environmentVariables")] + public SecretsDto Secrets { get; private set; } + } + + class SecretsDto + { + [JsonProperty("TOKEN")] public string Token { get; private set; } - [JsonProperty("Prefix")] + [JsonProperty("PREFIX")] public string Prefix { get; private set; } } } diff --git a/Bot_Discord_CSharp/Program.cs b/Bot_Discord_CSharp/Program.cs index f2b65ca..7b4b4b1 100644 --- a/Bot_Discord_CSharp/Program.cs +++ b/Bot_Discord_CSharp/Program.cs @@ -1,8 +1,4 @@ -using Microsoft.AspNetCore.Hosting; -using System; -using System.IO; - -namespace Bot_Discord_CSharp +namespace Bot_Discord_CSharp { class Program { diff --git a/Bot_Discord_CSharp/docker-compose.yml b/Bot_Discord_CSharp/docker-compose.yml index 7953ab9..765b6af 100644 --- a/Bot_Discord_CSharp/docker-compose.yml +++ b/Bot_Discord_CSharp/docker-compose.yml @@ -1,5 +1,8 @@ version: "3" + services: bot: build: . - image: mydiscordbot \ No newline at end of file + image: mydiscordbot + + \ No newline at end of file