Fixed a bug with invalid token bot startup
This commit is contained in:
@@ -18,19 +18,28 @@ namespace DiscordBot
|
|||||||
Console.WriteLine("Welcome to the SethBot installer !");
|
Console.WriteLine("Welcome to the SethBot installer !");
|
||||||
Console.WriteLine("First, we need to configure the bot. Don't worry, it will be quick !");
|
Console.WriteLine("First, we need to configure the bot. Don't worry, it will be quick !");
|
||||||
Console.WriteLine("The following information will be stored in the config.json file in the ./Data/Resources folder. You can change it later from there.");
|
Console.WriteLine("The following information will be stored in the config.json file in the ./Data/Resources folder. You can change it later from there.");
|
||||||
Console.WriteLine("The bot tokn is required to run the bot. You can get it from the Discord Developer Portal. (https://discord.com/developers/applications)");
|
Console.WriteLine("The bot token is required to run the bot. You can get it from the Discord Developer Portal. (https://discord.com/developers/applications)");
|
||||||
|
|
||||||
|
if (!Config.Data.ContainsKey("token"))
|
||||||
|
{
|
||||||
Console.WriteLine("Please enter the bot token :");
|
Console.WriteLine("Please enter the bot token :");
|
||||||
var token = Console.ReadLine();
|
var token = Console.ReadLine();
|
||||||
|
Config.Data.Add("token", token);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Config.Data.ContainsKey("prefix"))
|
||||||
|
{
|
||||||
Console.WriteLine("Please enter the bot prefix :");
|
Console.WriteLine("Please enter the bot prefix :");
|
||||||
var prefix = Console.ReadLine();
|
var prefix = Console.ReadLine();
|
||||||
|
Config.Data.Add("prefix", prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Config.Data.ContainsKey("ServerID"))
|
||||||
|
{
|
||||||
Console.WriteLine("Please enter the Server ID :");
|
Console.WriteLine("Please enter the Server ID :");
|
||||||
var serverId = Console.ReadLine();
|
var serverId = Console.ReadLine();
|
||||||
|
|
||||||
Config.Data.Add("token", token);
|
|
||||||
Config.Data.Add("prefix", prefix);
|
|
||||||
Config.Data.Add("ServerID", serverId);
|
Config.Data.Add("ServerID", serverId);
|
||||||
|
}
|
||||||
|
|
||||||
Config.Logger.Log("Config Saved", "Installer", LogLevel.INFO);
|
Config.Logger.Log("Config Saved", "Installer", LogLevel.INFO);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Discord;
|
using Discord;
|
||||||
@@ -68,7 +69,6 @@ public class Boot
|
|||||||
|
|
||||||
//Disable system clock checkup (for responses at slash commands)
|
//Disable system clock checkup (for responses at slash commands)
|
||||||
UseInteractionSnowflakeDate = false,
|
UseInteractionSnowflakeDate = false,
|
||||||
|
|
||||||
GatewayIntents = GatewayIntents.All
|
GatewayIntents = GatewayIntents.All
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -110,6 +110,7 @@ public class Boot
|
|||||||
{
|
{
|
||||||
Config.Data.Remove("token");
|
Config.Data.Remove("token");
|
||||||
Config.Logger.Log("The token is invalid. Please restart the bot and enter a valid token.", this, Others.LogLevel.ERROR);
|
Config.Logger.Log("The token is invalid. Please restart the bot and enter a valid token.", this, Others.LogLevel.ERROR);
|
||||||
|
Config.Data.Save();
|
||||||
await Task.Delay(4000);
|
await Task.Delay(4000);
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,14 @@ public class Config
|
|||||||
protected IDictionary<TKey, TValue> _dictionary;
|
protected IDictionary<TKey, TValue> _dictionary;
|
||||||
private readonly string _file = "";
|
private readonly string _file = "";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Empty constructor
|
||||||
|
/// </summary>
|
||||||
|
public Json()
|
||||||
|
{
|
||||||
|
_dictionary = new Dictionary<TKey, TValue>();
|
||||||
|
}
|
||||||
|
|
||||||
public Json(string file)
|
public Json(string file)
|
||||||
{
|
{
|
||||||
_dictionary = PrivateReadConfig(file).GetAwaiter().GetResult();
|
_dictionary = PrivateReadConfig(file).GetAwaiter().GetResult();
|
||||||
@@ -62,6 +70,7 @@ public class Config
|
|||||||
|
|
||||||
public async void Save()
|
public async void Save()
|
||||||
{
|
{
|
||||||
|
if(!string.IsNullOrEmpty(_file))
|
||||||
await Functions.SaveToJsonFile(_file, _dictionary);
|
await Functions.SaveToJsonFile(_file, _dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user