forked from adam/discord-bot-shtik
configurations but not webhooks
All checks were successful
gitea.arg.rip/vassago/pipeline/head This commit looks good
All checks were successful
gitea.arg.rip/vassago/pipeline/head This commit looks good
see #47
This commit is contained in:
parent
2ce4656ac5
commit
65b3985b14
@ -28,39 +28,39 @@ public class Webhook : Behavior
|
|||||||
public static void SetupWebhooks(IEnumerable<string> confSection)
|
public static void SetupWebhooks(IEnumerable<string> confSection)
|
||||||
{
|
{
|
||||||
//configuredWebhooks = confSection.Get<List<vassago.Behavior.WebhookConf>>();
|
//configuredWebhooks = confSection.Get<List<vassago.Behavior.WebhookConf>>();
|
||||||
if(confSection != null) foreach (var confLine in confSection)
|
if (confSection != null) foreach (var confLine in confSection)
|
||||||
{
|
|
||||||
var conf = JsonConvert.DeserializeObject<WebhookConf>(confLine);
|
|
||||||
var confName = $"Webhook: {conf.Trigger}";
|
|
||||||
var changed = false;
|
|
||||||
var myUAC = rememberer.SearchUAC(uac => uac.OwnerId == conf.uacID);
|
|
||||||
if (myUAC == null)
|
|
||||||
{
|
{
|
||||||
myUAC = new()
|
var conf = JsonConvert.DeserializeObject<WebhookConf>(confLine);
|
||||||
|
var confName = $"Webhook: {conf.Trigger}";
|
||||||
|
var changed = false;
|
||||||
|
var myUAC = rememberer.SearchUAC(uac => uac.OwnerId == conf.uacID);
|
||||||
|
if (myUAC == null)
|
||||||
{
|
{
|
||||||
OwnerId = conf.uacID,
|
myUAC = new()
|
||||||
DisplayName = confName,
|
{
|
||||||
Description = conf.Description
|
OwnerId = conf.uacID,
|
||||||
};
|
DisplayName = confName,
|
||||||
changed = true;
|
Description = conf.Description
|
||||||
rememberer.RememberUAC(myUAC);
|
};
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (myUAC.DisplayName != confName)
|
|
||||||
{
|
|
||||||
myUAC.DisplayName = confName;
|
|
||||||
changed = true;
|
changed = true;
|
||||||
|
rememberer.RememberUAC(myUAC);
|
||||||
}
|
}
|
||||||
if (myUAC.Description != conf.Description)
|
else
|
||||||
{
|
{
|
||||||
myUAC.Description = conf.Description;
|
if (myUAC.DisplayName != confName)
|
||||||
changed = true;
|
{
|
||||||
|
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<UAC> matchedUACs)
|
public override bool ShouldAct(Message message, List<UAC> matchedUACs)
|
||||||
@ -111,10 +111,11 @@ public class Webhook : Behavior
|
|||||||
}
|
}
|
||||||
var msg = translate(actionOrder, message);
|
var msg = translate(actionOrder, message);
|
||||||
var req = new HttpRequestMessage(new HttpMethod(actionOrder.Conf.Method.ToString()), actionOrder.Conf.Uri);
|
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");
|
var theContentHeader = actionOrder.Conf.Headers?.FirstOrDefault(h => h?.ToLower().StartsWith("content-type:") ?? false);
|
||||||
if (theContentHeader != null)
|
var contentHeaderVal = theContentHeader?.Split(':')?[1]?.ToLower();
|
||||||
|
if (contentHeaderVal != null)
|
||||||
{
|
{
|
||||||
switch (theContentHeader[1]?.ToLower())
|
switch (contentHeaderVal)
|
||||||
{
|
{
|
||||||
//json content is constructed some other weird way.
|
//json content is constructed some other weird way.
|
||||||
case "multipart/form-data":
|
case "multipart/form-data":
|
||||||
@ -124,7 +125,7 @@ public class Webhook : Behavior
|
|||||||
req.Content = new System.Net.Http.StringContent(msg);
|
req.Content = new System.Net.Http.StringContent(msg);
|
||||||
break;
|
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)
|
if (req.Content == null)
|
||||||
{
|
{
|
||||||
@ -133,17 +134,16 @@ public class Webhook : Behavior
|
|||||||
Console.WriteLine($"survived translating string content. request content: {req.Content}");
|
Console.WriteLine($"survived translating string content. request content: {req.Content}");
|
||||||
if (actionOrder.Conf.Headers?.ToList().Count > 0)
|
if (actionOrder.Conf.Headers?.ToList().Count > 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine("will add headers.");
|
foreach (var header in actionOrder.Conf.Headers.ToList())
|
||||||
foreach (var kvp in actionOrder.Conf.Headers.ToList())
|
|
||||||
{
|
{
|
||||||
if (kvp[0] == theContentHeader[0])
|
if (header?.ToLower().StartsWith("content-type:") ?? false)
|
||||||
{
|
{
|
||||||
Console.WriteLine("content header; skipping.");
|
Console.WriteLine("content header; skipping.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine($"adding header; {kvp[0]}: {kvp[1]}");
|
Console.WriteLine($"adding header; {header}");
|
||||||
req.Headers.Add(kvp[0], kvp[1]);
|
req.Headers.Add(header.Split(':')[0], header.Split(':')[1]);
|
||||||
Console.WriteLine("survived.");
|
Console.WriteLine("survived.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,6 @@ namespace vassago
|
|||||||
}
|
}
|
||||||
Conversion.Converter.Load(confEntity.ExchangePairsLocation);
|
Conversion.Converter.Load(confEntity.ExchangePairsLocation);
|
||||||
Telefranz.Configure(confEntity.KafkaName, confEntity.KafkaBootstrap);
|
Telefranz.Configure(confEntity.KafkaName, confEntity.KafkaBootstrap);
|
||||||
vassago.Behavior.Webhook.SetupWebhooks(confEntity.Webhooks);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
424
Migrations/20250708171025_UnconfinguredWebhooks.Designer.cs
generated
Normal file
424
Migrations/20250708171025_UnconfinguredWebhooks.Designer.cs
generated
Normal file
@ -0,0 +1,424 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
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
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
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<Guid>("AccountInChannelsId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("UACsId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("AccountInChannelsId", "UACsId");
|
||||||
|
|
||||||
|
b.HasIndex("UACsId");
|
||||||
|
|
||||||
|
b.ToTable("AccountUAC");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("ChannelUAC", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("ChannelsId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("UACsId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("ChannelsId", "UACsId");
|
||||||
|
|
||||||
|
b.HasIndex("UACsId");
|
||||||
|
|
||||||
|
b.ToTable("ChannelUAC");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("UACUser", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("UACsId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("UsersId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("UACsId", "UsersId");
|
||||||
|
|
||||||
|
b.HasIndex("UsersId");
|
||||||
|
|
||||||
|
b.ToTable("UACUser");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("vassago.Models.Account", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("DisplayName")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ExternalId")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool>("IsBot")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<Guid?>("IsUserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Protocol")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid?>("SeenInChannelId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("IsUserId");
|
||||||
|
|
||||||
|
b.HasIndex("SeenInChannelId");
|
||||||
|
|
||||||
|
b.ToTable("Accounts");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("vassago.Models.Attachment", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<byte[]>("Content")
|
||||||
|
.HasColumnType("bytea");
|
||||||
|
|
||||||
|
b.Property<string>("ContentType")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<decimal?>("ExternalId")
|
||||||
|
.HasColumnType("numeric(20,0)");
|
||||||
|
|
||||||
|
b.Property<string>("Filename")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid?>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<int>("Size")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Source")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MessageId");
|
||||||
|
|
||||||
|
b.ToTable("Attachments");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("vassago.Models.Channel", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<int>("ChannelType")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("DisplayName")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ExternalId")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int?>("LewdnessFilterLevel")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<bool?>("LinksAllowed")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<decimal?>("MaxAttachmentBytes")
|
||||||
|
.HasColumnType("numeric(20,0)");
|
||||||
|
|
||||||
|
b.Property<long?>("MaxTextChars")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<int?>("MeannessFilterLevel")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<Guid?>("ParentChannelId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Protocol")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool?>("ReactionsPossible")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ParentChannelId");
|
||||||
|
|
||||||
|
b.ToTable("Channels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("vassago.Models.Configuration", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<List<string>>("DiscordTokens")
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<string>("ExchangePairsLocation")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("KafkaBootstrap")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("KafkaName")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool>("SetupDiscordSlashCommands")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<List<string>>("TwitchConfigs")
|
||||||
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
|
b.Property<string>("reportedApiUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Configurations");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("vassago.Models.Message", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<bool>("ActedOn")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<Guid?>("AuthorId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid?>("ChannelId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Content")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ExternalId")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool>("MentionsMe")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("Protocol")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("Timestamp")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("TranslatedContent")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("AuthorId");
|
||||||
|
|
||||||
|
b.HasIndex("ChannelId");
|
||||||
|
|
||||||
|
b.ToTable("Messages");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("vassago.Models.UAC", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Dictionary<string, string>>("CommandAlterations")
|
||||||
|
.HasColumnType("hstore");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("DisplayName")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid>("OwnerId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Dictionary<string, string>>("Translations")
|
||||||
|
.HasColumnType("hstore");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("UACs");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("vassago.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
Migrations/20250708171025_UnconfinguredWebhooks.cs
Normal file
29
Migrations/20250708171025_UnconfinguredWebhooks.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace vassago.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class UnconfinguredWebhooks : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Webhooks",
|
||||||
|
table: "Configurations");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<List<string>>(
|
||||||
|
name: "Webhooks",
|
||||||
|
table: "Configurations",
|
||||||
|
type: "text[]",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -212,9 +212,6 @@ namespace vassago.Migrations
|
|||||||
b.Property<List<string>>("TwitchConfigs")
|
b.Property<List<string>>("TwitchConfigs")
|
||||||
.HasColumnType("text[]");
|
.HasColumnType("text[]");
|
||||||
|
|
||||||
b.Property<List<string>>("Webhooks")
|
|
||||||
.HasColumnType("text[]");
|
|
||||||
|
|
||||||
b.Property<string>("reportedApiUrl")
|
b.Property<string>("reportedApiUrl")
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ public class Configuration
|
|||||||
public List<string> TwitchConfigs { get; set; }
|
public List<string> 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 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 bool SetupDiscordSlashCommands { get; set; } = false; //i'm kind of idealogically opposed to these.
|
||||||
public List<string> Webhooks { get; set; }
|
|
||||||
public string KafkaBootstrap { get; set; } = "http://localhost:9092";
|
public string KafkaBootstrap { get; set; } = "http://localhost:9092";
|
||||||
public string KafkaName { get; set; } = "vassago";
|
public string KafkaName { get; set; } = "vassago";
|
||||||
public string reportedApiUrl { get; set; } = "http://localhost:5093/api";
|
public string reportedApiUrl { get; set; } = "http://localhost:5093/api";
|
||||||
|
19
Models/Webhook.cs
Normal file
19
Models/Webhook.cs
Normal file
@ -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<string> Headers { get; set; }
|
||||||
|
public string Content { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
}
|
@ -28,7 +28,6 @@ public class ConfigurationController() : Controller
|
|||||||
conf.TwitchConfigs = incoming.TwitchConfigs;
|
conf.TwitchConfigs = incoming.TwitchConfigs;
|
||||||
conf.ExchangePairsLocation = incoming.ExchangePairsLocation;
|
conf.ExchangePairsLocation = incoming.ExchangePairsLocation;
|
||||||
conf.SetupDiscordSlashCommands = incoming.SetupDiscordSlashCommands;
|
conf.SetupDiscordSlashCommands = incoming.SetupDiscordSlashCommands;
|
||||||
conf.Webhooks = incoming.Webhooks;
|
|
||||||
conf.KafkaBootstrap = incoming.KafkaBootstrap;
|
conf.KafkaBootstrap = incoming.KafkaBootstrap;
|
||||||
conf.KafkaName = incoming.KafkaName;
|
conf.KafkaName = incoming.KafkaName;
|
||||||
conf.reportedApiUrl = incoming.reportedApiUrl;
|
conf.reportedApiUrl = incoming.reportedApiUrl;
|
||||||
@ -100,30 +99,30 @@ public class ConfigurationController() : Controller
|
|||||||
return RedirectToAction("Index", "Configuration");
|
return RedirectToAction("Index", "Configuration");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
// [HttpPost]
|
||||||
public IActionResult AddWebhook(WebhookConf newWebhook)
|
// public IActionResult AddWebhook(WebhookConf newWebhook)
|
||||||
{
|
// {
|
||||||
Console.WriteLine($"adding webhook, {newWebhook}");
|
// Console.WriteLine($"adding webhook, {newWebhook}");
|
||||||
var conf = r.Configuration();
|
// var conf = r.Configuration();
|
||||||
conf.Webhooks??= [];
|
// conf.Webhooks??= [];
|
||||||
conf.Webhooks.Add(JsonConvert.SerializeObject(newWebhook));
|
// conf.Webhooks.Add(JsonConvert.SerializeObject(newWebhook));
|
||||||
r.RememberConfiguration(conf);
|
// r.RememberConfiguration(conf);
|
||||||
return RedirectToAction("Index", "Configuration");
|
// return RedirectToAction("Index", "Configuration");
|
||||||
}
|
// }
|
||||||
|
|
||||||
[HttpPost]
|
// [HttpPost]
|
||||||
public IActionResult RemoveWebhook(int index)
|
// public IActionResult RemoveWebhook(int index)
|
||||||
{
|
// {
|
||||||
Console.WriteLine($"removing webhook[{index}]");
|
// Console.WriteLine($"removing webhook[{index}]");
|
||||||
var conf = r.Configuration();
|
// var conf = r.Configuration();
|
||||||
if (conf.Webhooks?.Count <= index)
|
// if (conf.Webhooks?.Count <= index)
|
||||||
{
|
// {
|
||||||
Console.Error.WriteLine("error removing webhook {index} from configuration, only have {conf.Webhooks?.Count}.");
|
// Console.Error.WriteLine("error removing webhook {index} from configuration, only have {conf.Webhooks?.Count}.");
|
||||||
return RedirectToAction("Index", "Configuration");
|
// return RedirectToAction("Index", "Configuration");
|
||||||
}
|
// }
|
||||||
|
|
||||||
conf.Webhooks.RemoveAt(index);
|
// conf.Webhooks.RemoveAt(index);
|
||||||
r.RememberConfiguration(conf);
|
// r.RememberConfiguration(conf);
|
||||||
return RedirectToAction("Index", "Configuration");
|
// return RedirectToAction("Index", "Configuration");
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -62,45 +62,6 @@
|
|||||||
<th><label for="ExchangePairsLocation">Exchange Pairs Location</label></th>
|
<th><label for="ExchangePairsLocation">Exchange Pairs Location</label></th>
|
||||||
<td><input type="text" class="form-control" name="ExchangePairsLocation" value="@Model.ExchangePairsLocation"/></td>
|
<td><input type="text" class="form-control" name="ExchangePairsLocation" value="@Model.ExchangePairsLocation"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<th colspan="2">Webhooks</th>
|
|
||||||
</tr>
|
|
||||||
@{
|
|
||||||
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<WebhookConf>(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();
|
|
||||||
}
|
|
||||||
<tr>
|
|
||||||
<th><label for="Webhooks[@i]">@wh.Trigger</label></th>
|
|
||||||
<td>
|
|
||||||
<input type="hidden" name="Webhooks[@i]" id="Webhooks_@i" value="@Model.Webhooks[i]" />
|
|
||||||
<input type="text" class="form-control" data-name="Trigger" value="@wh.Trigger"/>
|
|
||||||
<input type="text" class="form-control" data-name="Uri" value="@wh.Uri"/>
|
|
||||||
<input type="text" class="form-control" data-name="Method" value="@wh.Method"/>
|
|
||||||
<input type="textarea" class="form-control" data-name="Headers" value="@sb.ToString()"/>
|
|
||||||
<input type="text" class="form-control" data-name="Content" value="@wh.Content"/>
|
|
||||||
<input type="text" class="form-control" data-name="Description" value="@wh.Description"/>
|
|
||||||
<button type="button" onclick="removeWebhook(@i);" class="btn btn-danger">del</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
<tr>
|
|
||||||
<td></td>
|
|
||||||
<td>
|
|
||||||
<button type="button" onclick="addWebhookDialog.showModal()">add</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr class="form-text">
|
<tr class="form-text">
|
||||||
<th><label for="KafkaBootstrap">Kafka Bootstrap Server</label></th>
|
<th><label for="KafkaBootstrap">Kafka Bootstrap Server</label></th>
|
||||||
<td><input type="text" class="form-control" name="KafkaBootstrap" value="@Model.KafkaBootstrap"/></td>
|
<td><input type="text" class="form-control" name="KafkaBootstrap" value="@Model.KafkaBootstrap"/></td>
|
||||||
@ -150,33 +111,6 @@
|
|||||||
<button class="btn btn-danger" type="submit">delete</button>
|
<button class="btn btn-danger" type="submit">delete</button>
|
||||||
</form>
|
</form>
|
||||||
</dialog>
|
</dialog>
|
||||||
<dialog id="addWebhookDialog">
|
|
||||||
<form action="@Url.Action("AddWebhook", "Configuration")" method="post">
|
|
||||||
trigger
|
|
||||||
<input type="text" class="form-control" name="Trigger" />
|
|
||||||
Uri
|
|
||||||
<input type="text" class="form-control" name="Uri" />
|
|
||||||
Method
|
|
||||||
<input type="text" class="form-control" name="Method" />
|
|
||||||
Headers
|
|
||||||
<input type="textarea" class="form-control" id="newWebhookHeaders" />
|
|
||||||
<input type="hidden" name="Headers" />
|
|
||||||
Content
|
|
||||||
<input type="text" class="form-control" name="Content" />
|
|
||||||
Description
|
|
||||||
<input type="text" class="form-control" name="Description" />
|
|
||||||
<button class="btn btn-secondary" type="button" onclick="addWebhookDialog.close()">cancel</button>
|
|
||||||
<button class="btn btn-success" type="button" onclick="addWebhookComplexSubmit()">save</button>
|
|
||||||
</form>
|
|
||||||
</dialog>
|
|
||||||
<dialog id="removeWebhookDialog">
|
|
||||||
<form action="@Url.Action("RemoveWebhook", "Configuration")" method="post">
|
|
||||||
Are you sure?
|
|
||||||
<input type="hidden" name="id" id="removeWebhookTarget" />
|
|
||||||
<button class="btn btn-secondary" type="button" onclick="removeWebhookDialog.close()">cancel</button>
|
|
||||||
<button class="btn btn-danger" type="submit">delete</button>
|
|
||||||
</form>
|
|
||||||
</dialog>
|
|
||||||
@section scripts{
|
@section scripts{
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
@ -189,10 +123,6 @@ function removeTwitch(idx){
|
|||||||
removeTwitchTarget.value = idx;
|
removeTwitchTarget.value = idx;
|
||||||
removeTwitchDialog.showModal();
|
removeTwitchDialog.showModal();
|
||||||
}
|
}
|
||||||
function removeWebhook(idx){
|
|
||||||
removeWebhookTarget.value = idx;
|
|
||||||
removeWebhookDialog.showModal();
|
|
||||||
}
|
|
||||||
function complexSubmit()
|
function complexSubmit()
|
||||||
{
|
{
|
||||||
for (let i = 0; true; i++)
|
for (let i = 0; true; i++)
|
||||||
@ -210,74 +140,7 @@ function complexSubmit()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let i = 0; true; i++)
|
|
||||||
{
|
|
||||||
let thisCell = document.querySelector("td>#Webhooks_" + i);
|
|
||||||
if(thisCell !== null)
|
|
||||||
{
|
|
||||||
let nextCell = thisCell;
|
|
||||||
let asObj = {};
|
|
||||||
while(true){
|
|
||||||
nextCell = nextCell.nextElementSibling;
|
|
||||||
if(nextCell == null)
|
|
||||||
break;
|
|
||||||
if(!nextCell.hasAttribute("data-name"))
|
|
||||||
continue;
|
|
||||||
let dataname = nextCell.attributes["data-name"].value;
|
|
||||||
if(nextCell.value != "")
|
|
||||||
{
|
|
||||||
if(dataname == "Headers")
|
|
||||||
{
|
|
||||||
asObj["Headers"] = [];
|
|
||||||
let headerArray = nextCell.value.split('\n');
|
|
||||||
headerArray.forEach((elem) => {
|
|
||||||
if(elem.indexOf(":") > -1)
|
|
||||||
{
|
|
||||||
asObj["Headers"].push(elem.split(":"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
asObj[dataname] = nextCell.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
thisCell.value = JSON.stringify(asObj);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
theForm.submit();
|
theForm.submit();
|
||||||
}
|
}
|
||||||
function addWebhookComplexSubmit()
|
|
||||||
{
|
|
||||||
let headersInput = document.querySelector("#newWebhookHeaders");
|
|
||||||
if(headersInput.value != "")
|
|
||||||
{
|
|
||||||
if(headersInput.value.indexOf("\n") == -1)
|
|
||||||
{
|
|
||||||
headersInput.value += "\n";
|
|
||||||
}
|
|
||||||
let headers = headersInput.value.split("\n");
|
|
||||||
let i = 0;
|
|
||||||
headers.forEach((headerInputLine) => {
|
|
||||||
console.log(headerInputLine);
|
|
||||||
if(headerInputLine.indexOf(":") > -1)
|
|
||||||
{
|
|
||||||
var newElem = document.createElement("input");
|
|
||||||
newElem.setAttribute("type", "hidden");
|
|
||||||
newElem.setAttribute("name", "Headers[" + i + "]");
|
|
||||||
newElem.value = JSON.stringify(headerInputLine.split(":"));
|
|
||||||
headersInput.parentElement.appendChild(newElem);
|
|
||||||
console.log(newElem.value);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
document.querySelector("#addWebhookDialog form").submit();
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user