diff --git a/Behavior/Webhook.cs b/Behavior/Webhook.cs index 90b5bab..1bd0413 100644 --- a/Behavior/Webhook.cs +++ b/Behavior/Webhook.cs @@ -28,39 +28,39 @@ public class Webhook : Behavior public static void SetupWebhooks(IEnumerable confSection) { //configuredWebhooks = confSection.Get>(); - if(confSection != null) foreach (var confLine in confSection) - { - var conf = JsonConvert.DeserializeObject(confLine); - var confName = $"Webhook: {conf.Trigger}"; - var changed = false; - var myUAC = rememberer.SearchUAC(uac => uac.OwnerId == conf.uacID); - if (myUAC == null) + if (confSection != null) foreach (var confLine in confSection) { - myUAC = new() + var conf = JsonConvert.DeserializeObject(confLine); + var confName = $"Webhook: {conf.Trigger}"; + var changed = false; + var myUAC = rememberer.SearchUAC(uac => uac.OwnerId == conf.uacID); + if (myUAC == null) { - OwnerId = conf.uacID, - DisplayName = confName, - Description = conf.Description - }; - changed = true; - rememberer.RememberUAC(myUAC); - } - else - { - if (myUAC.DisplayName != confName) - { - myUAC.DisplayName = confName; + myUAC = new() + { + OwnerId = conf.uacID, + DisplayName = confName, + Description = conf.Description + }; changed = true; + rememberer.RememberUAC(myUAC); } - if (myUAC.Description != conf.Description) + else { - myUAC.Description = conf.Description; - changed = true; + if (myUAC.DisplayName != confName) + { + myUAC.DisplayName = confName; + changed = true; + } + if (myUAC.Description != conf.Description) + { + myUAC.Description = conf.Description; + changed = true; + } } + if (changed) + rememberer.RememberUAC(myUAC); } - if (changed) - rememberer.RememberUAC(myUAC); - } } public override bool ShouldAct(Message message, List matchedUACs) @@ -111,10 +111,11 @@ public class Webhook : Behavior } var msg = translate(actionOrder, message); var req = new HttpRequestMessage(new HttpMethod(actionOrder.Conf.Method.ToString()), actionOrder.Conf.Uri); - var theContentHeader = actionOrder.Conf.Headers?.FirstOrDefault(h => h[0]?.ToLower() == "content-type"); - if (theContentHeader != null) + var theContentHeader = actionOrder.Conf.Headers?.FirstOrDefault(h => h?.ToLower().StartsWith("content-type:") ?? false); + var contentHeaderVal = theContentHeader?.Split(':')?[1]?.ToLower(); + if (contentHeaderVal != null) { - switch (theContentHeader[1]?.ToLower()) + switch (contentHeaderVal) { //json content is constructed some other weird way. case "multipart/form-data": @@ -124,7 +125,7 @@ public class Webhook : Behavior req.Content = new System.Net.Http.StringContent(msg); break; } - req.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(theContentHeader[1]?.ToLower()); + req.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentHeaderVal); } if (req.Content == null) { @@ -133,17 +134,16 @@ public class Webhook : Behavior Console.WriteLine($"survived translating string content. request content: {req.Content}"); if (actionOrder.Conf.Headers?.ToList().Count > 0) { - Console.WriteLine("will add headers."); - foreach (var kvp in actionOrder.Conf.Headers.ToList()) + foreach (var header in actionOrder.Conf.Headers.ToList()) { - if (kvp[0] == theContentHeader[0]) + if (header?.ToLower().StartsWith("content-type:") ?? false) { Console.WriteLine("content header; skipping."); } else { - Console.WriteLine($"adding header; {kvp[0]}: {kvp[1]}"); - req.Headers.Add(kvp[0], kvp[1]); + Console.WriteLine($"adding header; {header}"); + req.Headers.Add(header.Split(':')[0], header.Split(':')[1]); Console.WriteLine("survived."); } } diff --git a/ConsoleService.cs b/ConsoleService.cs index 857b1b6..21f88df 100644 --- a/ConsoleService.cs +++ b/ConsoleService.cs @@ -73,7 +73,6 @@ namespace vassago } Conversion.Converter.Load(confEntity.ExchangePairsLocation); Telefranz.Configure(confEntity.KafkaName, confEntity.KafkaBootstrap); - vassago.Behavior.Webhook.SetupWebhooks(confEntity.Webhooks); } } } diff --git a/Migrations/20250708171025_UnconfinguredWebhooks.Designer.cs b/Migrations/20250708171025_UnconfinguredWebhooks.Designer.cs new file mode 100644 index 0000000..e34b80c --- /dev/null +++ b/Migrations/20250708171025_UnconfinguredWebhooks.Designer.cs @@ -0,0 +1,424 @@ +// +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using vassago.Models; + +#nullable disable + +namespace vassago.Migrations +{ + [DbContext(typeof(ChattingContext))] + [Migration("20250708171025_UnconfinguredWebhooks")] + partial class UnconfinguredWebhooks + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "hstore"); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("AccountUAC", b => + { + b.Property("AccountInChannelsId") + .HasColumnType("uuid"); + + b.Property("UACsId") + .HasColumnType("uuid"); + + b.HasKey("AccountInChannelsId", "UACsId"); + + b.HasIndex("UACsId"); + + b.ToTable("AccountUAC"); + }); + + modelBuilder.Entity("ChannelUAC", b => + { + b.Property("ChannelsId") + .HasColumnType("uuid"); + + b.Property("UACsId") + .HasColumnType("uuid"); + + b.HasKey("ChannelsId", "UACsId"); + + b.HasIndex("UACsId"); + + b.ToTable("ChannelUAC"); + }); + + modelBuilder.Entity("UACUser", b => + { + b.Property("UACsId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("UACsId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("UACUser"); + }); + + modelBuilder.Entity("vassago.Models.Account", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DisplayName") + .HasColumnType("text"); + + b.Property("ExternalId") + .HasColumnType("text"); + + b.Property("IsBot") + .HasColumnType("boolean"); + + b.Property("IsUserId") + .HasColumnType("uuid"); + + b.Property("Protocol") + .HasColumnType("text"); + + b.Property("SeenInChannelId") + .HasColumnType("uuid"); + + b.Property("Username") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("IsUserId"); + + b.HasIndex("SeenInChannelId"); + + b.ToTable("Accounts"); + }); + + modelBuilder.Entity("vassago.Models.Attachment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Content") + .HasColumnType("bytea"); + + b.Property("ContentType") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("ExternalId") + .HasColumnType("numeric(20,0)"); + + b.Property("Filename") + .HasColumnType("text"); + + b.Property("MessageId") + .HasColumnType("uuid"); + + b.Property("Size") + .HasColumnType("integer"); + + b.Property("Source") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("MessageId"); + + b.ToTable("Attachments"); + }); + + modelBuilder.Entity("vassago.Models.Channel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ChannelType") + .HasColumnType("integer"); + + b.Property("DisplayName") + .HasColumnType("text"); + + b.Property("ExternalId") + .HasColumnType("text"); + + b.Property("LewdnessFilterLevel") + .HasColumnType("integer"); + + b.Property("LinksAllowed") + .HasColumnType("boolean"); + + b.Property("MaxAttachmentBytes") + .HasColumnType("numeric(20,0)"); + + b.Property("MaxTextChars") + .HasColumnType("bigint"); + + b.Property("MeannessFilterLevel") + .HasColumnType("integer"); + + b.Property("ParentChannelId") + .HasColumnType("uuid"); + + b.Property("Protocol") + .HasColumnType("text"); + + b.Property("ReactionsPossible") + .HasColumnType("boolean"); + + b.HasKey("Id"); + + b.HasIndex("ParentChannelId"); + + b.ToTable("Channels"); + }); + + modelBuilder.Entity("vassago.Models.Configuration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property>("DiscordTokens") + .HasColumnType("text[]"); + + b.Property("ExchangePairsLocation") + .HasColumnType("text"); + + b.Property("KafkaBootstrap") + .HasColumnType("text"); + + b.Property("KafkaName") + .HasColumnType("text"); + + b.Property("SetupDiscordSlashCommands") + .HasColumnType("boolean"); + + b.Property>("TwitchConfigs") + .HasColumnType("text[]"); + + b.Property("reportedApiUrl") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Configurations"); + }); + + modelBuilder.Entity("vassago.Models.Message", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ActedOn") + .HasColumnType("boolean"); + + b.Property("AuthorId") + .HasColumnType("uuid"); + + b.Property("ChannelId") + .HasColumnType("uuid"); + + b.Property("Content") + .HasColumnType("text"); + + b.Property("ExternalId") + .HasColumnType("text"); + + b.Property("MentionsMe") + .HasColumnType("boolean"); + + b.Property("Protocol") + .HasColumnType("text"); + + b.Property("Timestamp") + .HasColumnType("timestamp with time zone"); + + b.Property("TranslatedContent") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("AuthorId"); + + b.HasIndex("ChannelId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("vassago.Models.UAC", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property>("CommandAlterations") + .HasColumnType("hstore"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("DisplayName") + .HasColumnType("text"); + + b.Property("OwnerId") + .HasColumnType("uuid"); + + b.Property>("Translations") + .HasColumnType("hstore"); + + b.HasKey("Id"); + + b.ToTable("UACs"); + }); + + modelBuilder.Entity("vassago.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("AccountUAC", b => + { + b.HasOne("vassago.Models.Account", null) + .WithMany() + .HasForeignKey("AccountInChannelsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("vassago.Models.UAC", null) + .WithMany() + .HasForeignKey("UACsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ChannelUAC", b => + { + b.HasOne("vassago.Models.Channel", null) + .WithMany() + .HasForeignKey("ChannelsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("vassago.Models.UAC", null) + .WithMany() + .HasForeignKey("UACsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("UACUser", b => + { + b.HasOne("vassago.Models.UAC", null) + .WithMany() + .HasForeignKey("UACsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("vassago.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("vassago.Models.Account", b => + { + b.HasOne("vassago.Models.User", "IsUser") + .WithMany("Accounts") + .HasForeignKey("IsUserId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("vassago.Models.Channel", "SeenInChannel") + .WithMany("Users") + .HasForeignKey("SeenInChannelId") + .OnDelete(DeleteBehavior.Cascade); + + b.Navigation("IsUser"); + + b.Navigation("SeenInChannel"); + }); + + modelBuilder.Entity("vassago.Models.Attachment", b => + { + b.HasOne("vassago.Models.Message", "Message") + .WithMany("Attachments") + .HasForeignKey("MessageId") + .OnDelete(DeleteBehavior.Cascade); + + b.Navigation("Message"); + }); + + modelBuilder.Entity("vassago.Models.Channel", b => + { + b.HasOne("vassago.Models.Channel", "ParentChannel") + .WithMany("SubChannels") + .HasForeignKey("ParentChannelId") + .OnDelete(DeleteBehavior.Cascade); + + b.Navigation("ParentChannel"); + }); + + modelBuilder.Entity("vassago.Models.Message", b => + { + b.HasOne("vassago.Models.Account", "Author") + .WithMany() + .HasForeignKey("AuthorId"); + + b.HasOne("vassago.Models.Channel", "Channel") + .WithMany("Messages") + .HasForeignKey("ChannelId") + .OnDelete(DeleteBehavior.Cascade); + + b.Navigation("Author"); + + b.Navigation("Channel"); + }); + + modelBuilder.Entity("vassago.Models.Channel", b => + { + b.Navigation("Messages"); + + b.Navigation("SubChannels"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("vassago.Models.Message", b => + { + b.Navigation("Attachments"); + }); + + modelBuilder.Entity("vassago.Models.User", b => + { + b.Navigation("Accounts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20250708171025_UnconfinguredWebhooks.cs b/Migrations/20250708171025_UnconfinguredWebhooks.cs new file mode 100644 index 0000000..eb6f0cf --- /dev/null +++ b/Migrations/20250708171025_UnconfinguredWebhooks.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace vassago.Migrations +{ + /// + public partial class UnconfinguredWebhooks : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Webhooks", + table: "Configurations"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn>( + name: "Webhooks", + table: "Configurations", + type: "text[]", + nullable: true); + } + } +} diff --git a/Migrations/ChattingContextModelSnapshot.cs b/Migrations/ChattingContextModelSnapshot.cs index 6a48c4b..cb68600 100644 --- a/Migrations/ChattingContextModelSnapshot.cs +++ b/Migrations/ChattingContextModelSnapshot.cs @@ -212,9 +212,6 @@ namespace vassago.Migrations b.Property>("TwitchConfigs") .HasColumnType("text[]"); - b.Property>("Webhooks") - .HasColumnType("text[]"); - b.Property("reportedApiUrl") .HasColumnType("text"); diff --git a/Models/Configuration.cs b/Models/Configuration.cs index 8c52a1d..c171130 100644 --- a/Models/Configuration.cs +++ b/Models/Configuration.cs @@ -21,7 +21,6 @@ public class Configuration public List TwitchConfigs { get; set; } public string ExchangePairsLocation { get; set; } = "assets/exchangepairs.json"; //TODO: have this be "exchange API key", so you can have it continually update. public bool SetupDiscordSlashCommands { get; set; } = false; //i'm kind of idealogically opposed to these. - public List Webhooks { get; set; } public string KafkaBootstrap { get; set; } = "http://localhost:9092"; public string KafkaName { get; set; } = "vassago"; public string reportedApiUrl { get; set; } = "http://localhost:5093/api"; diff --git a/Models/Webhook.cs b/Models/Webhook.cs new file mode 100644 index 0000000..5865213 --- /dev/null +++ b/Models/Webhook.cs @@ -0,0 +1,19 @@ +namespace vassago.Models; + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using vassago.Models; + +public class Webhook +{ + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + public UAC Uac {get;set;} + public string Trigger { get; set; } + public Uri Uri { get; set; } + public Enumerations.HttpVerb Method { 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 d3aff1e..9789e47 100644 --- a/WebInterface/Controllers/ConfigurationController.cs +++ b/WebInterface/Controllers/ConfigurationController.cs @@ -28,7 +28,6 @@ public class ConfigurationController() : Controller 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; @@ -100,30 +99,30 @@ public class ConfigurationController() : Controller 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 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"); - } + // [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"); - } + // 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 93e51b6..5addafc 100644 --- a/WebInterface/Views/Configuration/Index.cshtml +++ b/WebInterface/Views/Configuration/Index.cshtml @@ -62,45 +62,6 @@ - - Webhooks - - @{ - 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(); - } - - - - - - - - - - - - - - } - } - - - - - - @@ -150,33 +111,6 @@ - -
- trigger - - Uri - - Method - - Headers - - - Content - - Description - - - -
-
- -
- Are you sure? - - - -
-
@section scripts{ }