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

@@ -1,16 +1,17 @@
using DiscordBotCore;
using DiscordBotCore.Interfaces.Logger;
using DiscordBotCore.Interfaces.Modules;
using DiscordBotCore.Interfaces.Modules;
using DiscordBotCore.Others;
namespace LoggerModule
{
public class Entry : IModule<ILogger>
public class Entry : IModule
{
public string Name => "Logger Module";
public string Name => "LoggerModule";
public ModuleType ModuleType => ModuleType.Logger;
const string _LogFolder = "./Data/Logs/";
const string _LogFormat = "{ThrowTime} {SenderName} {Message}";
public ILogger Module { get; private set; }
public ILogger Module { get; private set; } = null!;
public Task Initialize()
{
@@ -18,5 +19,20 @@ namespace LoggerModule
Module = logger;
return Task.CompletedTask;
}
public void SetOutFunction(Action<string> outFunction)
{
Module.SetOutFunction(outFunction);
}
public void LogMessage(string message) => Module.Log(message);
public void LogMessageWithTypeAndFormat(string message, LogType logType, string format) => Module.Log(message, logType, format);
public void LogMessageWithType(string message, LogType logType) => Module.Log(message, logType);
public void LogMessageWithSender(string message, object Sender) => Module.Log(message, Sender);
public void LogMessageWithTypeAndSender(string message, object Sender, LogType type) => Module.Log(message, Sender, type);
public void LogExceptionWithSenderAndFullStack(Exception exception, object Sender, bool logFullStack = false) => Module.LogException(exception, Sender, logFullStack);
}
}

View File

@@ -0,0 +1,12 @@
using DiscordBotCore.Others;
namespace LoggerModule;
public interface ILogMessage
{
public string Message { get; protected set; }
public DateTime ThrowTime { get; protected set; }
public string SenderName { get; protected set; }
public LogType LogMessageType { get; protected set; }
}

View File

@@ -0,0 +1,22 @@
using DiscordBotCore.Others;
namespace LoggerModule;
public interface ILogger
{
public struct FormattedMessage {
public string Message;
public LogType Type;
}
string LogMessageFormat { get; set; }
void Log(string message);
void Log(string message, LogType logType);
void Log(string message, LogType logType, string format);
void Log(string message, object Sender);
void Log(string message, object Sender, LogType type);
void LogException(Exception exception, object Sender, bool logFullStack = false);
void SetOutFunction(Action<string> outFunction);
}

View File

@@ -1,5 +1,4 @@
using DiscordBotCore.Interfaces.Logger;
using DiscordBotCore.Others;
using DiscordBotCore.Others;
namespace LoggerModule
{

View File

@@ -1,5 +1,4 @@
using DiscordBotCore.Interfaces.Logger;
using DiscordBotCore.Others;
using DiscordBotCore.Others;
namespace LoggerModule;