Updated API for plugins to work with database from remote. Added PluginRepository and removed Installation Scripts

This commit is contained in:
2025-01-26 20:34:34 +02:00
parent 8b2169dc7b
commit 84b19e2069
35 changed files with 435 additions and 1056 deletions

View File

@@ -6,7 +6,9 @@ namespace DiscordBotCore.Plugin;
public class OnlineDependencyInfo
{
public string DependencyName { get; private set; }
[JsonPropertyName("dependencyLink")]
public string DownloadLink { get; private set; }
[JsonPropertyName("dependencyLocation")]
public string DownloadLocation { get; private set; }
public bool IsExecutable { get; private set; }

View File

@@ -0,0 +1,27 @@
using System.Text.Json.Serialization;
namespace DiscordBotCore.Plugin;
public class OnlinePlugin
{
public int PluginId { get; private set; }
public string PluginName { get; private set; }
public string PluginDescription { get; private set; }
public string LatestVersion { get; private set; }
public string PluginAuthor { get; private set; }
public string PluginLink { get; private set; }
public int OperatingSystem { get; private set; }
[JsonConstructor]
public OnlinePlugin(int pluginId, string pluginName, string pluginDescription, string latestVersion,
string pluginAuthor, string pluginLink, int operatingSystem)
{
PluginId = pluginId;
PluginName = pluginName;
PluginDescription = pluginDescription;
LatestVersion = latestVersion;
PluginAuthor = pluginAuthor;
PluginLink = pluginLink;
OperatingSystem = operatingSystem;
}
}

View File

@@ -1,14 +0,0 @@
namespace DiscordBotCore.Plugin
{
public class OnlineScriptDependencyInfo
{
public string DependencyName { get; private set; }
public string ScriptContent { get; private set; }
public OnlineScriptDependencyInfo(string dependencyName, string scriptContent)
{
DependencyName = dependencyName;
ScriptContent = scriptContent;
}
}
}

View File

@@ -8,7 +8,7 @@ namespace DiscordBotCore.Plugin;
public class PluginInfo
{
public string PluginName { get; private set; }
public PluginVersion PluginVersion { get; private set; }
public string PluginVersion { get; private set; }
public string FilePath { get; private set; }
public Dictionary<string, string> ListOfExecutableDependencies {get; private set;}
public bool IsMarkedToUninstall {get; internal set;}
@@ -16,7 +16,7 @@ public class PluginInfo
public bool IsEnabled { get; internal set; }
[JsonConstructor]
public PluginInfo(string pluginName, PluginVersion pluginVersion, Dictionary<string, string> listOfExecutableDependencies, bool isMarkedToUninstall, bool isOfflineAdded, bool isEnabled)
public PluginInfo(string pluginName, string pluginVersion, Dictionary<string, string> listOfExecutableDependencies, bool isMarkedToUninstall, bool isOfflineAdded, bool isEnabled)
{
PluginName = pluginName;
PluginVersion = pluginVersion;
@@ -27,7 +27,7 @@ public class PluginInfo
IsEnabled = isEnabled;
}
public PluginInfo(string pluginName, PluginVersion pluginVersion, Dictionary<string, string> listOfExecutableDependencies)
public PluginInfo(string pluginName, string pluginVersion, Dictionary<string, string> listOfExecutableDependencies)
{
PluginName = pluginName;
PluginVersion = pluginVersion;
@@ -38,21 +38,14 @@ public class PluginInfo
IsEnabled = true;
}
public static PluginInfo FromOnlineInfo(PluginOnlineInfo onlineInfo)
public static PluginInfo FromOnlineInfo(OnlinePlugin plugin, List<OnlineDependencyInfo> dependencies)
{
var pluginName = onlineInfo.Name;
var version = onlineInfo.Version;
var dependencies= onlineInfo.Dependencies;
if(dependencies is null)
{
return new PluginInfo(pluginName, version, new Dictionary<string, string>());
}
var executableDependencies = dependencies.Where(dep => dep.IsExecutable);
var dictDependencies = executableDependencies.Select(dep => new KeyValuePair<string, string>(dep.DependencyName, dep.DownloadLocation)).ToDictionary();
return new PluginInfo(pluginName, version, dictDependencies);
PluginInfo pluginInfo = new PluginInfo(
plugin.PluginName, plugin.LatestVersion,
dependencies.Where(dependency => dependency.IsExecutable)
.ToDictionary(dependency => dependency.DependencyName, dependency => dependency.DownloadLocation)
);
return pluginInfo;
}
}

View File

@@ -1,56 +0,0 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using DiscordBotCore.Online.Helpers;
using DiscordBotCore.Others;
namespace DiscordBotCore.Plugin;
public class PluginOnlineInfo
{
public string Name { get; private set; }
public string Author { get; private set; }
public PluginVersion Version { get; private set; }
public string DownLoadLink { get; private set; }
public string Description { get; private set; }
public List<OnlineDependencyInfo>? Dependencies { get; private set; }
public List<OnlineScriptDependencyInfo>? ScriptDependencies { get; private set; }
public OSType SupportedOS { get; private set; }
public bool HasFileDependencies => Dependencies is not null && Dependencies.Count > 0;
public bool HasScriptDependencies => ScriptDependencies is not null && ScriptDependencies.Count > 0;
[JsonConstructor]
public PluginOnlineInfo(string name, string author, PluginVersion version, string description, string downLoadLink, OSType supportedOS, List<OnlineDependencyInfo> dependencies, List<OnlineScriptDependencyInfo> scriptDependencies)
{
Name = name;
Author = author;
Version = version;
Description = description;
DownLoadLink = downLoadLink;
SupportedOS = supportedOS;
Dependencies = dependencies;
ScriptDependencies = scriptDependencies;
}
public PluginOnlineInfo(string name, string author, PluginVersion version, string description, string downLoadLink, OSType supportedOS)
{
Name = name;
Author = author;
Version = version;
Description = description;
DownLoadLink = downLoadLink;
SupportedOS = supportedOS;
Dependencies = new List<OnlineDependencyInfo>();
ScriptDependencies = new List<OnlineScriptDependencyInfo>();
}
public static async Task<PluginOnlineInfo> FromRawData(string jsonText)
{
return await JsonManager.ConvertFromJson<PluginOnlineInfo>(jsonText);
}
public override string ToString()
{
return $"{Name} <{Author}> - {Version} ({Description})";
}
}