Added pages for module and plugin download
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
@using DiscordBotCore.Plugin
|
||||
@using DiscordBotWebUI.Types
|
||||
|
||||
@inject DialogService DialogService
|
||||
|
||||
<RadzenDataGrid AllowColumnResize="true" PageSize="5" AllowPaging="true" PagerHorizontalAlign="HorizontalAlign.Left" Data="ListedItems">
|
||||
<Columns>
|
||||
<RadzenDataGridColumn Property="@nameof(MarketItem.Name)" Title="Item Name"></RadzenDataGridColumn>
|
||||
@@ -50,8 +48,6 @@
|
||||
});
|
||||
await Application.CurrentApplication.ModuleManager.InstallModule(moduleName, downloadProgress);
|
||||
_ProgressBarVisible = false;
|
||||
|
||||
DialogService.Close(true);
|
||||
}
|
||||
|
||||
private async Task DownloadPlugin(string pluginName)
|
||||
@@ -68,7 +64,5 @@
|
||||
await Application.CurrentApplication.PluginManager.InstallPlugin(pluginInfo, downloadProgress);
|
||||
|
||||
_ProgressBarVisible = false;
|
||||
|
||||
DialogService.Close(true);
|
||||
}
|
||||
}
|
||||
@@ -21,13 +21,13 @@
|
||||
</div>
|
||||
|
||||
<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
|
||||
</NavLink>
|
||||
</div>
|
||||
|
||||
<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
|
||||
</NavLink>
|
||||
</div>
|
||||
|
||||
@@ -13,6 +13,14 @@
|
||||
@code {
|
||||
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)
|
||||
{
|
||||
if(!requirements.RequireAny)
|
||||
@@ -27,19 +35,17 @@
|
||||
}
|
||||
|
||||
private async void Initialize()
|
||||
{
|
||||
DiscordBotStartup setup = new DiscordBotStartup(FixModules);
|
||||
|
||||
setup.Log += async (sender, str) => {
|
||||
{
|
||||
_DiscordBotStartup.Log += async (sender, str) => {
|
||||
_TextValue += str + "\n";
|
||||
await InvokeAsync(StateHasChanged);
|
||||
};
|
||||
|
||||
dynamic result = await setup.LoadComponents();
|
||||
dynamic result = _DiscordBotStartup.LoadComponents();
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -47,7 +53,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
await setup.PrepareBot();
|
||||
await setup.RefreshPlugins(false);
|
||||
await _DiscordBotStartup.PrepareBot();
|
||||
await _DiscordBotStartup.RefreshPlugins(false);
|
||||
}
|
||||
}
|
||||
26
DiscordBotWebUI/Components/Pages/ModulesMarket.razor
Normal file
26
DiscordBotWebUI/Components/Pages/ModulesMarket.razor
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
DiscordBotWebUI/Components/Pages/PluginsMarket.razor
Normal file
37
DiscordBotWebUI/Components/Pages/PluginsMarket.razor
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
@using DiscordBotCore
|
||||
@inject DialogService DialogService
|
||||
@page "/settings"
|
||||
@using DiscordBotCore
|
||||
|
||||
<RadzenPanel>
|
||||
<HeaderTemplate>
|
||||
@@ -14,7 +14,7 @@
|
||||
<RadzenTextBox Placeholder="Token..." Value="@_Token" ValueChanged="TokenValueChanged"></RadzenTextBox>
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
|
||||
<RadzenRow>
|
||||
<RadzenColumn>
|
||||
<RadzenText>Bot prefix</RadzenText>
|
||||
@@ -23,7 +23,7 @@
|
||||
<RadzenTextBox Placeholder="Bot prefix ..." MaxLength="1" Value="@_Prefix" ValueChanged="PrefixValueChanged"></RadzenTextBox>
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
|
||||
|
||||
<RadzenRow>
|
||||
<RadzenColumn>
|
||||
<RadzenText>Bot Server Ids:</RadzenText>
|
||||
@@ -33,14 +33,13 @@
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
</ChildContent>
|
||||
|
||||
|
||||
<FooterTemplate>
|
||||
<RadzenButton Text="Save" Click="SaveChanges"></RadzenButton>
|
||||
</FooterTemplate>
|
||||
</RadzenPanel>
|
||||
|
||||
@code {
|
||||
|
||||
private string _Token = string.Empty;
|
||||
private string _Prefix = string.Empty;
|
||||
private string _ServerIds = string.Empty;
|
||||
@@ -64,8 +63,8 @@
|
||||
|
||||
await Application.CurrentApplication.ApplicationEnvironmentVariables.SaveToFile();
|
||||
|
||||
DialogService.Close(true);
|
||||
}
|
||||
|
||||
private void ServerIDsValueChanged(string obj)
|
||||
{
|
||||
_ServerIds = obj;
|
||||
@@ -9,28 +9,31 @@ namespace DiscordBotWebUI.DiscordBot;
|
||||
public class DiscordBotStartup
|
||||
{
|
||||
public event EventHandler<string>? Log;
|
||||
private Func<ModuleRequirement, Task> RequireInstallModule { get; }
|
||||
public DiscordBotStartup(Func<ModuleRequirement, Task> requireInstallModule)
|
||||
{
|
||||
RequireInstallModule = requireInstallModule;
|
||||
}
|
||||
|
||||
private void WriteLog(string 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);
|
||||
}
|
||||
|
||||
public bool LoadComponents()
|
||||
{
|
||||
Application.Logger.SetOutFunction(WriteLog);
|
||||
|
||||
if (!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("ServerID") ||
|
||||
!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("token") ||
|
||||
!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("prefix"))
|
||||
return false;
|
||||
return Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("ServerID") &&
|
||||
Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("token") &&
|
||||
Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("prefix");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task PrepareBot()
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
using DiscordBotCore;
|
||||
using DiscordBotCore.Others.Exceptions;
|
||||
using DiscordBotWebUI.Components;
|
||||
using DiscordBotWebUI.Components.Pages.Setup;
|
||||
using DiscordBotWebUI.DiscordBot;
|
||||
using Radzen;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -7,6 +11,7 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddRazorComponents()
|
||||
.AddInteractiveServerComponents();
|
||||
builder.Services.AddRadzenComponents();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
||||
Reference in New Issue
Block a user