Merged projects with plugins and modules

This commit is contained in:
2024-07-22 01:18:00 +03:00
parent 1fd065f4c2
commit 8ace51c840
59 changed files with 1669 additions and 73 deletions

View File

@@ -107,7 +107,7 @@ public class App
if (arg.Message.Contains("401"))
{
Application.CurrentApplication.ApplicationEnvironmentVariables.Remove("token");
Application.CurrentApplication.Logger.Log("The token is invalid.", this, LogType.CRITICAL);
Application.CurrentApplication.Logger.Log("The token is invalid.", this, LogType.Critical);
await Application.CurrentApplication.ApplicationEnvironmentVariables.SaveToFile();
await Task.Delay(3000);
@@ -134,12 +134,12 @@ public class App
{
case LogSeverity.Error:
case LogSeverity.Critical:
Application.CurrentApplication.Logger.Log(message.Message, this, LogType.ERROR);
Application.CurrentApplication.Logger.Log(message.Message, this, LogType.Error);
break;
case LogSeverity.Info:
case LogSeverity.Debug:
Application.CurrentApplication.Logger.Log(message.Message, this, LogType.INFO);
Application.CurrentApplication.Logger.Log(message.Message, this, LogType.Info);
break;

View File

@@ -141,9 +141,9 @@ internal class CommandHandler
DbCommandExecutingArguments cmd = new(context, cleanMessage, split[0], argsClean);
Application.CurrentApplication.Logger.Log(
$"User ({context.User.Username}) from Guild \"{context.Guild.Name}\" executed command \"{cmd.cleanContent}\"",
$"User ({context.User.Username}) from Guild \"{context.Guild.Name}\" executed command \"{cmd.CleanContent}\"",
this,
LogType.INFO
LogType.Info
);
if (context.Channel is SocketDMChannel)

View File

@@ -41,7 +41,7 @@ public class PluginLoader
if (_Client == null)
{
Application.CurrentApplication.Logger.Log("Discord client is null", this, LogType.ERROR);
Application.CurrentApplication.Logger.Log("Discord client is null", this, LogType.Error);
return;
}
@@ -62,7 +62,7 @@ public class PluginLoader
private void FileLoadedException(FileLoaderResult result)
{
Application.CurrentApplication.Logger.Log(result.ErrorMessage, this, LogType.ERROR);
Application.CurrentApplication.Logger.Log(result.ErrorMessage, this, LogType.Error);
}
private async void OnPluginLoaded(PluginLoadResultData result)
@@ -71,10 +71,10 @@ public class PluginLoader
{
case PluginType.ACTION:
ICommandAction action = (ICommandAction)result.Plugin;
if (action.RunType == InternalActionRunType.ON_STARTUP || action.RunType == InternalActionRunType.BOTH)
if (action.RunType == InternalActionRunType.OnStartup || action.RunType == InternalActionRunType.OnStartupAndCall)
action.Execute(null);
if(action.RunType == InternalActionRunType.ON_CALL || action.RunType == InternalActionRunType.BOTH)
if(action.RunType == InternalActionRunType.OnCall || action.RunType == InternalActionRunType.OnStartupAndCall)
Actions.Add(action);
OnActionLoaded?.Invoke(result);
@@ -101,11 +101,11 @@ public class PluginLoader
OnSlashCommandLoaded?.Invoke(result);
}
else
Application.CurrentApplication.Logger.Log($"Failed to start slash command {result.PluginName}", this, LogType.ERROR);
Application.CurrentApplication.Logger.Log($"Failed to start slash command {result.PluginName}", this, LogType.Error);
break;
case PluginType.UNKNOWN:
default:
Application.CurrentApplication.Logger.Log("Unknown plugin type", this, LogType.ERROR);
Application.CurrentApplication.Logger.Log("Unknown plugin type", this, LogType.Error);
break;
}
}

View File

