More fixes to the new config. Module loader reworked

This commit is contained in:
2024-08-06 22:47:59 +03:00
parent 27e25a9166
commit 18a059af0e
51 changed files with 390 additions and 301 deletions

View File

@@ -21,7 +21,7 @@ namespace CppWrapper.LibraryManagement
return;
}
Application.CurrentApplication.Logger.Log($"Loading library {LibraryPath}");
Application.Logger.Log($"Loading library {LibraryPath}");
if(!NativeLibrary.TryLoad(LibraryPath, out IntPtr hModule))
@@ -29,7 +29,7 @@ namespace CppWrapper.LibraryManagement
throw new DllNotFoundException($"Unable to load library {LibraryPath}");
}
Application.CurrentApplication.Logger.Log($"Library {LibraryPath} loaded successfully [{hModule}]");
Application.Logger.Log($"Library {LibraryPath} loaded successfully [{hModule}]");
LibraryHandle = hModule;
}
@@ -44,7 +44,7 @@ namespace CppWrapper.LibraryManagement
NativeLibrary.Free(LibraryHandle);
LibraryHandle = IntPtr.Zero;
Application.CurrentApplication.Logger.Log($"Library {LibraryPath} freed successfully");
Application.Logger.Log($"Library {LibraryPath} freed successfully");
}
private IntPtr GetFunctionPointer(string functionName)
@@ -66,11 +66,11 @@ namespace CppWrapper.LibraryManagement
{
IntPtr functionPointer = GetFunctionPointer(methodName);
Application.CurrentApplication.Logger.Log($"Function pointer for {methodName} obtained successfully [address: {functionPointer}]");
Application.Logger.Log($"Function pointer for {methodName} obtained successfully [address: {functionPointer}]");
T result = (T)Marshal.GetDelegateForFunctionPointer(functionPointer, typeof(T));
Application.CurrentApplication.Logger.Log($"Delegate for {methodName} created successfully");
Application.Logger.Log($"Delegate for {methodName} created successfully");
return result;
}
@@ -79,7 +79,7 @@ namespace CppWrapper.LibraryManagement
{
IntPtr functionPointer = Marshal.GetFunctionPointerForDelegate(functionDelegate);
Application.CurrentApplication.Logger.Log($"Function pointer for delegate {functionDelegate.Method.Name} obtained successfully [address: {functionPointer}]");
Application.Logger.Log($"Function pointer for delegate {functionDelegate.Method.Name} obtained successfully [address: {functionPointer}]");
return functionPointer;
}
@@ -104,7 +104,7 @@ namespace CppWrapper.LibraryManagement
var result = setterDelegate.DynamicInvoke(executableFunctionPtr);
Application.CurrentApplication.Logger.Log($"Function {setterExternFunctionName} bound to local action successfully");
Application.Logger.Log($"Function {setterExternFunctionName} bound to local action successfully");
return result;
}

View File

@@ -48,7 +48,7 @@ public class Entry : ICommandAction
externalLibrary.FreeLibrary();
} catch (Exception dllException) {
Application.CurrentApplication.Logger.LogException(dllException, this);
Application.Logger.LogException(dllException, this);
}
}
}

View File

