Fixed some text and added some missing texts to commands. Added new command to clear screen and formated code.

This commit is contained in:
2023-07-03 14:39:50 +03:00
parent 4a6a12baae
commit 298e557260
36 changed files with 1503 additions and 1542 deletions

View File

@@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using PluginManager.Interfaces;
using PluginManager.Online;
using PluginManager.Others;
namespace PluginManager.Loaders;
@@ -23,7 +19,7 @@ public class PluginLoader
private const string pluginFolder = @"./Data/Plugins/";
internal const string pluginExtension = "dll";
internal const string pluginExtension = "dll";
private readonly DiscordSocketClient _client;
/// <summary>
@@ -62,20 +58,24 @@ public class PluginLoader
public static List<DBEvent>? Events { get; set; }
/// <summary>
/// A list of <see cref="DBSlashCommand"/> commands
/// A list of <see cref="DBSlashCommand" /> commands
/// </summary>
public static List<DBSlashCommand>? SlashCommands { get; set; }
public static int PluginsLoaded { get {
var count = 0;
if (Commands is not null)
count += Commands.Count;
if (Events is not null)
count += Events.Count;
if (SlashCommands is not null)
count += SlashCommands.Count;
return count;
}}
public static int PluginsLoaded
{
get
{
var count = 0;
if (Commands is not null)
count += Commands.Count;
if (Events is not null)
count += Events.Count;
if (SlashCommands is not null)
count += SlashCommands.Count;
return count;
}
}
/// <summary>
/// The main mathod that is called to load all events
@@ -84,24 +84,24 @@ public class PluginLoader
{
//Load all plugins
Commands = new List<DBCommand>();
Events = new List<DBEvent>();
Commands = new List<DBCommand>();
Events = new List<DBEvent>();
SlashCommands = new List<DBSlashCommand>();
Config.Logger.Log("Starting plugin loader ... Client: " + _client.CurrentUser.Username, this, Others.LogLevel.INFO);
Config.Logger.Log("Starting plugin loader ... Client: " + _client.CurrentUser.Username, this,
LogLevel.INFO);
var loader = new Loader("./Data/Plugins", "dll");
loader.FileLoaded += (args) => Config.Logger.Log($"{args.PluginName} file Loaded", this , Others.LogLevel.INFO);
loader.FileLoaded += args => Config.Logger.Log($"{args.PluginName} file Loaded", this, LogLevel.INFO);
loader.PluginLoaded += Loader_PluginLoaded;
var res = loader.Load();
Events = res.Item1;
Commands = res.Item2;
Events = res.Item1;
Commands = res.Item2;
SlashCommands = res.Item3;
}
private async void Loader_PluginLoaded(LoaderArgs args)
{
switch (args.TypeName)
{
case "DBCommand":
@@ -117,27 +117,29 @@ public class PluginLoader
}
catch (Exception ex)
{
Config.Logger.Log(ex.Message, this, Others.LogLevel.ERROR);
Config.Logger.Log(ex.Message, this, LogLevel.ERROR);
}
break;
case "DBSlashCommand":
if (args.IsLoaded)
{
var slash = (DBSlashCommand)args.Plugin;
SlashCommandBuilder builder = new SlashCommandBuilder();
var slash = (DBSlashCommand)args.Plugin;
var builder = new SlashCommandBuilder();
builder.WithName(slash.Name);
builder.WithDescription(slash.Description);
builder.WithDMPermission(slash.canUseDM);
builder.Options = slash.Options;
onSLSHLoad?.Invoke(((DBSlashCommand)args.Plugin!).Name, args.TypeName, args.IsLoaded, args.Exception);
onSLSHLoad?.Invoke(((DBSlashCommand)args.Plugin!).Name, args.TypeName, args.IsLoaded,
args.Exception);
await _client.CreateGlobalApplicationCommandAsync(builder.Build());
}
break;
}
}
public static async Task LoadPluginFromAssembly(Assembly asmb, DiscordSocketClient client)
{
var types = asmb.GetTypes();
@@ -146,28 +148,27 @@ public class PluginLoader
{
var instance = (DBEvent)Activator.CreateInstance(type);
instance.Start(client);
PluginLoader.Events.Add(instance);
Config.Logger.Log($"[EVENT] Loaded external {type.FullName}!", Others.LogLevel.INFO);
Events.Add(instance);
Config.Logger.Log($"[EVENT] Loaded external {type.FullName}!", LogLevel.INFO);
}
else if (type.IsClass && typeof(DBCommand).IsAssignableFrom(type))
{
var instance = (DBCommand)Activator.CreateInstance(type);
PluginLoader.Commands.Add(instance);
Config.Logger.Log($"[CMD] Instance: {type.FullName} loaded !", Others.LogLevel.INFO);
Commands.Add(instance);
Config.Logger.Log($"[CMD] Instance: {type.FullName} loaded !", LogLevel.INFO);
}
else if (type.IsClass && typeof(DBSlashCommand).IsAssignableFrom(type))
{
var instance = (DBSlashCommand)Activator.CreateInstance(type);
SlashCommandBuilder builder = new SlashCommandBuilder();
var builder = new SlashCommandBuilder();
builder.WithName(instance.Name);
builder.WithDescription(instance.Description);
builder.WithDMPermission(instance.canUseDM);
builder.Options = instance.Options;
await client.CreateGlobalApplicationCommandAsync(builder.Build());
PluginLoader.SlashCommands.Add(instance);
Config.Logger.Log($"[SLASH] Instance: {type.FullName} loaded !", Others.LogLevel.INFO);
SlashCommands.Add(instance);
Config.Logger.Log($"[SLASH] Instance: {type.FullName} loaded !", LogLevel.INFO);
}
}
}
}