@@ -26,7 +26,7 @@ internal static class PluginLoaderExtensions
}
catch (Exception e)
{
Application.CurrentApplication.Logger.Log($"Error starting event {dbEvent.Name}: {e.Message}", typeof(PluginLoader), LogType.ERROR);
Application.CurrentApplication.Logger.Log($"Error starting event {dbEvent.Name}: {e.Message}", typeof(PluginLoader), LogType.Error);
Application.CurrentApplication.Logger.LogException(e, typeof(PluginLoader));
return false;
}
@@ -39,14 +39,14 @@ internal static class PluginLoaderExtensions
if(pluginLoader._Client.Guilds.Count == 0) return;
if (!ulong.TryParse(Application.CurrentApplication.ServerID, out _))
{
Application.CurrentApplication.Logger.Log("Invalid ServerID in config file. Can not reset specific guild commands", typeof(PluginLoader), LogType.ERROR);
Application.CurrentApplication.Logger.Log("Invalid ServerID in config file. Can not reset specific guild commands", typeof(PluginLoader), LogType.Error);
return;
}
SocketGuild? guild = pluginLoader._Client.GetGuild(ulong.Parse(Application.CurrentApplication.ServerID));
if(guild is null)
{
Application.CurrentApplication.Logger.Log("Failed to get guild with ID " + Application.CurrentApplication.ServerID, typeof(PluginLoader), LogType.ERROR);
Application.CurrentApplication.Logger.Log("Failed to get guild with ID " + Application.CurrentApplication.ServerID, typeof(PluginLoader), LogType.Error);
return;
}
@@ -79,7 +79,7 @@ internal static class PluginLoaderExtensions
SocketGuild? guild = pluginLoader._Client.GetGuild(result);
if (guild is null)
{
Application.CurrentApplication.Logger.Log("Failed to get guild with ID " + Application.CurrentApplication.ServerID, typeof(PluginLoader), LogType.ERROR);
Application.CurrentApplication.Logger.Log("Failed to get guild with ID " + Application.CurrentApplication.ServerID, typeof(PluginLoader), LogType.Error);
return false;
}
@@ -90,7 +90,7 @@ internal static class PluginLoaderExtensions
}
catch (Exception e)
{
Application.CurrentApplication.Logger.Log($"Error starting slash command {dbSlashCommand.Name}: {e.Message}", typeof(PluginLoader), LogType.ERROR);
Application.CurrentApplication.Logger.Log($"Error starting slash command {dbSlashCommand.Name}: {e.Message}", typeof(PluginLoader), LogType.Error);
return false;
}
}

View File

@@ -119,7 +119,7 @@ public class PluginManager : IPluginManager
{
if (await pluginUpdater.HasUpdate(plugin.PluginName))
{
Application.CurrentApplication.Logger.Log("Updating plugin: " + plugin.PluginName, this, LogType.INFO);
Application.CurrentApplication.Logger.Log("Updating plugin: " + plugin.PluginName, this, LogType.Info);
await pluginUpdater.UpdatePlugin(plugin.PluginName);
}
}

View File

