Renamed PluginManager to DiscordBotCore.

Revamped the Logger
This commit is contained in:
2024-05-12 20:10:52 +03:00
parent 413d465d7f
commit 17147d920d
66 changed files with 529 additions and 556 deletions

View File

@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PluginManager.Interfaces;
using PluginManager.Others;
using PluginManager.Others.Actions;
using DiscordBotCore.Interfaces;
using DiscordBotCore.Others;
using DiscordBotCore.Others.Actions;
namespace DiscordBot.Bot.Actions;

View File

@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using PluginManager;
using PluginManager.Interfaces;
using PluginManager.Others;
using PluginManager.Others.Actions;
using DiscordBotCore;
using DiscordBotCore.Interfaces;
using DiscordBotCore.Others;
using DiscordBotCore.Others.Actions;
namespace DiscordBot.Bot.Actions;
@@ -24,8 +24,8 @@ public class Exit: ICommandAction
{
if (args is null || args.Length == 0)
{
Config.Logger.Log("Exiting...", typeof(ICommandAction), LogType.WARNING);
await Config.AppSettings.SaveToFile();
Application.CurrentApplication.Logger.Log("Exiting...", typeof(ICommandAction), LogType.WARNING);
await Application.CurrentApplication.ApplicationEnvironmentVariables.SaveToFile();
Environment.Exit(0);
}
else
@@ -40,7 +40,7 @@ public class Exit: ICommandAction
case "-f":
case "force":
Config.Logger.Log("Exiting (FORCE)...", typeof(ICommandAction), LogType.WARNING);
Application.CurrentApplication.Logger.Log("Exiting (FORCE)...", typeof(ICommandAction), LogType.WARNING);
Environment.Exit(0);
break;

View File

@@ -6,11 +6,12 @@ using System.Threading.Tasks;
using DiscordBot.Utilities;
using PluginManager;
using PluginManager.Interfaces;
using PluginManager.Loaders;
using PluginManager.Online;
using PluginManager.Others;
using DiscordBotCore;
using DiscordBotCore.Interfaces;
using DiscordBotCore.Loaders;
using DiscordBotCore.Online;
using DiscordBotCore.Others;
using DiscordBotCore.Plugin;
using Spectre.Console;
@@ -18,7 +19,7 @@ namespace DiscordBot.Bot.Actions.Extra;
internal static class PluginMethods
{
internal static async Task List(PluginsManager manager)
internal static async Task List(PluginManager manager)
{
var data = await ConsoleUtilities.ExecuteWithProgressBar(manager.GetPluginsList(), "Reading remote database");
@@ -38,11 +39,11 @@ internal static class PluginMethods
internal static async Task RefreshPlugins(bool quiet)
{
await Program.internalActionManager.Execute("plugin", "load", quiet ? "-q" : string.Empty);
await Program.internalActionManager.Refresh();
await Application.CurrentApplication.InternalActionManager.Execute("plugin", "load", quiet ? "-q" : string.Empty);
await Application.CurrentApplication.InternalActionManager.Refresh();
}
internal static async Task DownloadPlugin(PluginsManager manager, string pluginName)
internal static async Task DownloadPlugin(PluginManager manager, string pluginName)
{
var pluginData = await manager.GetPluginDataByName(pluginName);
if (pluginData is null)
@@ -66,7 +67,7 @@ internal static class PluginMethods
IProgress<float> progress = new Progress<float>(p => { downloadTask.Value = p; });
await ServerCom.DownloadFileAsync(pluginLink, $"{Config.AppSettings["PluginFolder"]}/{pluginName}.dll", progress);
await ServerCom.DownloadFileAsync(pluginLink, $"{Application.CurrentApplication.ApplicationEnvironmentVariables["PluginFolder"]}/{pluginName}.dll", progress);
downloadTask.Increment(100);
@@ -76,7 +77,7 @@ internal static class PluginMethods
if (!pluginData.HasDependencies)
{
await manager.AppendPluginToDatabase(new PluginManager.Plugin.PluginInfo(pluginName, pluginData.Version, []));
await manager.AppendPluginToDatabase(new PluginInfo(pluginName, pluginData.Version, []));
Console.WriteLine("Finished installing " + pluginName + " successfully");
await RefreshPlugins(false);
return;
@@ -108,8 +109,8 @@ internal static class PluginMethods
int maxParallelDownloads = 5;
if (Config.AppSettings.ContainsKey("MaxParallelDownloads"))
maxParallelDownloads = int.Parse(Config.AppSettings["MaxParallelDownloads"]);
if (Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("MaxParallelDownloads"))
maxParallelDownloads = int.Parse(Application.CurrentApplication.ApplicationEnvironmentVariables["MaxParallelDownloads"]);
var options = new ParallelOptions()
{
@@ -129,13 +130,13 @@ internal static class PluginMethods
}
);
await manager.AppendPluginToDatabase(new PluginManager.Plugin.PluginInfo(pluginName, pluginData.Version, pluginData.Dependencies.Select(sep => sep.DownloadLocation).ToList()));
await manager.AppendPluginToDatabase(new PluginInfo(pluginName, pluginData.Version, pluginData.Dependencies.Select(sep => sep.DownloadLocation).ToList()));
await RefreshPlugins(false);
}
internal static async Task<bool> LoadPlugins(string[] args)
{
var loader = new PluginLoader(Config.DiscordBot.Client);
var loader = new PluginLoader(Application.CurrentApplication.DiscordBotClient.Client);
if (args.Length == 2 && args[1] == "-q")
{
await loader.LoadPlugins();
@@ -147,14 +148,14 @@ internal static class PluginMethods
{
if (data.IsSuccess)
{
Config.Logger.Log("Successfully loaded command : " + data.PluginName, typeof(ICommandAction),
Application.CurrentApplication.Logger.Log("Successfully loaded command : " + data.PluginName, typeof(ICommandAction),
LogType.INFO
);
}
else
{
Config.Logger.Log("Failed to load command : " + data.PluginName + " because " + data.ErrorMessage,
Application.CurrentApplication.Logger.Log("Failed to load command : " + data.PluginName + " because " + data.ErrorMessage,
typeof(ICommandAction), LogType.ERROR
);
}
@@ -165,13 +166,13 @@ internal static class PluginMethods
{
if (data.IsSuccess)
{
Config.Logger.Log("Successfully loaded event : " + data.PluginName, typeof(ICommandAction),
Application.CurrentApplication.Logger.Log("Successfully loaded event : " + data.PluginName, typeof(ICommandAction),
LogType.INFO
);
}
else
{
Config.Logger.Log("Failed to load event : " + data.PluginName + " because " + data.ErrorMessage,
Application.CurrentApplication.Logger.Log("Failed to load event : " + data.PluginName + " because " + data.ErrorMessage,
typeof(ICommandAction), LogType.ERROR
);
}
@@ -183,13 +184,13 @@ internal static class PluginMethods
{
if (data.IsSuccess)
{
Config.Logger.Log("Successfully loaded slash command : " + data.PluginName, typeof(ICommandAction),
Application.CurrentApplication.Logger.Log("Successfully loaded slash command : " + data.PluginName, typeof(ICommandAction),
LogType.INFO
);
}
else
{
Config.Logger.Log("Failed to load slash command : " + data.PluginName + " because " + data.ErrorMessage,
Application.CurrentApplication.Logger.Log("Failed to load slash command : " + data.PluginName + " because " + data.ErrorMessage,
typeof(ICommandAction), LogType.ERROR
);
}

View File

@@ -1,6 +1,5 @@
using System.Linq;
using PluginManager;
using PluginManager.Loaders;
using DiscordBotCore;
namespace DiscordBot.Bot.Actions.Extra;
@@ -13,21 +12,21 @@ internal static class SettingsConfigExtra
if (value is null) return;
if (!Config.AppSettings.ContainsKey(key))
if (!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey(key))
return;
Config.AppSettings[key] = string.Join(' ', value);
// Config.AppSettings.SaveToFile().Wait();
Application.CurrentApplication.ApplicationEnvironmentVariables[key] = string.Join(' ', value);
// Config.Application.CurrentApplication.ApplicationEnvironmentVariables.SaveToFile().Wait();
}
internal static void RemoveSettings(string key)
{
if (key is null) return;
if (!Config.AppSettings.ContainsKey(key))
if (!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey(key))
return;
Config.AppSettings.Remove(key);
Application.CurrentApplication.ApplicationEnvironmentVariables.Remove(key);
}
internal static void AddSettings(string key, params string[] value)
@@ -36,10 +35,10 @@ internal static class SettingsConfigExtra
if (value is null) return;
if (Config.AppSettings.ContainsKey(key))
if (Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey(key))
return;
Config.AppSettings.Add(key, string.Join(' ', value));
// Config.AppSettings.SaveToFile().Wait();
Application.CurrentApplication.ApplicationEnvironmentVariables.Add(key, string.Join(' ', value));
// Config.Application.CurrentApplication.ApplicationEnvironmentVariables.SaveToFile().Wait();
}
}

View File

@@ -3,9 +3,11 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DiscordBot.Utilities;
using PluginManager.Interfaces;
using PluginManager.Others;
using PluginManager.Others.Actions;
using DiscordBotCore;
using DiscordBotCore.Interfaces;
using DiscordBotCore.Others;
using DiscordBotCore.Others.Actions;
using Spectre.Console;
namespace DiscordBot.Bot.Actions;
@@ -30,7 +32,7 @@ public class Help: ICommandAction
tableData.Columns = ["Command", "Usage", "Description", "Options"];
foreach (var a in Program.internalActionManager.Actions)
foreach (var a in Application.CurrentApplication.InternalActionManager.Actions)
{
Markup actionName = new Markup($"[bold]{a.Key}[/]");
Markup usage = new Markup($"[italic]{a.Value.Usage}[/]");
@@ -68,13 +70,13 @@ public class Help: ICommandAction
return;
}
if (!Program.internalActionManager.Actions.ContainsKey(args[0]))
if (!Application.CurrentApplication.InternalActionManager.Actions.ContainsKey(args[0]))
{
Console.WriteLine("Command not found");
return;
}
var action = Program.internalActionManager.Actions[args[0]];
var action = Application.CurrentApplication.InternalActionManager.Actions[args[0]];
tableData.Columns = ["Command", "Usage", "Description"];
tableData.AddRow([action.ActionName, action.Usage, action.Description]);

View File

@@ -2,10 +2,10 @@ using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DiscordBot.Bot.Actions.Extra;
using PluginManager;
using PluginManager.Interfaces;
using PluginManager.Others;
using PluginManager.Others.Actions;
using DiscordBotCore;
using DiscordBotCore.Interfaces;
using DiscordBotCore.Others;
using DiscordBotCore.Others.Actions;
namespace DiscordBot.Bot.Actions;
@@ -50,24 +50,24 @@ public class Plugin: ICommandAction
case "uninstall":
string plugName = string.Join(' ', args, 1, args.Length-1);
bool result = await Config.PluginsManager.MarkPluginToUninstall(plugName);
bool result = await Application.CurrentApplication.PluginManager.MarkPluginToUninstall(plugName);
if(result)
Console.WriteLine($"Marked to uninstall plugin {plugName}. Please restart the bot");
break;
case "list":
await PluginMethods.List(Config.PluginsManager);
await PluginMethods.List(Application.CurrentApplication.PluginManager);
break;
case "load":
if (pluginsLoaded)
{
Config.Logger.Log("Plugins already loaded", typeof(ICommandAction), LogType.WARNING);
Application.CurrentApplication.Logger.Log("Plugins already loaded", typeof(ICommandAction), LogType.WARNING);
break;
}
if (Config.DiscordBot is null)
if (Application.CurrentApplication.DiscordBotClient is null)
{
Config.Logger.Log("DiscordBot is null", typeof(ICommandAction), LogType.WARNING);
Application.CurrentApplication.Logger.Log("DiscordBot is null", typeof(ICommandAction), LogType.WARNING);
break;
}
@@ -88,7 +88,7 @@ public class Plugin: ICommandAction
}
}
await PluginMethods.DownloadPlugin(Config.PluginsManager, pluginName);
await PluginMethods.DownloadPlugin(Application.CurrentApplication.PluginManager, pluginName);
break;
}
}

View File

@@ -2,10 +2,10 @@ using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DiscordBot.Bot.Actions.Extra;
using PluginManager;
using PluginManager.Interfaces;
using PluginManager.Others;
using PluginManager.Others.Actions;
using DiscordBotCore;
using DiscordBotCore.Interfaces;
using DiscordBotCore.Others;
using DiscordBotCore.Others.Actions;
namespace DiscordBot.Bot.Actions;
@@ -26,7 +26,7 @@ public class SettingsConfig: ICommandAction
{
if (args is null)
{
foreach (var settings in Config.AppSettings)
foreach (var settings in Application.CurrentApplication.ApplicationEnvironmentVariables)
Console.WriteLine(settings.Key + ": " + settings.Value);
return Task.CompletedTask;