diff --git a/.idea/.idea.DiscordBotWithAPI/.idea/.gitignore b/.idea/.idea.DiscordBotWithAPI/.idea/.gitignore
deleted file mode 100644
index 1e2399a..0000000
--- a/.idea/.idea.DiscordBotWithAPI/.idea/.gitignore
+++ /dev/null
@@ -1,13 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Rider ignored files
-/modules.xml
-/contentModel.xml
-/.idea.DiscordBotWithAPI.iml
-/projectSettingsUpdater.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/.idea/.idea.DiscordBotWithAPI/.idea/avalonia.xml b/.idea/.idea.DiscordBotWithAPI/.idea/avalonia.xml
deleted file mode 100644
index c0fdb9d..0000000
--- a/.idea/.idea.DiscordBotWithAPI/.idea/avalonia.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.DiscordBotWithAPI/.idea/encodings.xml b/.idea/.idea.DiscordBotWithAPI/.idea/encodings.xml
deleted file mode 100644
index df87cf9..0000000
--- a/.idea/.idea.DiscordBotWithAPI/.idea/encodings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.DiscordBotWithAPI/.idea/indexLayout.xml b/.idea/.idea.DiscordBotWithAPI/.idea/indexLayout.xml
deleted file mode 100644
index 7b08163..0000000
--- a/.idea/.idea.DiscordBotWithAPI/.idea/indexLayout.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/.idea.DiscordBotWithAPI/.idea/vcs.xml b/.idea/.idea.DiscordBotWithAPI/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/.idea.DiscordBotWithAPI/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs
index 1414f89..00aadb4 100644
--- a/DiscordBot/Program.cs
+++ b/DiscordBot/Program.cs
@@ -25,7 +25,7 @@ namespace DiscordBot
Directory.CreateDirectory("./Data/Resources");
Directory.CreateDirectory("./Data/Plugins/Commands");
Directory.CreateDirectory("./Data/Plugins/Events");
- PreLoadComponents();
+ PreLoadComponents().Wait();
if (!Config.ContainsKey("token") || Config.GetValue("token") == null || Config.GetValue("token")?.Length != 70)
{
@@ -45,7 +45,7 @@ namespace DiscordBot
Console.WriteLine("Please insert your prefix (max. 1 character long):");
Console.WriteLine("For a prefix longer then one character, the first character will be saved and the others will be ignored. No spaces or numbers allowed");
Console.Write("Prefix = ");
- char prefix = Console.ReadLine()[0];
+ char prefix = Console.ReadLine()![0];
if (prefix == ' ' || char.IsDigit(prefix)) continue;
Config.AddValueToVariables("prefix", prefix.ToString(), false);
@@ -58,15 +58,6 @@ namespace DiscordBot
HandleInput(args).Wait();
}
- ///
- /// Reset all settings for the bot
- ///
- private static async Task ResetSettings()
- {
- string[] files = Directory.GetFiles(@"./Data/Resources");
- foreach (string file in files) File.Delete(file);
- }
-
///
/// The main loop for the discord bot
///
@@ -98,12 +89,21 @@ namespace DiscordBot
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("============================ Discord BOT - Cross Platform ============================");
- string token = Config.GetValue("token");
- string prefix = Config.GetValue("prefix");
- var discordbooter = new Boot(token, prefix);
- await discordbooter.Awake();
- return discordbooter;
+ try
+ {
+ string token = Config.GetValue("token");
+ string prefix = Config.GetValue("prefix");
+
+ var discordbooter = new Boot(token, prefix);
+ await discordbooter.Awake();
+ return discordbooter;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex);
+ return null;
+ }
}
///
@@ -138,7 +138,7 @@ namespace DiscordBot
if (len == 1 && args[0] == "--logout")
{
- File.Delete(Functions.dataFolder + "var.dat");
+ File.Delete(Functions.dataFolder + "config.json");
await Task.Run(async () =>
{
await Task.Delay(1000);
@@ -188,7 +188,6 @@ namespace DiscordBot
"\tCommand name\t\t\t\tDescription\n" +
"-- help | -help\t\t ------ \tDisplay the help message\n" +
"--reset-full\t\t ------ \tReset all files (clear files)\n" +
- "--reset-settings\t ------ \tReset only bot settings\n" +
"--reset-logs\t\t ------ \tClear up the output folder\n" +
"--start\t\t ------ \tStart the bot\n" +
"exit\t\t\t ------ \tClose the application"
@@ -201,10 +200,6 @@ namespace DiscordBot
switch (message[0])
{
- case "--reset-settings":
- await ResetSettings();
- Console.WriteLine("Successfully reseted all settings !");
- break;
case "--help":
case "-help":
Console.ForegroundColor = ConsoleColor.DarkYellow;
@@ -250,8 +245,7 @@ namespace DiscordBot
private static async Task PreLoadComponents()
{
- Config.LoadConfig().Wait();
-
+ await Config.LoadConfig();
if (Config.ContainsKey("DeleteLogsAtStartup"))
if (Config.GetValue("DeleteLogsAtStartup"))
foreach (string file in Directory.GetFiles("./Output/Logs/"))
diff --git a/PluginManager/Config.cs b/PluginManager/Config.cs
index 04193ed..d6cb269 100644
--- a/PluginManager/Config.cs
+++ b/PluginManager/Config.cs
@@ -1,5 +1,4 @@
-using System;
-using PluginManager.Others;
+using PluginManager.Others;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -31,8 +30,15 @@ namespace PluginManager
public static T? GetValue(string key)
{
if (!appConfig.ApplicationVariables.ContainsKey(key)) return default;
- JsonElement element = (JsonElement)appConfig.ApplicationVariables[key];
- return element.Deserialize();
+ try
+ {
+ JsonElement element = (JsonElement)appConfig.ApplicationVariables[key];
+ return element.Deserialize();
+ }
+ catch
+ {
+ return (T)appConfig.ApplicationVariables[key];
+ }
}
public static bool SetValue(string key, T value)
@@ -56,14 +62,14 @@ namespace PluginManager
public static async void SaveConfig()
{
- string path = Functions.dataFolder + "var.dat";
+ string path = Functions.dataFolder + "config.json";
await Functions.SaveToJsonFile(path, appConfig);
}
public static async Task LoadConfig()
{
- string path = Functions.dataFolder + "var.dat";
+ string path = Functions.dataFolder + "config.json";
if (File.Exists(path))
{
appConfig = await Functions.ConvertFromJson(path);