@@ -16,12 +16,12 @@ public class InternalActionManager
PluginLoader.Actions.ForEach(action =>
{
if (action.RunType == InternalActionRunType.ON_CALL || action.RunType == InternalActionRunType.BOTH)
if (action.RunType == InternalActionRunType.OnCall || action.RunType == InternalActionRunType.OnStartupAndCall)
{
if (this.Actions.ContainsKey(action.ActionName))
{
// This should never happen. If it does, log it and return
Application.CurrentApplication.Logger.Log($"Action {action.ActionName} already exists", this, LogType.ERROR);
Application.CurrentApplication.Logger.Log($"Action {action.ActionName} already exists", this, LogType.Error);
return;
}
@@ -49,15 +49,15 @@ public class InternalActionManager
{
if (!Actions.ContainsKey(actionName))
{
Application.CurrentApplication.Logger.Log($"Action {actionName} not found", this, LogType.ERROR);
Application.CurrentApplication.Logger.Log($"Action {actionName} not found", this, LogType.Error);
return false;
}
try
{
if (Actions[actionName].RunType == InternalActionRunType.ON_STARTUP)
if (Actions[actionName].RunType == InternalActionRunType.OnStartup)
{
Application.CurrentApplication.Logger.Log($"Action {actionName} is not executable", this, LogType.ERROR);
Application.CurrentApplication.Logger.Log($"Action {actionName} is not executable", this, LogType.Error);
return false;
}
@@ -66,7 +66,7 @@ public class InternalActionManager
}
catch (Exception e)
{
Application.CurrentApplication.Logger.Log(e.Message, type: LogType.ERROR, Sender: this);
Application.CurrentApplication.Logger.Log(e.Message, type: LogType.Error, Sender: this);
return false;
}
}

View File

@@ -87,7 +87,7 @@ public static class ArchiveManager
}
catch (Exception ex)
{
Application.CurrentApplication.Logger.Log(ex.Message, typeof(ArchiveManager), LogType.ERROR); // Write the error to a file
Application.CurrentApplication.Logger.Log(ex.Message, typeof(ArchiveManager), LogType.Error); // Write the error to a file
await Task.Delay(100);
return await ReadFromPakAsync(fileName, archFile);
}
@@ -123,7 +123,7 @@ public static class ArchiveManager
}
catch (Exception ex)
{
Application.CurrentApplication.Logger.Log(ex.Message, typeof(ArchiveManager), LogType.ERROR);
Application.CurrentApplication.Logger.Log(ex.Message, typeof(ArchiveManager), LogType.Error);
}
currentZipFile++;
@@ -158,7 +158,7 @@ public static class ArchiveManager
}
catch (Exception ex)
{
Application.CurrentApplication.Logger.Log(ex.Message, typeof(ArchiveManager), LogType.ERROR);
Application.CurrentApplication.Logger.Log(ex.Message, typeof(ArchiveManager), LogType.Error);
}
await Task.Delay(10);

View File

@@ -7,42 +7,42 @@ namespace DiscordBotCore.Others;
public class DbCommandExecutingArguments
{
public SocketCommandContext context { get; init; }
public string cleanContent { get; init; }
public string commandUsed { get; init; }
public string[]? arguments { get; init; }
public ISocketMessageChannel Channel => context.Channel;
public SocketCommandContext Context { get; init; }
public string CleanContent { get; init; }
public string CommandUsed { get; init; }
public string[]? Arguments { get; init; }
public ISocketMessageChannel Channel => Context.Channel;
public DbCommandExecutingArguments(
SocketCommandContext context, string cleanContent, string commandUsed, string[]? arguments)
{
this.context = context;
this.cleanContent = cleanContent;
this.commandUsed = commandUsed;
this.arguments = arguments;
this.Context = context;
this.CleanContent = cleanContent;
this.CommandUsed = commandUsed;
this.Arguments = arguments;
}
public DbCommandExecutingArguments(SocketUserMessage? message, DiscordSocketClient client)
{
context = new SocketCommandContext(client, message);
Context = new SocketCommandContext(client, message);
var pos = 0;
if (message.HasMentionPrefix(client.CurrentUser, ref pos))
{
var mentionPrefix = "<@" + client.CurrentUser.Id + ">";
cleanContent = message.Content.Substring(mentionPrefix.Length + 1);
CleanContent = message.Content.Substring(mentionPrefix.Length + 1);
}
else
{
cleanContent = message.Content.Substring(Application.CurrentApplication.DiscordBotClient.BotPrefix.Length);
CleanContent = message.Content.Substring(Application.CurrentApplication.DiscordBotClient.BotPrefix.Length);
}
var split = cleanContent.Split(' ');
var split = CleanContent.Split(' ');
string[]? argsClean = null;
if (split.Length > 1)
argsClean = string.Join(' ', split, 1, split.Length - 1).Split(' ');
commandUsed = split[0];
arguments = argsClean;
CommandUsed = split[0];
Arguments = argsClean;
}
}

View File

@@ -7,10 +7,10 @@ namespace DiscordBotCore.Others;
/// </summary>
public enum LogType
{
INFO,
WARNING,
ERROR,
CRITICAL
Info,
Warning,
Error,
Critical
}
public enum UnzipProgressType
@@ -21,9 +21,9 @@ public enum UnzipProgressType
public enum InternalActionRunType
{
ON_STARTUP,
ON_CALL,
BOTH
OnStartup,
OnCall,
OnStartupAndCall
}
[Flags]