From a5e65a5ea50ed5a0dea3959983b62ed7d947b833 Mon Sep 17 00:00:00 2001 From: Andrei Tudor Date: Tue, 21 May 2024 21:21:48 +0300 Subject: [PATCH] Autorestart on token check fail --- DiscordBot/Entry.cs | 2 ++ DiscordBot/Program.cs | 1 - DiscordBotCore/Bot/Boot.cs | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/DiscordBot/Entry.cs b/DiscordBot/Entry.cs index 602f190..cfb7d25 100644 --- a/DiscordBot/Entry.cs +++ b/DiscordBot/Entry.cs @@ -46,6 +46,8 @@ public static class Entry #endif + Console.Clear(); + Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(logo); Console.ResetColor(); diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index 526e83d..33c51ad 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -21,7 +21,6 @@ public class Program public static async Task Startup(string[] args) { await LoadComponents(args); - await PrepareConsole(); await ConsoleInputHandler(); } diff --git a/DiscordBotCore/Bot/Boot.cs b/DiscordBotCore/Bot/Boot.cs index 70f3dfd..093914b 100644 --- a/DiscordBotCore/Bot/Boot.cs +++ b/DiscordBotCore/Bot/Boot.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Threading.Tasks; using Discord; using Discord.Commands; @@ -106,8 +107,11 @@ public class Boot if (arg.Message.Contains("401")) { Application.CurrentApplication.ApplicationEnvironmentVariables.Remove("token"); - Application.CurrentApplication.Logger.Log("The token is invalid. Please restart the bot and follow the instructions", this, LogType.CRITICAL); + Application.CurrentApplication.Logger.Log("The token is invalid.", this, LogType.CRITICAL); await Application.CurrentApplication.ApplicationEnvironmentVariables.SaveToFile(); + await Task.Delay(3000); + + Process.Start(Environment.ProcessPath); Environment.Exit(0); } }