Reformatting code
This commit is contained in:
@@ -26,7 +26,7 @@ public class InternalActionManager
|
||||
Actions.TryAdd(action.ActionName, action);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task Refresh()
|
||||
{
|
||||
Actions.Clear();
|
||||
@@ -59,7 +59,7 @@ public class InternalActionManager
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Config.Logger.Log(e.Message , type: LogType.ERROR, source: typeof(InternalActionManager));
|
||||
Config.Logger.Log(e.Message, type: LogType.ERROR, source: typeof(InternalActionManager));
|
||||
return e.Message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,24 +37,24 @@ public static class ArchiveManager
|
||||
|
||||
if (!File.Exists(archName))
|
||||
throw new Exception("Failed to load file !");
|
||||
|
||||
|
||||
byte[]? data = null;
|
||||
|
||||
|
||||
using (var zip = ZipFile.OpenRead(archName))
|
||||
{
|
||||
var entry = zip.Entries.FirstOrDefault(entry => entry.FullName == fileName || entry.Name == fileName);
|
||||
if (entry is null) throw new Exception("File not found in archive");
|
||||
|
||||
|
||||
var MemoryStream = new MemoryStream();
|
||||
|
||||
|
||||
var stream = entry.Open();
|
||||
await stream.CopyToAsync(MemoryStream);
|
||||
data = MemoryStream.ToArray();
|
||||
|
||||
|
||||
stream.Close();
|
||||
MemoryStream.Close();
|
||||
}
|
||||
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public static class ArchiveManager
|
||||
{
|
||||
if (type == UnzipProgressType.PERCENTAGE_FROM_NUMBER_OF_FILES)
|
||||
{
|
||||
var totalZIPFiles = archive.Entries.Count();
|
||||
var totalZIPFiles = archive.Entries.Count();
|
||||
var currentZIPFile = 0;
|
||||
foreach (var entry in archive.Entries)
|
||||
{
|
||||
@@ -173,4 +173,4 @@ public static class ArchiveManager
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,19 +29,19 @@ public class DBCommandExecutingArguments
|
||||
{
|
||||
this.cleanContent = message.Content.Substring(Config.DiscordBot.botPrefix.Length);
|
||||
}
|
||||
|
||||
|
||||
var split = this.cleanContent.Split(' ');
|
||||
|
||||
string[]? argsClean = null;
|
||||
if (split.Length > 1)
|
||||
argsClean = string.Join(' ', split, 1, split.Length - 1).Split(' ');
|
||||
|
||||
|
||||
this.commandUsed = split[0];
|
||||
this.arguments = argsClean;
|
||||
this.arguments = argsClean;
|
||||
}
|
||||
|
||||
public SocketCommandContext context { get; init; }
|
||||
public string cleanContent { get; init; }
|
||||
public string commandUsed { get; init; }
|
||||
public string[]? arguments { get; init; }
|
||||
public SocketCommandContext context { get; init; }
|
||||
public string cleanContent { get; init; }
|
||||
public string commandUsed { get; init; }
|
||||
public string[]? arguments { get; init; }
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ public enum InternalActionRunType
|
||||
ON_CALL
|
||||
}
|
||||
|
||||
internal enum ExceptionExitCode : int
|
||||
internal enum ExceptionExitCode: int
|
||||
{
|
||||
CONFIG_FAILED_TO_LOAD = 1,
|
||||
CONFIG_KEY_NOT_FOUND = 2,
|
||||
CONFIG_KEY_NOT_FOUND = 2,
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ public static class Functions
|
||||
/// <exception cref="InvalidOperationException">Triggered if <paramref name="stream" /> is not readable</exception>
|
||||
/// <exception cref="ArgumentException">Triggered in <paramref name="destination" /> is not writable</exception>
|
||||
public static async Task CopyToOtherStreamAsync(
|
||||
this Stream stream, Stream destination, int bufferSize,
|
||||
IProgress<long>? progress = null,
|
||||
this Stream stream, Stream destination, int bufferSize,
|
||||
IProgress<long>? progress = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (stream == null) throw new ArgumentNullException(nameof(stream));
|
||||
@@ -76,7 +76,7 @@ public static class Functions
|
||||
progress?.Report(totalBytesRead);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static T SelectRandomValueOf<T>()
|
||||
{
|
||||
|
||||
@@ -38,10 +38,10 @@ public class JsonManager
|
||||
else
|
||||
text = new MemoryStream(Encoding.ASCII.GetBytes(input));
|
||||
text.Position = 0;
|
||||
|
||||
|
||||
var obj = await JsonSerializer.DeserializeAsync<T>(text);
|
||||
await text.FlushAsync();
|
||||
text.Close();
|
||||
return (obj ?? default)!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,60 +4,46 @@ using PluginManager.Interfaces.Logger;
|
||||
|
||||
namespace PluginManager.Others.Logger;
|
||||
|
||||
public class Log : ILog
|
||||
public class Log: ILog
|
||||
{
|
||||
public string Message { get; set; }
|
||||
public string OutputFile { get; set; }
|
||||
public Type? Source { get; set; }
|
||||
public LogType Type { get; set; }
|
||||
public DateTime ThrowTime { get; set; }
|
||||
|
||||
public Log(string message, string outputFile, Type? source, LogType type, DateTime throwTime)
|
||||
public string Message { get; set; }
|
||||
public Type? Source { get; set; }
|
||||
public LogType Type { get; set; }
|
||||
public DateTime ThrowTime { get; set; }
|
||||
|
||||
public Log(string message, Type? source, LogType type, DateTime throwTime)
|
||||
{
|
||||
Message = message;
|
||||
OutputFile = outputFile;
|
||||
Source = source;
|
||||
Type = type;
|
||||
ThrowTime = throwTime;
|
||||
Message = message;
|
||||
Source = source;
|
||||
Type = type;
|
||||
ThrowTime = throwTime;
|
||||
}
|
||||
|
||||
public Log(string message, string outputFile, Type? source, LogType type)
|
||||
|
||||
public Log(string message, Type? source, LogType type)
|
||||
{
|
||||
Message = message;
|
||||
OutputFile = outputFile;
|
||||
Source = source;
|
||||
Type = type;
|
||||
ThrowTime = DateTime.Now;
|
||||
Message = message;
|
||||
Source = source;
|
||||
Type = type;
|
||||
ThrowTime = DateTime.Now;
|
||||
}
|
||||
|
||||
public Log(string message, string outputFile, Type? source)
|
||||
|
||||
public Log(string message, Type? source)
|
||||
{
|
||||
Message = message;
|
||||
OutputFile = outputFile;
|
||||
Source = source;
|
||||
Type = LogType.INFO;
|
||||
ThrowTime = DateTime.Now;
|
||||
Message = message;
|
||||
Source = source;
|
||||
Type = LogType.INFO;
|
||||
ThrowTime = DateTime.Now;
|
||||
}
|
||||
|
||||
public Log(string message, string outputFile)
|
||||
{
|
||||
Message = message;
|
||||
OutputFile = outputFile;
|
||||
Source = typeof(Log);
|
||||
Type = LogType.INFO;
|
||||
ThrowTime = DateTime.Now;
|
||||
}
|
||||
|
||||
|
||||
public Log(string message)
|
||||
{
|
||||
Message = message;
|
||||
OutputFile = "";
|
||||
Source = typeof(Log);
|
||||
Type = LogType.INFO;
|
||||
ThrowTime = DateTime.Now;
|
||||
Message = message;
|
||||
Source = typeof(Log);
|
||||
Type = LogType.INFO;
|
||||
ThrowTime = DateTime.Now;
|
||||
}
|
||||
|
||||
public static implicit operator Log(string message) => new (message);
|
||||
|
||||
public static implicit operator Log(string message) => new(message);
|
||||
|
||||
public static implicit operator string(Log log) => $"[{log.ThrowTime}] {log.Message}";
|
||||
|
||||
@@ -65,7 +51,7 @@ public class Log : ILog
|
||||
{
|
||||
return $"[{ThrowTime}] [{Source}] [{Type}] {Message}";
|
||||
}
|
||||
|
||||
|
||||
public string AsShortString()
|
||||
{
|
||||
return this;
|
||||
|
||||
@@ -6,64 +6,72 @@ using PluginManager.Interfaces.Logger;
|
||||
|
||||
namespace PluginManager.Others.Logger;
|
||||
|
||||
public sealed class Logger : ILogger
|
||||
public sealed class Logger: ILogger
|
||||
{
|
||||
public bool IsEnabled { get; init; }
|
||||
public bool OutputToFile { get; init; }
|
||||
public bool IsEnabled { get; init; }
|
||||
public bool OutputToFile { get; init; }
|
||||
public string? OutputFile { get; init; }
|
||||
|
||||
private LogType LowestLogLevel { get; }
|
||||
private bool UseShortVersion { get; }
|
||||
|
||||
public Logger(bool useShortVersion, bool outputToFile, LogType lowestLogLevel = LogType.INFO)
|
||||
private LogType LowestLogLevel { get; }
|
||||
private bool UseShortVersion { get; }
|
||||
|
||||
public Logger(bool useShortVersion, bool outputToFile, string outputFile, LogType lowestLogLevel = LogType.INFO)
|
||||
{
|
||||
UseShortVersion = useShortVersion;
|
||||
OutputToFile = outputToFile;
|
||||
IsEnabled = true;
|
||||
LowestLogLevel = lowestLogLevel;
|
||||
OutputFile = outputFile;
|
||||
}
|
||||
|
||||
public Logger(bool useShortVersion, LogType lowestLogLevel = LogType.INFO)
|
||||
{
|
||||
UseShortVersion = useShortVersion;
|
||||
OutputToFile = false;
|
||||
IsEnabled = true;
|
||||
LowestLogLevel = lowestLogLevel;
|
||||
OutputFile = null;
|
||||
}
|
||||
|
||||
public event EventHandler<Log>? OnLog;
|
||||
|
||||
|
||||
private async Task Log(Log logMessage)
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
|
||||
|
||||
OnLog?.Invoke(this, logMessage);
|
||||
|
||||
|
||||
if (logMessage.Type < LowestLogLevel) return;
|
||||
|
||||
if (OutputToFile)
|
||||
await File.AppendAllTextAsync(
|
||||
logMessage.OutputFile,
|
||||
(UseShortVersion ? logMessage : logMessage.AsLongString()) + "\n");
|
||||
OutputFile!,
|
||||
(UseShortVersion ? logMessage : logMessage.AsLongString()) + "\n"
|
||||
);
|
||||
}
|
||||
|
||||
public async void Log(string message = "", string outputFile = "", Type? source = default, LogType type = LogType.INFO, DateTime throwTime = default)
|
||||
|
||||
public async void Log(string message = "", Type? source = default, LogType type = LogType.INFO, DateTime throwTime = default)
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
|
||||
|
||||
if (type < LowestLogLevel) return;
|
||||
|
||||
if (string.IsNullOrEmpty(message)) return;
|
||||
|
||||
if (string.IsNullOrEmpty(outputFile)) outputFile = Config.AppSettings["LogFolder"] + "/" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
|
||||
|
||||
if(throwTime == default) throwTime = DateTime.Now;
|
||||
|
||||
if (throwTime == default) throwTime = DateTime.Now;
|
||||
|
||||
if (source == default) source = typeof(Log);
|
||||
|
||||
await Log(new Log(message, outputFile, source, type, throwTime));
|
||||
|
||||
|
||||
await Log(new Log(message, source, type, throwTime));
|
||||
|
||||
}
|
||||
|
||||
public async void Log(Exception exception, LogType logType = LogType.ERROR, Type? source = null)
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
|
||||
|
||||
if (logType < LowestLogLevel) return;
|
||||
|
||||
await Log(new Log(exception.Message,
|
||||
Config.AppSettings["LogFolder"] + "/" + DateTime.Now.ToString("yyyy-MM-dd") + ".log",
|
||||
source, logType, DateTime.Now));
|
||||
await Log(new Log(exception.Message, source, logType, DateTime.Now));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace PluginManager.Others;
|
||||
|
||||
public class SettingsDictionary<TKey, TValue> : IDictionary<TKey, TValue>
|
||||
public class SettingsDictionary<TKey, TValue>: IDictionary<TKey, TValue>
|
||||
{
|
||||
public string? _file { get; }
|
||||
private IDictionary<TKey, TValue>? _dictionary;
|
||||
|
||||
|
||||
public SettingsDictionary(string? file)
|
||||
{
|
||||
_file = file;
|
||||
@@ -19,7 +19,7 @@ public class SettingsDictionary<TKey, TValue> : IDictionary<TKey, TValue>
|
||||
SaveToFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task SaveToFile()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_file))
|
||||
@@ -36,8 +36,8 @@ public class SettingsDictionary<TKey, TValue> : IDictionary<TKey, TValue>
|
||||
string FileContent = File.ReadAllText(_file);
|
||||
if (string.IsNullOrEmpty(FileContent))
|
||||
File.WriteAllText(_file, "{}");
|
||||
|
||||
if(!FileContent.Contains("{") || !FileContent.Contains("}"))
|
||||
|
||||
if (!FileContent.Contains("{") || !FileContent.Contains("}"))
|
||||
File.WriteAllText(_file, "{}");
|
||||
}
|
||||
else
|
||||
@@ -61,7 +61,7 @@ public class SettingsDictionary<TKey, TValue> : IDictionary<TKey, TValue>
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable) _dictionary!).GetEnumerator();
|
||||
return ((IEnumerable)_dictionary!).GetEnumerator();
|
||||
}
|
||||
|
||||
public void Add(KeyValuePair<TKey, TValue> item)
|
||||
@@ -89,7 +89,7 @@ public class SettingsDictionary<TKey, TValue> : IDictionary<TKey, TValue>
|
||||
return this._dictionary!.Remove(item);
|
||||
}
|
||||
|
||||
public int Count => _dictionary!.Count;
|
||||
public int Count => _dictionary!.Count;
|
||||
public bool IsReadOnly => _dictionary!.IsReadOnly;
|
||||
public void Add(TKey key, TValue value)
|
||||
{
|
||||
@@ -116,9 +116,9 @@ public class SettingsDictionary<TKey, TValue> : IDictionary<TKey, TValue>
|
||||
get
|
||||
{
|
||||
if (this._dictionary!.ContainsKey(key))
|
||||
if(this._dictionary[key] is string s && !string.IsNullOrEmpty(s) && !string.IsNullOrWhiteSpace(s))
|
||||
if (this._dictionary[key] is string s && !string.IsNullOrEmpty(s) && !string.IsNullOrWhiteSpace(s))
|
||||
return this._dictionary[key];
|
||||
|
||||
|
||||
return default!;
|
||||
}
|
||||
set => this._dictionary![key] = value;
|
||||
@@ -126,4 +126,4 @@ public class SettingsDictionary<TKey, TValue> : IDictionary<TKey, TValue>
|
||||
|
||||
public ICollection<TKey> Keys => _dictionary!.Keys;
|
||||
public ICollection<TValue> Values => _dictionary!.Values;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user