@@ -5,7 +5,7 @@ using DiscordBotCore.Others;
namespace LevelingSystem;
internal class LevelCommand: DBCommand
internal class LevelCommand: IDbCommand
{
public string Command => "level";
@@ -15,13 +15,13 @@ internal class LevelCommand: DBCommand
public string Usage => "level";
public bool requireAdmin => false;
public bool RequireAdmin => false;
public async void ExecuteServer(DbCommandExecutingArguments args)
{
if(Variables.Database is null)
{
Application.CurrentApplication.Logger.Log("Database is not initialized", this, LogType.Warning);
Application.Logger.Log("Database is not initialized", this, LogType.Warning);
return;
}

View File

@@ -7,7 +7,7 @@ using static LevelingSystem.Variables;
namespace LevelingSystem;
internal class LevelEvent : DBEvent
internal class LevelEvent : IDbEvent
{
public string Name => "Leveling System Event Handler";
public string Description => "The Leveling System Event Handler";

View File

@@ -7,7 +7,7 @@ using DiscordBotCore.Others;
namespace MusicPlayer.Commands;
public class AddMelody: DBCommand
public class AddMelody: IDbCommand
{
public string Command => "add_melody";
@@ -18,7 +18,7 @@ public class AddMelody: DBCommand
public string Description => "Add a custom melody to the database";
public string Usage => "add_melody [title],[description?],[aliases],[byteSize]";
public bool requireAdmin => false;
public bool RequireAdmin => false;
public async void ExecuteServer(DbCommandExecutingArguments args)
{

View File

@@ -6,7 +6,7 @@ using DiscordBotCore.Others;
namespace MusicPlayer.Commands;
public class AddMelodyYoutube: DBCommand
public class AddMelodyYoutube: IDbCommand
{
public string Command => "add_melody_youtube";
@@ -17,7 +17,7 @@ public class AddMelodyYoutube: DBCommand
public string Description => "Add melody to the database from a youtube link";
public string Usage => "add_melody_youtube [URL] <alias1|alias2|...>";
public bool requireAdmin => true;
public bool RequireAdmin => true;
public async void ExecuteServer(DbCommandExecutingArguments args)
{

View File

@@ -4,14 +4,14 @@ using DiscordBotCore.Others;
namespace MusicPlayer.Commands;
public class SearchMelody: DBCommand
public class SearchMelody: IDbCommand
{
public string Command => "search_melody";
public List<string>? Aliases => null;
public string Description => "Search for a melody in the database";
public string Usage => "search_melody [melody name OR one of its aliases]";
public bool requireAdmin => false;
public bool RequireAdmin => false;
public void ExecuteServer(DbCommandExecutingArguments args)
{

View File

@@ -5,7 +5,7 @@ using DiscordBotCore.Interfaces;
namespace MusicPlayer.Events;
public class OnLoad: DBEvent
public class OnLoad: IDbEvent
{
private static readonly string _DefaultMusicPath = "Music/";
private static readonly string _DefaultSaveLocation = "Music/Melodies/";

View File

@@ -5,7 +5,7 @@ using DiscordBotCore.Others;
namespace MusicPlayer.Events;
public class OnVoiceRemoved: DBEvent
public class OnVoiceRemoved: IDbEvent
{
public string Name => "Event: OnVoiceRemoved";
@@ -24,7 +24,7 @@ public class OnVoiceRemoved: DBEvent
Variables.audioClient = null;
Variables._MusicPlayer = null;
Application.CurrentApplication.Logger.Log("Bot left voice channel.", this, LogType.Info);
Application.Logger.Log("Bot left voice channel.", this, LogType.Info);
}
};

View File

@@ -29,13 +29,13 @@ public class MusicPlayer
{
if (isQueueRunning)
{
Application.CurrentApplication.Logger.Log("Another queue is running !", typeof(MusicPlayer), LogType.Warning);
Application.Logger.Log("Another queue is running !", typeof(MusicPlayer), LogType.Warning);
return;
}
if (Variables.audioClient is null)
{
Application.CurrentApplication.Logger.Log("Audio Client is null", typeof(MusicPlayer), LogType.Warning);
Application.Logger.Log("Audio Client is null", typeof(MusicPlayer), LogType.Warning);
return;
}
@@ -44,7 +44,7 @@ public class MusicPlayer
string? ffmpegPath = await Application.CurrentApplication.PluginManager.GetDependencyLocation("FFMPEG");
if(ffmpegPath is null)
{
Application.CurrentApplication.Logger.Log("FFMPEG is missing. Please install it and try again.", typeof(MusicPlayer), LogType.Error);
Application.Logger.Log("FFMPEG is missing. Please install it and try again.", typeof(MusicPlayer), LogType.Error);
isQueueRunning = false;
return;
}
@@ -61,7 +61,7 @@ public class MusicPlayer
using var ffmpeg = CreateStream(ffmpegPath, CurrentlyPlaying.Location);
if (ffmpeg is null)
{
Application.CurrentApplication.Logger.Log($"Failed to start ffmpeg process. FFMPEG is missing or the {CurrentlyPlaying.Location} has an invalid format.", typeof(MusicPlayer), LogType.Error);
Application.Logger.Log($"Failed to start ffmpeg process. FFMPEG is missing or the {CurrentlyPlaying.Location} has an invalid format.", typeof(MusicPlayer), LogType.Error);
continue;
}
await using var ffmpegOut = ffmpeg.StandardOutput.BaseStream;
@@ -111,7 +111,7 @@ public class MusicPlayer
}
catch (Exception ex)
{
Application.CurrentApplication.Logger.LogException(ex, this);
Application.Logger.LogException(ex, this);
break;
}
}

View File

@@ -4,12 +4,12 @@ using DiscordBotCore.Interfaces;
namespace MusicPlayer.SlashCommands;
public class Loop: DBSlashCommand
public class Loop: IDbSlashCommand
{
public string Name => "loop";
public string Description => "Loop the current song for a certain amount of times. If no times are specified, it will loop once";
public bool canUseDM => false;
public bool CanUseDm => false;
public bool HasInteraction => false;
public List<SlashCommandOptionBuilder> Options => new()

View File

@@ -7,11 +7,11 @@ using DiscordBotCore.Others;
namespace MusicPlayer.SlashCommands;
public class Play: DBSlashCommand
public class Play: IDbSlashCommand
{
public string Name => "play";
public string Description => "Play music command";
public bool canUseDM => false;
public bool CanUseDm => false;
public bool HasInteraction => false;
public List<SlashCommandOptionBuilder> Options => new()
@@ -55,7 +55,7 @@ public class Play: DBSlashCommand
if (user is null)
{
await context.RespondAsync("Failed to get user data from channel ! Check error log at " + DateTime.Now.ToLongTimeString());
Application.CurrentApplication.Logger.Log("User is null while trying to convert from context.User to IGuildUser.", typeof(Play), LogType.Error);
Application.Logger.Log("User is null while trying to convert from context.User to IGuildUser.", typeof(Play), LogType.Error);
return;
}

View File

@@ -4,11 +4,11 @@ using DiscordBotCore.Interfaces;
namespace MusicPlayer.SlashCommands;
public class Queue: DBSlashCommand
public class Queue: IDbSlashCommand
{
public string Name => "queue";
public string Description => "Queue a melody to play";
public bool canUseDM => false;
public bool CanUseDm => false;
public bool HasInteraction => false;
public List<SlashCommandOptionBuilder> Options => null;

View File

@@ -4,11 +4,11 @@ using DiscordBotCore.Interfaces;
namespace MusicPlayer.SlashCommands;
public class Skip: DBSlashCommand
public class Skip: IDbSlashCommand
{
public string Name => "skip";
public string Description => "Skip the current melody";
public bool canUseDM => false;
public bool CanUseDm => false;
public bool HasInteraction => false;
public List<SlashCommandOptionBuilder> Options => null;