From 56c71ee533251320f6168baf08b7fc7a5378a5f0 Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 3 Jul 2025 13:18:35 -0400 Subject: [PATCH] frontend progress. I am *almost* returning to monke.... but my datatype uses strings to serialize some objects in order to cooperate with entity framework. how hard do you want to not use javascript.. is knockout.js worse than a viewmodel? --- ConsoleService.cs | 24 +++++--- .../DiscordInterface/DiscordInterface.cs | 12 +++- Rememberer.cs | 7 +++ .../Controllers/ConfigurationController.cs | 11 ++++ WebInterface/Views/Configuration/Index.cshtml | 60 ++++++++++++++----- 5 files changed, 90 insertions(+), 24 deletions(-) diff --git a/ConsoleService.cs b/ConsoleService.cs index c16b644..857b1b6 100644 --- a/ConsoleService.cs +++ b/ConsoleService.cs @@ -37,10 +37,19 @@ namespace vassago foreach (var dt in DiscordTokens) { var d = new DiscordInterface(); - initTasks.Add(d.Init(dt)); - Shared.ProtocolList.Add(d); + initTasks.Add(Task.Run(() => + { + try + { + d.Init(dt); + Shared.ProtocolList.Add(d); + } + catch (Exception e){ + Console.Error.WriteLine($"couldn't initialize discord interface with token {dt}"); + Console.Error.WriteLine(e); + } + })); } - if (TwitchConfigs?.Any() ?? false) foreach (var tc in TwitchConfigs) { @@ -50,6 +59,7 @@ namespace vassago } Task.WaitAll(initTasks.ToArray(), cancellationToken); + Console.WriteLine("init tasks are done"); } private void dbConfig(ref vassago.Models.Configuration confEntity) { @@ -57,10 +67,10 @@ namespace vassago Shared.API_URL = new Uri(confEntity.reportedApiUrl); DiscordTokens = confEntity.DiscordTokens; TwitchConfigs = new List(); - if(confEntity.TwitchConfigs != null) foreach (var twitchConfString in confEntity.TwitchConfigs) - { - TwitchConfigs.Add(JsonConvert.DeserializeObject(twitchConfString)); - } + if (confEntity.TwitchConfigs != null) foreach (var twitchConfString in confEntity.TwitchConfigs) + { + TwitchConfigs.Add(JsonConvert.DeserializeObject(twitchConfString)); + } Conversion.Converter.Load(confEntity.ExchangePairsLocation); Telefranz.Configure(confEntity.KafkaName, confEntity.KafkaBootstrap); vassago.Behavior.Webhook.SetupWebhooks(confEntity.Webhooks); diff --git a/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs b/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs index 2491e0d..5e2ba5e 100644 --- a/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs +++ b/ProtocolInterfaces/DiscordInterface/DiscordInterface.cs @@ -33,6 +33,8 @@ public class DiscordInterface : ProtocolInterface public async Task Init(string config) { var token = config; + Console.WriteLine($"going to validate token {token}"); + Discord.TokenUtils.ValidateToken(TokenType.Bot, token);//throws an exception if invalid await SetupDiscordChannel(); client = new DiscordSocketClient(new DiscordSocketConfig() { GatewayIntents = GatewayIntents.All }); @@ -41,12 +43,18 @@ public class DiscordInterface : ProtocolInterface Console.WriteLine(msg.ToString()); return Task.CompletedTask; }; - client.Connected += () => Task.Run(SelfConnected); - client.Ready += () => Task.Run(ClientReady); + client.Connected += this.SelfConnected; + client.Disconnected += this.ClientDisconnected; + client.Ready += this.ClientReady; await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); } + private async Task ClientDisconnected(Exception e) + { + Console.WriteLine("client disconnected!"); + Console.WriteLine(e?.Message); + } private async Task SetupDiscordChannel() { diff --git a/Rememberer.cs b/Rememberer.cs index b890a4c..0a1154a 100644 --- a/Rememberer.cs +++ b/Rememberer.cs @@ -354,4 +354,11 @@ public class Rememberer dbAccessSemaphore.Release(); return toReturn; } + public void RememberConfiguration(Configuration conf) + { + dbAccessSemaphore.Wait(); + db.Update(conf); + db.SaveChanges(); + dbAccessSemaphore.Release(); + } } diff --git a/WebInterface/Controllers/ConfigurationController.cs b/WebInterface/Controllers/ConfigurationController.cs index dc3a259..a9c11e3 100644 --- a/WebInterface/Controllers/ConfigurationController.cs +++ b/WebInterface/Controllers/ConfigurationController.cs @@ -25,4 +25,15 @@ public class ConfigurationController() : Controller { return View(new ErrorPageViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } + + [HttpPost] + public IActionResult AddDiscord(string newToken) + { + Console.WriteLine($"remembering discord, {newToken}"); + var conf = r.Configuration(); + conf.DiscordTokens ??=[]; + conf.DiscordTokens.Add(newToken); + r.RememberConfiguration(conf); + return RedirectToAction("Index", "Configuration"); + } } diff --git a/WebInterface/Views/Configuration/Index.cshtml b/WebInterface/Views/Configuration/Index.cshtml index a2b6473..6c39faf 100644 --- a/WebInterface/Views/Configuration/Index.cshtml +++ b/WebInterface/Views/Configuration/Index.cshtml @@ -1,22 +1,24 @@ @model vassago.Models.Configuration @using Newtonsoft.Json; @using vassago.Behavior; -@{ -} + home/configuration
- + @{ if(Model.DiscordTokens != null) for(var i = 0; i < Model.DiscordTokens.Count; i++) { - Html.Raw(""); - Html.Raw($""); - Html.Raw($""); - Html.Raw(""); + + + + } } @@ -30,18 +32,22 @@ - + @{ if(Model.TwitchConfigs != null) for(var i = 0; i < Model.TwitchConfigs.Count; i++) { - Html.Raw(""); - Html.Raw($""); - Html.Raw(""); - Html.Raw(""); + var tc = JsonConvert.DeserializeObject(Model.TwitchConfigs[i]); + + + + + } } @@ -109,6 +115,14 @@ + +
+ Are you sure? + + + + +
@@ -117,6 +131,14 @@
+ +
+ Are you sure? + + + + +
@@ -124,3 +146,11 @@
+ +
+ Are you sure? + + + + +
DiscordDiscord (@(Model?.DiscordTokens?.Count ?? 0) accounts)
+ + +
TwitchTwitch (@(Model?.TwitchConfigs?.Count ?? 0) accounts)
"); - Html.Raw(""); - Html.Raw(""); - Html.Raw("
+ + + + +