From 2178ff54b64c4897eb54cb9dd64c331a7fb83999 Mon Sep 17 00:00:00 2001 From: Sarah Faey Date: Tue, 22 Nov 2022 22:38:32 +0100 Subject: [PATCH] discord token is now in token file --- .gitignore | 4 +++ .../Controllers/WeatherForecastController.cs | 33 ------------------- DiscordBot/Program.cs | 26 +++++---------- DiscordBot/WeatherForecast.cs | 13 -------- 4 files changed, 12 insertions(+), 64 deletions(-) delete mode 100644 DiscordBot/Controllers/WeatherForecastController.cs delete mode 100644 DiscordBot/WeatherForecast.cs diff --git a/.gitignore b/.gitignore index 9bde008..4a75bf1 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,10 @@ mono_crash.* # Sqlite Database Database/ +# Discord Tokens +DiscordBot/token.txt +DiscordBot/debugtoken.txt + # Build results [Dd]ebug/ [Dd]ebugPublic/ diff --git a/DiscordBot/Controllers/WeatherForecastController.cs b/DiscordBot/Controllers/WeatherForecastController.cs deleted file mode 100644 index 8ca320e..0000000 --- a/DiscordBot/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace DiscordBot.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} \ No newline at end of file diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index 5ebc323..4fcc030 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -79,16 +79,11 @@ namespace DiscordBot _client.Log += Log; _client.Ready += Client_Ready; - // You can assign your bot token to a string, and pass that in to connect. - // This is, however, insecure, particularly if you plan to have your code hosted in a public repository. - var token = "MTAxODE3MDczMDU0Mzg1Nzc3NA.GA2Qzu.__kLICXm-8VLTQD6KzL-uGaPx60Q6fn8K6lE3A"; - //var token = "Njc2NzQ4NjM2NjI5MTA2NzE4.Xtu2Ww._2oF7lQtxLLOUhfAIMxocN52dYo"; - - // Some alternative options would be to keep your token in an Environment Variable or a standalone file. - // var token = Environment.GetEnvironmentVariable("NameOfYourEnvironmentVariable"); - // var token = File.ReadAllText("token.txt"); - // var token = JsonConvert.DeserializeObject(File.ReadAllText("config.json")).Token; - +#if DEBUG + var token = File.ReadAllText("debugtoken.txt"); +#else + var token = File.ReadAllText("token.txt"); +#endif await _client.LoginAsync(TokenType.Bot, token); await _client.StartAsync(); @@ -109,10 +104,8 @@ namespace DiscordBot public async Task Client_Ready() { - // Let's build a guild command! We're going to need a guild so lets just put that in a variable. var guild = _client.GetGuild(666953424734257182); - // Next, lets create our slash command builder. This is like the embed builder but for slash commands. var guildCommand = new SlashCommandBuilder() .WithName(Constants.SlashCommands.RAID) .WithDescription("Raid commands") @@ -166,13 +159,10 @@ namespace DiscordBot // Using the ready event is a simple implementation for the sake of the example. Suitable for testing and development. // For a production bot, it is recommended to only run the CreateGlobalApplicationCommandAsync() once for each command. } - catch (ApplicationCommandException exception) + catch (HttpException exception) { - // If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is. - //var json = JsonConvert.SerializeObject(exception.Error, Formatting.Indented); - - // You can send this error somewhere or just print it to the console, for this example we're just going to print it. - //Console.WriteLine(json); + var json = JsonConvert.SerializeObject(exception.Errors, Formatting.Indented); + Console.WriteLine(json); } } diff --git a/DiscordBot/WeatherForecast.cs b/DiscordBot/WeatherForecast.cs deleted file mode 100644 index 49bd2ee..0000000 --- a/DiscordBot/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace DiscordBot -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string? Summary { get; set; } - } -} \ No newline at end of file