From 2ce4656ac5cb97bbb7dbb3e38486d370f15bf012 Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 5 Jul 2025 00:36:09 -0400 Subject: [PATCH] most of config works, but not webhook's headers and you know what, webhooks ought to make their way into the database anyway. and fuck it, be a paragraph --- Behavior/Webhook.cs | 2 +- .../Controllers/ConfigurationController.cs | 94 +++++++- WebInterface/Views/Configuration/Index.cshtml | 209 ++++++++++++++---- 3 files changed, 261 insertions(+), 44 deletions(-) diff --git a/Behavior/Webhook.cs b/Behavior/Webhook.cs index 658f3bc..90b5bab 100644 --- a/Behavior/Webhook.cs +++ b/Behavior/Webhook.cs @@ -186,7 +186,7 @@ public class WebhookConf public Uri Uri { get; set; } //public HttpMethod Method { get; set; } public Enumerations.HttpVerb Method { get; set; } - public List> Headers { get; set; } + public List Headers { get; set; } public string Content { get; set; } public string Description { get; set; } } diff --git a/WebInterface/Controllers/ConfigurationController.cs b/WebInterface/Controllers/ConfigurationController.cs index a9c11e3..d3aff1e 100644 --- a/WebInterface/Controllers/ConfigurationController.cs +++ b/WebInterface/Controllers/ConfigurationController.cs @@ -7,6 +7,7 @@ using vassago; using vassago.Behavior; using vassago.Models; using vassago.WebInterface.Models; +using vassago.TwitchInterface; namespace vassago.WebInterface.Controllers; @@ -19,6 +20,21 @@ public class ConfigurationController() : Controller ViewData.Add("Serialized", JsonConvert.SerializeObject(conf)); return View(conf); } + [HttpPost] + public IActionResult Submit(Configuration incoming) + { + var conf = r.Configuration() ?? new Configuration(); + conf.DiscordTokens = incoming.DiscordTokens; + conf.TwitchConfigs = incoming.TwitchConfigs; + conf.ExchangePairsLocation = incoming.ExchangePairsLocation; + conf.SetupDiscordSlashCommands = incoming.SetupDiscordSlashCommands; + conf.Webhooks = incoming.Webhooks; + conf.KafkaBootstrap = incoming.KafkaBootstrap; + conf.KafkaName = incoming.KafkaName; + conf.reportedApiUrl = incoming.reportedApiUrl; + r.RememberConfiguration(conf); + return RedirectToAction("Index", "Configuration"); + } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() @@ -29,11 +45,85 @@ public class ConfigurationController() : Controller [HttpPost] public IActionResult AddDiscord(string newToken) { - Console.WriteLine($"remembering discord, {newToken}"); + Console.WriteLine($"adding discord, {newToken}"); var conf = r.Configuration(); - conf.DiscordTokens ??=[]; + conf.DiscordTokens ??= []; conf.DiscordTokens.Add(newToken); r.RememberConfiguration(conf); return RedirectToAction("Index", "Configuration"); } + + [HttpPost] + public IActionResult RemoveDiscord(int index) + { + Console.WriteLine($"removing discord[{index}]"); + var conf = r.Configuration(); + if (conf.DiscordTokens?.Count <= index) + { + Console.Error.WriteLine("error removing discord {index} from configuration, only have {conf.DiscordTokens?.Count}."); + return RedirectToAction("Index", "Configuration"); + } + + conf.DiscordTokens.RemoveAt(index); + r.RememberConfiguration(conf); + return RedirectToAction("Index", "Configuration"); + } + + [HttpPost] + public IActionResult AddTwitch(string newUsername, string newOauth) + { + Console.WriteLine($"adding twitch, {newUsername}/{newOauth}"); + var conf = r.Configuration(); + conf.TwitchConfigs ??= []; + var thisOne = new TwitchConfig() + { + username = newUsername, + oauth = newOauth + }; + conf.TwitchConfigs.Add(JsonConvert.SerializeObject(thisOne)); + r.RememberConfiguration(conf); + return RedirectToAction("Index", "Configuration"); + } + + [HttpPost] + public IActionResult RemoveTwitch(int index) + { + Console.WriteLine($"removing twitch[{index}]"); + var conf = r.Configuration(); + if (conf.TwitchConfigs?.Count <= index) + { + Console.Error.WriteLine("error removing twitch {index} from configuration, only have {conf.TwitchConfigs?.Count}."); + return RedirectToAction("Index", "Configuration"); + } + conf.TwitchConfigs.RemoveAt(index); + r.RememberConfiguration(conf); + return RedirectToAction("Index", "Configuration"); + } + + [HttpPost] + public IActionResult AddWebhook(WebhookConf newWebhook) + { + Console.WriteLine($"adding webhook, {newWebhook}"); + var conf = r.Configuration(); + conf.Webhooks??= []; + conf.Webhooks.Add(JsonConvert.SerializeObject(newWebhook)); + r.RememberConfiguration(conf); + return RedirectToAction("Index", "Configuration"); + } + + [HttpPost] + public IActionResult RemoveWebhook(int index) + { + Console.WriteLine($"removing webhook[{index}]"); + var conf = r.Configuration(); + if (conf.Webhooks?.Count <= index) + { + Console.Error.WriteLine("error removing webhook {index} from configuration, only have {conf.Webhooks?.Count}."); + return RedirectToAction("Index", "Configuration"); + } + + conf.Webhooks.RemoveAt(index); + r.RememberConfiguration(conf); + return RedirectToAction("Index", "Configuration"); + } } diff --git a/WebInterface/Views/Configuration/Index.cshtml b/WebInterface/Views/Configuration/Index.cshtml index 6c39faf..93e51b6 100644 --- a/WebInterface/Views/Configuration/Index.cshtml +++ b/WebInterface/Views/Configuration/Index.cshtml @@ -1,9 +1,11 @@ @model vassago.Models.Configuration @using Newtonsoft.Json; @using vassago.Behavior; +@using vassago.TwitchInterface; +@using System.Text; home/configuration -
+ @@ -16,7 +18,7 @@ } @@ -29,7 +31,7 @@ + @@ -42,10 +44,10 @@ } @@ -58,24 +60,37 @@ - + @{ - if(Model.Webhooks != null) for(var i = 0; i< Model.Webhooks.Count; i++) + if(Model.Webhooks != null) for(var i = 0; i < Model.Webhooks.Count; i++) { + if(Model.Webhooks[i] == null) continue; + Console.WriteLine(Model.Webhooks[i]); var wh = JsonConvert.DeserializeObject(Model.Webhooks[i]); + if(wh == null) continue; + var sb = new StringBuilder(); + if(wh.Headers != null) foreach(var header in wh.Headers) + { + sb.Append($"{header[0]}:"); + if(header.Count == 2) + sb.Append(header[1]); + sb.AppendLine(); + } } @@ -83,27 +98,23 @@ - - - - - + - + - - + + - +
- +
-
Twitch (@(Model?.TwitchConfigs?.Count ?? 0) accounts)
- - - - + + + +
Webhooks
- - - - - - + + + + + + + +
- +
@@ -115,42 +126,158 @@
- -
+ + Are you sure? - - + +
- - + username: + oauth:
- -
+ + Are you sure? - +
- +
- - - + trigger + + Uri + + Method + + Headers + + + Content + + Description + + +
- -
+ + Are you sure? - +
+@section scripts{ + +}