@page "/" @using DiscordBotCore.Bot @using DiscordBotCore.Logging @using DiscordBotCore.PluginManagement.Loading @using WebUI.Models @using WebUI.Services @inject IDiscordBotApplication DiscordBotApplication @inject IPluginLoader PluginLoader @inject ILogger Logger @inject IJSRuntime JS @inject NotificationService NotificationService @rendermode InteractiveServer
Console Log
@Logger.LogMessages.Count()
@foreach (var line in Logger.LogMessages) {
@line.Message
}
@code { private bool IsRunning { get; set; } protected override void OnInitialized() { IsRunning = DiscordBotApplication.IsReady; Logger.OnLogReceived += LoggerOnLogReceived; } private void LoggerOnLogReceived(ILogMessage obj) { InvokeAsync(async () => { await JS.InvokeVoidAsync("scrollToBottom", "consoleLog"); StateHasChanged(); }); } private async Task StartApplication() { if (!DiscordBotApplication.IsReady) { await DiscordBotApplication.StartAsync(); Logger.Log("Application started", this); NotificationService.Notify("Bot Started !", NotificationType.Success); } IsRunning = DiscordBotApplication.IsReady; } private async Task StopApplication() { if (DiscordBotApplication.IsReady) { await DiscordBotApplication.StopAsync(); Logger.Log("Application stopped", this); NotificationService.Notify("Bot Stopped !", NotificationType.Success); } IsRunning = DiscordBotApplication.IsReady; } private async Task LoadPlugins() { Logger.Log("Loading plugins", this); await PluginLoader.LoadPlugins(); Logger.Log("Plugins loaded", this); NotificationService.Notify("Plugins Loaded !", NotificationType.Success); } private string GetLogStyle(ILogMessage logMessage) { return logMessage.LogMessageType switch { LogType.Info => "color: white;", LogType.Warning => "color: yellow;", LogType.Error => "color: red;", LogType.Critical => "color: purple;", _ => "" }; } private void ClearLogs() { Logger.LogMessages.Clear(); } }