This commit is contained in:
2022-06-08 20:45:25 +03:00
parent 51324f6dca
commit 1712205222
7 changed files with 30 additions and 74 deletions

View File

@@ -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

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AvaloniaProject">
<option name="projectPerEditor">
<map>
<entry key="DiscordBotGUI/App.axaml" value="DiscordBotGUI/DiscordBotGUI.csproj" />
<entry key="DiscordBotGUI/AppUpdater.axaml" value="DiscordBotGUI/DiscordBotGUI.csproj" />
<entry key="DiscordBotGUI/Settings/Commands.axaml" value="DiscordBotGUI/DiscordBotGUI.csproj" />
<entry key="DiscordBotGUI/Settings/Events.axaml" value="DiscordBotGUI/DiscordBotGUI.csproj" />
</map>
</option>
</component>
</project>

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -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<string>("token") == null || Config.GetValue<string>("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();
}
/// <summary>
/// Reset all settings for the bot
/// </summary>
private static async Task ResetSettings()
{
string[] files = Directory.GetFiles(@"./Data/Resources");
foreach (string file in files) File.Delete(file);
}
/// <summary>
/// The main loop for the discord bot
/// </summary>
@@ -98,12 +89,21 @@ namespace DiscordBot
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("============================ Discord BOT - Cross Platform ============================");
string token = Config.GetValue<string>("token");
string prefix = Config.GetValue<string>("prefix");
var discordbooter = new Boot(token, prefix);
await discordbooter.Awake();
return discordbooter;
try
{
string token = Config.GetValue<string>("token");
string prefix = Config.GetValue<string>("prefix");
var discordbooter = new Boot(token, prefix);
await discordbooter.Awake();
return discordbooter;
}
catch (Exception ex)
{
Console.WriteLine(ex);
return null;
}
}
/// <summary>
@@ -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<bool>("DeleteLogsAtStartup"))
foreach (string file in Directory.GetFiles("./Output/Logs/"))

View File

@@ -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<T>(string key)
{
if (!appConfig.ApplicationVariables.ContainsKey(key)) return default;
JsonElement element = (JsonElement)appConfig.ApplicationVariables[key];
return element.Deserialize<T>();
try
{
JsonElement element = (JsonElement)appConfig.ApplicationVariables[key];
return element.Deserialize<T>();
}
catch
{
return (T)appConfig.ApplicationVariables[key];
}
}
public static bool SetValue<T>(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<AppConfig>(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<AppConfig>(path);