Autorestart on token check fail

This commit is contained in:
2024-05-21 21:21:48 +03:00
parent d6398cd1cc
commit a5e65a5ea5
3 changed files with 7 additions and 2 deletions

View File

@@ -46,6 +46,8 @@ public static class Entry
#endif #endif
Console.Clear();
Console.ForegroundColor = ConsoleColor.DarkYellow; Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine(logo); Console.WriteLine(logo);
Console.ResetColor(); Console.ResetColor();

View File

@@ -21,7 +21,6 @@ public class Program
public static async Task Startup(string[] args) public static async Task Startup(string[] args)
{ {
await LoadComponents(args); await LoadComponents(args);
await PrepareConsole(); await PrepareConsole();
await ConsoleInputHandler(); await ConsoleInputHandler();
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
@@ -106,8 +107,11 @@ public class Boot
if (arg.Message.Contains("401")) if (arg.Message.Contains("401"))
{ {
Application.CurrentApplication.ApplicationEnvironmentVariables.Remove("token"); 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 Application.CurrentApplication.ApplicationEnvironmentVariables.SaveToFile();
await Task.Delay(3000);
Process.Start(Environment.ProcessPath);
Environment.Exit(0); Environment.Exit(0);
} }
} }