patch on discord bot UI
This commit is contained in:
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@@ -5,10 +5,10 @@
|
|||||||
"name": ".NET Core Launch (web)",
|
"name": ".NET Core Launch (web)",
|
||||||
"type": "coreclr",
|
"type": "coreclr",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"preLaunchTask": "build",
|
"preLaunchTask": "buildUI",
|
||||||
"program": "${workspaceFolder}/DiscordBotPlugins/DiscordBotUI/bin/Debug/net7.0/DiscordBotUI.dll",
|
"program": "${workspaceFolder}/DiscordBotPlugins/DiscordBotUI/bin/Debug/net7.0/DiscordBotUI.dll",
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}/DiscordBotPlugins/DiscordBotUI/",
|
"cwd": "${workspaceFolder}/DiscordBotPlugins/DiscordBotUI/bin/Debug/net7.0",
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"console": "externalTerminal",
|
"console": "externalTerminal",
|
||||||
"serverReadyAction": {
|
"serverReadyAction": {
|
||||||
|
|||||||
12
.vscode/tasks.json
vendored
12
.vscode/tasks.json
vendored
@@ -13,6 +13,18 @@
|
|||||||
],
|
],
|
||||||
"problemMatcher": "$msCompile"
|
"problemMatcher": "$msCompile"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": "buildUI",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"${workspaceFolder}/DiscordBotPlugins/DiscordBotUI/DiscordBotUI.csproj",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "publish",
|
"label": "publish",
|
||||||
"command": "dotnet",
|
"command": "dotnet",
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ public class Program
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Startup(string[] args)
|
public static void Startup(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
PreLoadComponents(args).Wait();
|
PreLoadComponents(args).Wait();
|
||||||
|
|
||||||
if (!Config.Data.ContainsKey("ServerID") || !Config.Data.ContainsKey("token") ||
|
if (!Config.Data.ContainsKey("ServerID") || !Config.Data.ContainsKey("token") ||
|
||||||
|
|||||||
@@ -18,24 +18,80 @@ namespace DiscordBotUI.Controllers
|
|||||||
Config.Data["prefix"]?.Length != 1)
|
Config.Data["prefix"]?.Length != 1)
|
||||||
return RedirectToAction("Settings", "Home");
|
return RedirectToAction("Settings", "Home");
|
||||||
|
|
||||||
|
bool isReady = true;
|
||||||
if (DiscordBot.DiscordBot.Instance is null)
|
if (DiscordBot.DiscordBot.Instance is null)
|
||||||
{
|
{
|
||||||
|
isReady=false;
|
||||||
|
await Task.Run(async() => {
|
||||||
new DiscordBot.DiscordBot(Config.Data["token"], Config.Data["prefix"]);
|
new DiscordBot.DiscordBot(Config.Data["token"], Config.Data["prefix"]);
|
||||||
await DiscordBot.DiscordBot.Instance.Start();
|
await DiscordBot.DiscordBot.Instance.Start();
|
||||||
await DiscordBot.DiscordBot.Instance.LoadPlugins();
|
await DiscordBot.DiscordBot.Instance.LoadPlugins();
|
||||||
|
new PluginManager.Items.ConsoleCommandsHandler(DiscordBot.DiscordBot.Instance._boot.client);
|
||||||
|
}).ContinueWith((t) => {
|
||||||
|
isReady = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!isReady)
|
||||||
|
await Task.Delay(100);
|
||||||
|
|
||||||
|
await Task.Delay(2000);
|
||||||
|
|
||||||
BotModel model = new BotModel();
|
BotModel model = new BotModel();
|
||||||
model.StartStatus = DiscordBot.DiscordBot.Instance._boot.client.ConnectionState.ToString();
|
model.StartStatus = DiscordBot.DiscordBot.Instance._boot.client.ConnectionState.ToString();
|
||||||
model.BotName = DiscordBot.DiscordBot.Instance._boot.client.CurrentUser.Username;
|
model.BotName = DiscordBot.DiscordBot.Instance._boot.client.CurrentUser.Username;
|
||||||
model.PluginsLoaded = PluginManager.Loaders.PluginLoader.PluginsLoaded;
|
model.PluginsLoaded = PluginManager.Loaders.PluginLoader.PluginsLoaded;
|
||||||
|
|
||||||
model.SlashCommands = PluginManager.Loaders.PluginLoader.SlashCommands;
|
model.SlashCommands = PluginManager.Loaders.PluginLoader.SlashCommands ?? new List<PluginManager.Interfaces.DBSlashCommand>();
|
||||||
model.Events = PluginManager.Loaders.PluginLoader.Events;
|
model.Events = PluginManager.Loaders.PluginLoader.Events ?? new List<PluginManager.Interfaces.DBEvent>();
|
||||||
model.Commands = PluginManager.Loaders.PluginLoader.Commands;
|
model.Commands = PluginManager.Loaders.PluginLoader.Commands ?? new List<PluginManager.Interfaces.DBCommand>();
|
||||||
|
|
||||||
return View(model);
|
return View(model);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> PluginsPage()
|
||||||
|
{
|
||||||
|
if(DiscordBot.DiscordBot.Instance is null) {
|
||||||
|
return RedirectToAction("Start");
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginsPageModel model = new PluginsPageModel();
|
||||||
|
if (PluginManager.Loaders.PluginLoader.Commands != null)
|
||||||
|
model.InstalledCommands = PluginManager.Loaders.PluginLoader.Commands.Select(x => x.Command).ToList();
|
||||||
|
else model.InstalledCommands = new List<string>();
|
||||||
|
if (PluginManager.Loaders.PluginLoader.Events != null)
|
||||||
|
model.InstalledEvents = PluginManager.Loaders.PluginLoader.Events.Select(x => x.Name).ToList();
|
||||||
|
else model.InstalledEvents = new List<string>();
|
||||||
|
if (PluginManager.Loaders.PluginLoader.SlashCommands != null)
|
||||||
|
model.InstalledSlashCommands = PluginManager.Loaders.PluginLoader.SlashCommands.Select(x => x.Name).ToList();
|
||||||
|
else model.InstalledSlashCommands = new List<string>();
|
||||||
|
model.PluginsManager = new("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Plugins.txt");
|
||||||
|
List<string[]> plugins = await model.PluginsManager.ListAvailablePlugins();
|
||||||
|
if (plugins == null) return RedirectToAction("Start");
|
||||||
|
|
||||||
|
model.Plugins = plugins;
|
||||||
|
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<int> InstallPlugin(string pluginName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(!DiscordBot.DiscordBot.Instance._boot.isReady)
|
||||||
|
return 1;
|
||||||
|
await PluginManager.Items.ConsoleCommandsHandler.ExecuteCommad("dwplug " + pluginName);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogError(ex);
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using PluginManager.Interfaces;
|
||||||
|
|
||||||
|
namespace DiscordBotUI.Models.Bot
|
||||||
|
{
|
||||||
|
public class PluginsPageModel
|
||||||
|
{
|
||||||
|
public List<string> InstalledCommands {get;set;}
|
||||||
|
public List<string> InstalledEvents {get;set;}
|
||||||
|
public List<string> InstalledSlashCommands {get;set;}
|
||||||
|
public List<string[]> Plugins {get;set;}
|
||||||
|
|
||||||
|
public PluginManager.Online.PluginsManager PluginsManager {get;set;}
|
||||||
|
}
|
||||||
|
}
|
||||||
72
DiscordBotPlugins/DiscordBotUI/Views/Bot/PluginsPage.cshtml
Normal file
72
DiscordBotPlugins/DiscordBotUI/Views/Bot/PluginsPage.cshtml
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
@model DiscordBotUI.Models.Bot.PluginsPageModel
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<link rel="stylesheet" href="~/css/bot/plugins.css" asp-append-version="true" />
|
||||||
|
<table class="text-white">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Plugin Name</th>
|
||||||
|
<th>Plugin Description</th>
|
||||||
|
<th>Plugin Type</th>
|
||||||
|
<th>Plugin Version</th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var item in Model.Plugins)
|
||||||
|
{
|
||||||
|
@if (item.Contains("+") || item.Contains("-") || item[0].Length < 2 || item[0] == "Name") continue;
|
||||||
|
<tr>
|
||||||
|
<td>@item[0]</td>
|
||||||
|
<td>@item[1]</td>
|
||||||
|
<td>@item[2]</td>
|
||||||
|
<td>@item[3]</td>
|
||||||
|
@if (Model.InstalledCommands.Contains(item[0]) || Model.InstalledEvents.Contains(item[0]) ||
|
||||||
|
Model.InstalledSlashCommands.Contains(item[0]))
|
||||||
|
{
|
||||||
|
<td>Installed</td>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<td><input type="button" value="Install" onclick="install(this)" name="@item[0]" /></td>
|
||||||
|
}
|
||||||
|
<td>
|
||||||
|
<div class="demo-container" style="display: none;">
|
||||||
|
<div class="progress-bar">
|
||||||
|
<div class="progress-bar-value"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
function install(button) {
|
||||||
|
var pluginName = button.name;
|
||||||
|
var progress = button.parentElement.nextElementSibling.firstElementChild;
|
||||||
|
progress.style.display = "";
|
||||||
|
$.ajax({
|
||||||
|
url: "/Bot/InstallPlugin",
|
||||||
|
type: "GET",
|
||||||
|
data: { pluginName: pluginName },
|
||||||
|
success: function (data) {
|
||||||
|
if (data == 0)
|
||||||
|
button.value = "Installed";
|
||||||
|
button.disabled = true;
|
||||||
|
progress.style.display = "none";
|
||||||
|
},
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
alert("Error: " + error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
@model DiscordBotUI.Models.Bot.BotModel
|
@model DiscordBotUI.Models.Bot.BotModel
|
||||||
|
<link rel="stylesheet" href="~/css/bot/start.css" asp-append-version="true" />
|
||||||
|
|
||||||
<label>Bot Name: @Model.BotName</label>
|
|
||||||
|
<label class="text-white">Bot Name: @Model.BotName</label>
|
||||||
<br />
|
<br />
|
||||||
<label>Connection Status: @Model.StartStatus</label>
|
<label class="text-white">Connection Status: @Model.StartStatus</label>
|
||||||
<br />
|
<br />
|
||||||
<label>Number of plugins loaded: @Model.PluginsLoaded</label>
|
<label class="text-white">Number of plugins loaded: @Model.PluginsLoaded</label>
|
||||||
<style>
|
<style>
|
||||||
* {
|
* {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
@@ -45,7 +47,7 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row text-white">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<h2>Commands</h2>
|
<h2>Commands</h2>
|
||||||
<table>
|
<table>
|
||||||
@@ -57,7 +59,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
@foreach(var cmd in Model.Commands)
|
@foreach(var cmd in Model.Commands)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr class="text-white bg-gradient" style="border: 0px; background-color: transparent;">
|
||||||
<td>@cmd.Command</td>
|
<td>@cmd.Command</td>
|
||||||
<td>@cmd.Description</td>
|
<td>@cmd.Description</td>
|
||||||
<td>@cmd.Usage</td>
|
<td>@cmd.Usage</td>
|
||||||
@@ -81,7 +83,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
@foreach(var eve in Model.Events)
|
@foreach(var eve in Model.Events)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr class="text-white bg-gradient" style="border: 0px; background-color: transparent;">
|
||||||
<td>@eve.Name</td>
|
<td>@eve.Name</td>
|
||||||
<td>@eve.Description</td>
|
<td>@eve.Description</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -99,7 +101,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
@foreach(var scmd in Model.SlashCommands)
|
@foreach(var scmd in Model.SlashCommands)
|
||||||
{
|
{
|
||||||
<tr>
|
<tr class="text-white bg-gradient" style="border: 0px; background-color: transparent;">
|
||||||
<td>@scmd.Name</td>
|
<td>@scmd.Name</td>
|
||||||
<td>@scmd.Description</td>
|
<td>@scmd.Description</td>
|
||||||
@if (scmd.canUseDM)
|
@if (scmd.canUseDM)
|
||||||
|
|||||||
@@ -23,6 +23,9 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-light" asp-area="" asp-controller="Bot" asp-action="Start">Start Bot</a>
|
<a class="nav-link text-light" asp-area="" asp-controller="Bot" asp-action="Start">Start Bot</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-light" asp-area="" asp-controller="Bot" asp-action="PluginsPage">Plugins</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
44
DiscordBotPlugins/DiscordBotUI/wwwroot/css/bot/plugins.css
Normal file
44
DiscordBotPlugins/DiscordBotUI/wwwroot/css/bot/plugins.css
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
html {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 25px;
|
||||||
|
font-family: sans-serif;
|
||||||
|
background: linear-gradient(#141e30, #243b55);
|
||||||
|
}
|
||||||
|
|
||||||
|
.demo-container {
|
||||||
|
width: 300px;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-bar {
|
||||||
|
height: 4px;
|
||||||
|
background-color: rgba(5, 114, 206, 0.2);
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-bar-value {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgb(5, 114, 206);
|
||||||
|
animation: indeterminateAnimation 1s infinite linear;
|
||||||
|
transform-origin: 0% 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes indeterminateAnimation {
|
||||||
|
0% {
|
||||||
|
transform: translateX(0) scaleX(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
40% {
|
||||||
|
transform: translateX(0) scaleX(0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
transform: translateX(100%) scaleX(0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
10
DiscordBotPlugins/DiscordBotUI/wwwroot/css/bot/start.css
Normal file
10
DiscordBotPlugins/DiscordBotUI/wwwroot/css/bot/start.css
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
html {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
font-family: sans-serif;
|
||||||
|
background: linear-gradient(#141e30, #243b55);
|
||||||
|
}
|
||||||
@@ -66,7 +66,16 @@ public class PluginLoader
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static List<DBSlashCommand>? SlashCommands { get; set; }
|
public static List<DBSlashCommand>? SlashCommands { get; set; }
|
||||||
|
|
||||||
public static int PluginsLoaded { get => Commands!.Count + Events!.Count + SlashCommands!.Count;}
|
public static int PluginsLoaded { get {
|
||||||
|
var count = 0;
|
||||||
|
if (Commands is not null)
|
||||||
|
count += Commands.Count;
|
||||||
|
if (Events is not null)
|
||||||
|
count += Events.Count;
|
||||||
|
if (SlashCommands is not null)
|
||||||
|
count += SlashCommands.Count;
|
||||||
|
return count;
|
||||||
|
}}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main mathod that is called to load all events
|
/// The main mathod that is called to load all events
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class PluginsManager
|
|||||||
/// The method to load all plugins
|
/// The method to load all plugins
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task ListAvailablePlugins()
|
public async Task<List<string[]>> ListAvailablePlugins()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -81,12 +81,16 @@ public class PluginsManager
|
|||||||
data.Add(new[] { "-", "-", "-", "-" });
|
data.Add(new[] { "-", "-", "-", "-" });
|
||||||
|
|
||||||
Utilities.FormatAndAlignTable(data, TableFormat.CENTER_EACH_COLUMN_BASED);
|
Utilities.FormatAndAlignTable(data, TableFormat.CENTER_EACH_COLUMN_BASED);
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
Logger.WriteLine("Failed to execute command: listplugs\nReason: " + exception.Message);
|
Logger.WriteLine("Failed to execute command: listplugs\nReason: " + exception.Message);
|
||||||
Logger.WriteErrFile(exception.ToString());
|
Logger.WriteErrFile(exception.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user