Added pages for module and plugin download
This commit is contained in:
@@ -40,11 +40,19 @@ public class PluginInfo
|
|||||||
|
|
||||||
public static PluginInfo FromOnlineInfo(PluginOnlineInfo onlineInfo)
|
public static PluginInfo FromOnlineInfo(PluginOnlineInfo onlineInfo)
|
||||||
{
|
{
|
||||||
return new PluginInfo(onlineInfo.Name,
|
var pluginName = onlineInfo.Name;
|
||||||
onlineInfo.Version,
|
var version = onlineInfo.Version;
|
||||||
onlineInfo.Dependencies
|
var dependencies= onlineInfo.Dependencies;
|
||||||
.Where(dep => dep.IsExecutable)
|
|
||||||
.Select(dep => new KeyValuePair<string, string>(dep.DependencyName, dep.DownloadLocation))
|
if(dependencies is null)
|
||||||
.ToDictionary());
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,19 +9,21 @@ namespace DiscordBotCore.Plugin;
|
|||||||
public class PluginOnlineInfo
|
public class PluginOnlineInfo
|
||||||
{
|
{
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
|
public string Author { get; private set; }
|
||||||
public PluginVersion Version { get; private set; }
|
public PluginVersion Version { get; private set; }
|
||||||
public string DownLoadLink { get; private set; }
|
public string DownLoadLink { get; private set; }
|
||||||
public string Description { get; private set; }
|
public string Description { get; private set; }
|
||||||
public List<OnlineDependencyInfo> Dependencies { get; private set; }
|
public List<OnlineDependencyInfo>? Dependencies { get; private set; }
|
||||||
public List<OnlineScriptDependencyInfo> ScriptDependencies { get; private set; }
|
public List<OnlineScriptDependencyInfo>? ScriptDependencies { get; private set; }
|
||||||
public OSType SupportedOS { get; private set; }
|
public OSType SupportedOS { get; private set; }
|
||||||
public bool HasFileDependencies => Dependencies is not null && Dependencies.Count > 0;
|
public bool HasFileDependencies => Dependencies is not null && Dependencies.Count > 0;
|
||||||
public bool HasScriptDependencies => ScriptDependencies is not null && ScriptDependencies.Count > 0;
|
public bool HasScriptDependencies => ScriptDependencies is not null && ScriptDependencies.Count > 0;
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public PluginOnlineInfo(string name, PluginVersion version, string description, string downLoadLink, OSType supportedOS, List<OnlineDependencyInfo> dependencies, List<OnlineScriptDependencyInfo> scriptDependencies)
|
public PluginOnlineInfo(string name, string author, PluginVersion version, string description, string downLoadLink, OSType supportedOS, List<OnlineDependencyInfo> dependencies, List<OnlineScriptDependencyInfo> scriptDependencies)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
|
Author = author;
|
||||||
Version = version;
|
Version = version;
|
||||||
Description = description;
|
Description = description;
|
||||||
DownLoadLink = downLoadLink;
|
DownLoadLink = downLoadLink;
|
||||||
@@ -30,9 +32,10 @@ public class PluginOnlineInfo
|
|||||||
ScriptDependencies = scriptDependencies;
|
ScriptDependencies = scriptDependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginOnlineInfo(string name, PluginVersion version, string description, string downLoadLink, OSType supportedOS)
|
public PluginOnlineInfo(string name, string author, PluginVersion version, string description, string downLoadLink, OSType supportedOS)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
|
Author = author;
|
||||||
Version = version;
|
Version = version;
|
||||||
Description = description;
|
Description = description;
|
||||||
DownLoadLink = downLoadLink;
|
DownLoadLink = downLoadLink;
|
||||||
@@ -48,6 +51,6 @@ public class PluginOnlineInfo
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{Name} - {Version} ({Description})";
|
return $"{Name} <{Author}> - {Version} ({Description})";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
@using DiscordBotCore.Plugin
|
@using DiscordBotCore.Plugin
|
||||||
@using DiscordBotWebUI.Types
|
@using DiscordBotWebUI.Types
|
||||||
|
|
||||||
@inject DialogService DialogService
|
|
||||||
|
|
||||||
<RadzenDataGrid AllowColumnResize="true" PageSize="5" AllowPaging="true" PagerHorizontalAlign="HorizontalAlign.Left" Data="ListedItems">
|
<RadzenDataGrid AllowColumnResize="true" PageSize="5" AllowPaging="true" PagerHorizontalAlign="HorizontalAlign.Left" Data="ListedItems">
|
||||||
<Columns>
|
<Columns>
|
||||||
<RadzenDataGridColumn Property="@nameof(MarketItem.Name)" Title="Item Name"></RadzenDataGridColumn>
|
<RadzenDataGridColumn Property="@nameof(MarketItem.Name)" Title="Item Name"></RadzenDataGridColumn>
|
||||||
@@ -50,8 +48,6 @@
|
|||||||
});
|
});
|
||||||
await Application.CurrentApplication.ModuleManager.InstallModule(moduleName, downloadProgress);
|
await Application.CurrentApplication.ModuleManager.InstallModule(moduleName, downloadProgress);
|
||||||
_ProgressBarVisible = false;
|
_ProgressBarVisible = false;
|
||||||
|
|
||||||
DialogService.Close(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task DownloadPlugin(string pluginName)
|
private async Task DownloadPlugin(string pluginName)
|
||||||
@@ -68,7 +64,5 @@
|
|||||||
await Application.CurrentApplication.PluginManager.InstallPlugin(pluginInfo, downloadProgress);
|
await Application.CurrentApplication.PluginManager.InstallPlugin(pluginInfo, downloadProgress);
|
||||||
|
|
||||||
_ProgressBarVisible = false;
|
_ProgressBarVisible = false;
|
||||||
|
|
||||||
DialogService.Close(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,13 +21,13 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<NavLink class="nav-link" href="/settings" Match="NavLinkMatch.All">
|
<NavLink class="nav-link" href="/market/plugins" Match="NavLinkMatch.All">
|
||||||
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Plugins
|
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Plugins
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nav-item px-3">
|
<div class="nav-item px-3">
|
||||||
<NavLink class="nav-link" href="/settings" Match="NavLinkMatch.All">
|
<NavLink class="nav-link" href="/market/modules" Match="NavLinkMatch.All">
|
||||||
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Modules
|
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Modules
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,6 +13,14 @@
|
|||||||
@code {
|
@code {
|
||||||
private string? _TextValue;
|
private string? _TextValue;
|
||||||
|
|
||||||
|
private DiscordBotStartup _DiscordBotStartup = null!;
|
||||||
|
|
||||||
|
protected override async void OnInitialized()
|
||||||
|
{
|
||||||
|
_DiscordBotStartup = new DiscordBotStartup(FixModules);
|
||||||
|
await _DiscordBotStartup.CreateApplication();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task FixModules(ModuleRequirement requirements)
|
private async Task FixModules(ModuleRequirement requirements)
|
||||||
{
|
{
|
||||||
if(!requirements.RequireAny)
|
if(!requirements.RequireAny)
|
||||||
@@ -27,19 +35,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async void Initialize()
|
private async void Initialize()
|
||||||
{
|
{
|
||||||
DiscordBotStartup setup = new DiscordBotStartup(FixModules);
|
_DiscordBotStartup.Log += async (sender, str) => {
|
||||||
|
|
||||||
setup.Log += async (sender, str) => {
|
|
||||||
_TextValue += str + "\n";
|
_TextValue += str + "\n";
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
};
|
};
|
||||||
|
|
||||||
dynamic result = await setup.LoadComponents();
|
dynamic result = _DiscordBotStartup.LoadComponents();
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
result = await DialogService.OpenAsync<FirstSetup>("Please complete this setup before starting the bot", new Dictionary<string, object>());
|
result = await DialogService.OpenAsync<Settings>("Please complete this setup before starting the bot", new Dictionary<string, object>());
|
||||||
|
|
||||||
if (result != true)
|
if (result != true)
|
||||||
{
|
{
|
||||||
@@ -47,7 +53,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await setup.PrepareBot();
|
await _DiscordBotStartup.PrepareBot();
|
||||||
await setup.RefreshPlugins(false);
|
await _DiscordBotStartup.RefreshPlugins(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
@page "/market/modules"
|
||||||
|
@using DiscordBotCore
|
||||||
|
@using DiscordBotWebUI.Types
|
||||||
|
@using DiscordBotWebUI.Components.Items
|
||||||
|
|
||||||
|
@if(_MarketItems is not null && _MarketItems.Any())
|
||||||
|
{
|
||||||
|
<Marketplace ListedItems="_MarketItems"/>
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
<RadzenText Text="There are no modules available right now ..."></RadzenText>
|
||||||
|
}
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private readonly List<MarketItem>? _MarketItems = new List<MarketItem>();
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
var modules = await Application.CurrentApplication.ModuleManager.ServerGetAllModules();
|
||||||
|
foreach(var onlineModule in modules)
|
||||||
|
{
|
||||||
|
var item = new MarketItem(onlineModule.ModuleName, onlineModule.ModuleAuthor, onlineModule.ModuleDescription, ItemType.Module);
|
||||||
|
_MarketItems.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
@page "/market/plugins"
|
||||||
|
@using DiscordBotCore
|
||||||
|
@using DiscordBotWebUI.Types
|
||||||
|
@using DiscordBotWebUI.Components.Items
|
||||||
|
|
||||||
|
@if(_MarketItems is null)
|
||||||
|
{
|
||||||
|
<RadzenText Text="There are no plugins available right now ..."></RadzenText>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if(_MarketItems is not null && _MarketItems.Any())
|
||||||
|
{
|
||||||
|
<Marketplace ListedItems="_MarketItems"/>
|
||||||
|
}
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private List<MarketItem>? _MarketItems;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
var plugins = await Application.CurrentApplication.PluginManager.GetPluginsList();
|
||||||
|
|
||||||
|
if(plugins is null)
|
||||||
|
{
|
||||||
|
_MarketItems = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_MarketItems = new List<MarketItem>();
|
||||||
|
|
||||||
|
foreach (var onlinePlugin in plugins)
|
||||||
|
{
|
||||||
|
var marketItem = new MarketItem(onlinePlugin.Name, onlinePlugin.Author, onlinePlugin.Description, ItemType.Plugin);
|
||||||
|
_MarketItems.Add(marketItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-7
@@ -1,5 +1,5 @@
|
|||||||
@using DiscordBotCore
|
@page "/settings"
|
||||||
@inject DialogService DialogService
|
@using DiscordBotCore
|
||||||
|
|
||||||
<RadzenPanel>
|
<RadzenPanel>
|
||||||
<HeaderTemplate>
|
<HeaderTemplate>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<RadzenTextBox Placeholder="Token..." Value="@_Token" ValueChanged="TokenValueChanged"></RadzenTextBox>
|
<RadzenTextBox Placeholder="Token..." Value="@_Token" ValueChanged="TokenValueChanged"></RadzenTextBox>
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
|
|
||||||
<RadzenRow>
|
<RadzenRow>
|
||||||
<RadzenColumn>
|
<RadzenColumn>
|
||||||
<RadzenText>Bot prefix</RadzenText>
|
<RadzenText>Bot prefix</RadzenText>
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
<RadzenTextBox Placeholder="Bot prefix ..." MaxLength="1" Value="@_Prefix" ValueChanged="PrefixValueChanged"></RadzenTextBox>
|
<RadzenTextBox Placeholder="Bot prefix ..." MaxLength="1" Value="@_Prefix" ValueChanged="PrefixValueChanged"></RadzenTextBox>
|
||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
|
|
||||||
<RadzenRow>
|
<RadzenRow>
|
||||||
<RadzenColumn>
|
<RadzenColumn>
|
||||||
<RadzenText>Bot Server Ids:</RadzenText>
|
<RadzenText>Bot Server Ids:</RadzenText>
|
||||||
@@ -33,14 +33,13 @@
|
|||||||
</RadzenColumn>
|
</RadzenColumn>
|
||||||
</RadzenRow>
|
</RadzenRow>
|
||||||
</ChildContent>
|
</ChildContent>
|
||||||
|
|
||||||
<FooterTemplate>
|
<FooterTemplate>
|
||||||
<RadzenButton Text="Save" Click="SaveChanges"></RadzenButton>
|
<RadzenButton Text="Save" Click="SaveChanges"></RadzenButton>
|
||||||
</FooterTemplate>
|
</FooterTemplate>
|
||||||
</RadzenPanel>
|
</RadzenPanel>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
|
||||||
private string _Token = string.Empty;
|
private string _Token = string.Empty;
|
||||||
private string _Prefix = string.Empty;
|
private string _Prefix = string.Empty;
|
||||||
private string _ServerIds = string.Empty;
|
private string _ServerIds = string.Empty;
|
||||||
@@ -64,8 +63,8 @@
|
|||||||
|
|
||||||
await Application.CurrentApplication.ApplicationEnvironmentVariables.SaveToFile();
|
await Application.CurrentApplication.ApplicationEnvironmentVariables.SaveToFile();
|
||||||
|
|
||||||
DialogService.Close(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ServerIDsValueChanged(string obj)
|
private void ServerIDsValueChanged(string obj)
|
||||||
{
|
{
|
||||||
_ServerIds = obj;
|
_ServerIds = obj;
|
||||||
@@ -9,28 +9,31 @@ namespace DiscordBotWebUI.DiscordBot;
|
|||||||
public class DiscordBotStartup
|
public class DiscordBotStartup
|
||||||
{
|
{
|
||||||
public event EventHandler<string>? Log;
|
public event EventHandler<string>? Log;
|
||||||
private Func<ModuleRequirement, Task> RequireInstallModule { get; }
|
|
||||||
public DiscordBotStartup(Func<ModuleRequirement, Task> requireInstallModule)
|
|
||||||
{
|
|
||||||
RequireInstallModule = requireInstallModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void WriteLog(string message)
|
private void WriteLog(string message)
|
||||||
{
|
{
|
||||||
Log?.Invoke(this, message);
|
Log?.Invoke(this, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly Func<ModuleRequirement, Task> RequireInstallModule;
|
||||||
|
|
||||||
public async Task<bool> LoadComponents()
|
public DiscordBotStartup(Func<ModuleRequirement, Task> requirementHandler)
|
||||||
|
{
|
||||||
|
this.RequireInstallModule = requirementHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task CreateApplication()
|
||||||
{
|
{
|
||||||
await Application.CreateApplication(RequireInstallModule);
|
await Application.CreateApplication(RequireInstallModule);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool LoadComponents()
|
||||||
|
{
|
||||||
Application.Logger.SetOutFunction(WriteLog);
|
Application.Logger.SetOutFunction(WriteLog);
|
||||||
|
|
||||||
if (!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("ServerID") ||
|
return Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("ServerID") &&
|
||||||
!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("token") ||
|
Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("token") &&
|
||||||
!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("prefix"))
|
Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("prefix");
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task PrepareBot()
|
public async Task PrepareBot()
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
|
using DiscordBotCore;
|
||||||
|
using DiscordBotCore.Others.Exceptions;
|
||||||
using DiscordBotWebUI.Components;
|
using DiscordBotWebUI.Components;
|
||||||
|
using DiscordBotWebUI.Components.Pages.Setup;
|
||||||
|
using DiscordBotWebUI.DiscordBot;
|
||||||
using Radzen;
|
using Radzen;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -7,6 +11,7 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
builder.Services.AddRazorComponents()
|
builder.Services.AddRazorComponents()
|
||||||
.AddInteractiveServerComponents();
|
.AddInteractiveServerComponents();
|
||||||
builder.Services.AddRadzenComponents();
|
builder.Services.AddRadzenComponents();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
|
|||||||
Reference in New Issue
Block a user