forked from adam/discord-bot-shtik
y'boi hates frontend
This commit is contained in:
parent
f6b0a736cd
commit
fc1e44e3dc
@ -10,6 +10,7 @@ using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using vassago.Models;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[StaticPlz]
|
||||
public class Webhook : Behavior
|
||||
@ -24,18 +25,13 @@ public class Webhook : Behavior
|
||||
private ConcurrentDictionary<Guid, WebhookActionOrder> authedCache = new ConcurrentDictionary<Guid, WebhookActionOrder>();
|
||||
private HttpClient hc = new HttpClient();
|
||||
|
||||
public static void SetupWebhooks(IConfigurationSection confSection)
|
||||
public static void SetupWebhooks(IEnumerable<string> confSection)
|
||||
{
|
||||
configuredWebhooks = confSection.Get<List<vassago.Behavior.WebhookConf>>();
|
||||
|
||||
foreach (var conf in configuredWebhooks)
|
||||
//configuredWebhooks = confSection.Get<List<vassago.Behavior.WebhookConf>>();
|
||||
if(confSection != null) foreach (var confLine in confSection)
|
||||
{
|
||||
var conf = JsonConvert.DeserializeObject<WebhookConf>(confLine);
|
||||
var confName = $"Webhook: {conf.Trigger}";
|
||||
Console.WriteLine($"confName: {confName}; conf.uri: {conf.Uri}, conf.uacID: {conf.uacID}, conf.Method: {conf.Method}, conf.Headers: {conf.Headers?.Count() ?? 0}, conf.Content: {conf.Content}");
|
||||
foreach (var kvp in conf.Headers)
|
||||
{
|
||||
Console.WriteLine($"{kvp[0]}: {kvp[1]}");
|
||||
}
|
||||
var changed = false;
|
||||
var myUAC = rememberer.SearchUAC(uac => uac.OwnerId == conf.uacID);
|
||||
if (myUAC == null)
|
||||
|
@ -7,24 +7,17 @@ namespace vassago
|
||||
using vassago.TwitchInterface;
|
||||
using vassago.ProtocolInterfaces.DiscordInterface;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
internal class ConsoleService : BackgroundService
|
||||
{
|
||||
public ConsoleService(IConfiguration aspConfig)
|
||||
{
|
||||
Shared.DBConnectionString = aspConfig["DBConnectionString"];
|
||||
Shared.SetupSlashCommands = aspConfig["SetupSlashCommands"]?.ToLower() == "true";
|
||||
Shared.API_URL = new Uri(aspConfig["API_URL"]);
|
||||
DiscordTokens = aspConfig.GetSection("DiscordTokens").Get<IEnumerable<string>>();
|
||||
TwitchConfigs = aspConfig.GetSection("TwitchConfigs").Get<IEnumerable<TwitchConfig>>();
|
||||
Conversion.Converter.Load(aspConfig["ExchangePairsLocation"]);
|
||||
Telefranz.Configure(aspConfig["KafkaName"], aspConfig["KafkaBootstrap"]);
|
||||
Console.WriteLine($"Telefranz.Configure({aspConfig["KafkaName"]}, {aspConfig["KafkaBootstrap"]});");
|
||||
vassago.Behavior.Webhook.SetupWebhooks(aspConfig.GetSection("Webhooks"));
|
||||
}
|
||||
|
||||
IEnumerable<string> DiscordTokens { get; }
|
||||
IEnumerable<TwitchConfig> TwitchConfigs { get; }
|
||||
List<string> DiscordTokens;
|
||||
List<TwitchConfig> TwitchConfigs;
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
@ -32,6 +25,14 @@ namespace vassago
|
||||
var dbc = new ChattingContext();
|
||||
await dbc.Database.MigrateAsync(cancellationToken);
|
||||
|
||||
var confEntity = dbc.Configurations.FirstOrDefault() ?? new Configuration();
|
||||
if (dbc.Configurations.Count() == 0)
|
||||
{
|
||||
dbc.Configurations.Add(confEntity);
|
||||
dbc.SaveChanges();
|
||||
}
|
||||
dbConfig(ref confEntity);
|
||||
|
||||
if (DiscordTokens?.Any() ?? false)
|
||||
foreach (var dt in DiscordTokens)
|
||||
{
|
||||
@ -47,9 +48,22 @@ namespace vassago
|
||||
initTasks.Add(t.Init(tc));
|
||||
Shared.ProtocolList.Add(t);
|
||||
}
|
||||
|
||||
|
||||
Task.WaitAll(initTasks.ToArray(), cancellationToken);
|
||||
}
|
||||
|
||||
private void dbConfig(ref vassago.Models.Configuration confEntity)
|
||||
{
|
||||
Shared.SetupSlashCommands = confEntity.SetupDiscordSlashCommands;
|
||||
Shared.API_URL = new Uri(confEntity.reportedApiUrl);
|
||||
DiscordTokens = confEntity.DiscordTokens;
|
||||
TwitchConfigs = new List<TwitchConfig>();
|
||||
if(confEntity.TwitchConfigs != null) foreach (var twitchConfString in confEntity.TwitchConfigs)
|
||||
{
|
||||
TwitchConfigs.Add(JsonConvert.DeserializeObject<TwitchConfig>(twitchConfString));
|
||||
}
|
||||
Conversion.Converter.Load(confEntity.ExchangePairsLocation);
|
||||
Telefranz.Configure(confEntity.KafkaName, confEntity.KafkaBootstrap);
|
||||
vassago.Behavior.Webhook.SetupWebhooks(confEntity.Webhooks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
427
Migrations/20250628034005_ConfigInDatabase.Designer.cs
generated
Normal file
427
Migrations/20250628034005_ConfigInDatabase.Designer.cs
generated
Normal file
@ -0,0 +1,427 @@
|
||||
// <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("20250628034005_ConfigInDatabase")]
|
||||
partial class ConfigInDatabase
|
||||
{
|
||||
/// <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<List<string>>("Webhooks")
|
||||
.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
|
||||
}
|
||||
}
|
||||
}
|
42
Migrations/20250628034005_ConfigInDatabase.cs
Normal file
42
Migrations/20250628034005_ConfigInDatabase.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace vassago.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ConfigInDatabase : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Configurations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
DiscordTokens = table.Column<List<string>>(type: "text[]", nullable: true),
|
||||
TwitchConfigs = table.Column<List<string>>(type: "text[]", nullable: true),
|
||||
ExchangePairsLocation = table.Column<string>(type: "text", nullable: true),
|
||||
SetupDiscordSlashCommands = table.Column<bool>(type: "boolean", nullable: false),
|
||||
Webhooks = table.Column<List<string>>(type: "text[]", nullable: true),
|
||||
KafkaBootstrap = table.Column<string>(type: "text", nullable: true),
|
||||
KafkaName = table.Column<string>(type: "text", nullable: true),
|
||||
reportedApiUrl = table.Column<string>(type: "text", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Configurations", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Configurations");
|
||||
}
|
||||
}
|
||||
}
|
@ -188,6 +188,41 @@ namespace vassago.Migrations
|
||||
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<List<string>>("Webhooks")
|
||||
.HasColumnType("text[]");
|
||||
|
||||
b.Property<string>("reportedApiUrl")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Configurations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("vassago.Models.Message", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
|
@ -11,6 +11,7 @@ public class ChattingContext : DbContext
|
||||
public DbSet<Message> Messages { get; set; }
|
||||
public DbSet<Account> Accounts { get; set; }
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<Configuration> Configurations {get; set;}
|
||||
|
||||
public ChattingContext(DbContextOptions<ChattingContext> options) : base(options) { }
|
||||
public ChattingContext() : base() { }
|
||||
|
28
Models/Configuration.cs
Normal file
28
Models/Configuration.cs
Normal file
@ -0,0 +1,28 @@
|
||||
namespace vassago.Models;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.WebSocket;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using vassago.TwitchInterface;
|
||||
using vassago.Behavior;
|
||||
|
||||
//TODO: it feels gross to have a *table* in a database that's intended to hold 1 **UND EXACTLY ONE** row, ever.
|
||||
//but also it feels worse to scatter my configuraiton-y data across external files and the database.
|
||||
|
||||
public class Configuration
|
||||
{
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public Guid Id { get; set; }
|
||||
public List<string> DiscordTokens { 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 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 KafkaName { get; set; } = "vassago";
|
||||
public string reportedApiUrl { get; set; } = "http://localhost:5093/api";
|
||||
}
|
@ -347,4 +347,11 @@ public class Rememberer
|
||||
if (toRemember.Channels?.Count() > 0)
|
||||
cacheChannels();
|
||||
}
|
||||
public Configuration Configuration()
|
||||
{
|
||||
dbAccessSemaphore.Wait();
|
||||
var toReturn = db.Configurations.FirstOrDefault();
|
||||
dbAccessSemaphore.Release();
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
28
WebInterface/Controllers/ConfigurationController.cs
Normal file
28
WebInterface/Controllers/ConfigurationController.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using vassago;
|
||||
using vassago.Behavior;
|
||||
using vassago.Models;
|
||||
using vassago.WebInterface.Models;
|
||||
|
||||
namespace vassago.WebInterface.Controllers;
|
||||
|
||||
public class ConfigurationController() : Controller
|
||||
{
|
||||
private static Rememberer r = Rememberer.Instance;
|
||||
public IActionResult Index()
|
||||
{
|
||||
var conf = r.Configuration() ?? new Configuration();
|
||||
ViewData.Add("Serialized", JsonConvert.SerializeObject(conf));
|
||||
return View(conf);
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorPageViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
@ -27,6 +27,8 @@ public class HomeController : Controller
|
||||
var sb = new StringBuilder();
|
||||
sb.Append('[');
|
||||
|
||||
sb.Append($"{{\"text\": \"<a href=\\\"{Url.ActionLink(action: "Index", controller: "Configuration")}\\\">Configuration</a>\"}},");
|
||||
|
||||
//UACs
|
||||
var allUACs = r.UACsOverview();
|
||||
var first = true;
|
||||
@ -81,7 +83,6 @@ public class HomeController : Controller
|
||||
sb.Append("]}");
|
||||
}
|
||||
|
||||
//type error, e is not defined
|
||||
//channels
|
||||
sb.Append(",{text: \"channels\", expanded:true, nodes: [");
|
||||
var topLevelChannels = r.ChannelsOverview().Where(x => x.ParentChannel == null).ToList();
|
||||
|
65
WebInterface/Views/Configuration/Index.cshtml
Normal file
65
WebInterface/Views/Configuration/Index.cshtml
Normal file
@ -0,0 +1,65 @@
|
||||
@model vassago.Models.Configuration
|
||||
@{
|
||||
}
|
||||
<a href="/">home</a>/configuration
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">Discord</th>
|
||||
<td><div id="discordTree"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label class="form-check-label" for="SetupDiscordSlashCommands">Setup Discord Slash Commands</label>
|
||||
<td><input type="checkbox" class="form-control" id="SetupDiscordSlashCommands" checked="@Model.SetupDiscordSlashCommands"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Twitch</th>
|
||||
<td><div id="twitchTree"/></td>
|
||||
</tr>
|
||||
<tr class="form-text">
|
||||
<th><label for="ExchangePairsLocation">Exchange Pairs Location</label></th>
|
||||
<td><input type="text" class="form-control" id="ExchangePairsLocation" value="@Model.ExchangePairsLocation"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Webhooks</th>
|
||||
<td><div id="webhooksTree"/></td>
|
||||
</tr>
|
||||
<tr class="form-text">
|
||||
<th><label for="KafkaBootstrap">Kafka Bootstrap Server</label></th>
|
||||
<td><input type="text" class="form-control" id="KafkaBootstrap" value="@Model.KafkaBootstrap"/></td>
|
||||
</tr>
|
||||
<tr class="form-text">
|
||||
<th><label for="KafkaName">Kafka Name</label></th>
|
||||
<td><input type="text" class="form-control" id="KafkaName" value="@Model.KafkaName"/></td>
|
||||
</tr>
|
||||
<tr class="form-text">
|
||||
<th><label for="reportedApiUrlKafkaName">reportedApiUrl</label></th>
|
||||
<td><input type="text" class="form-control" id="reportedApiUrl" value="@Model.reportedApiUrl"/></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
@section Scripts{
|
||||
<script type="text/javascript">
|
||||
var theModel = JSON.parse(@Html.Raw(ViewData["serialized"]));
|
||||
function discordTokenNode(tokenText, id){
|
||||
return "{ \"text\": \"<input type=\\\"text\\\" class=\\\"form-control\\\"" +
|
||||
"id=\\\"discordToken[" + id + "]\\\" +
|
||||
"value=\\\"" + tokenText + "\\\"/>" +
|
||||
"<button class=\\\"btn btn-danger\\\" onclick=\\\"removeDiscordToken(" + id + ")\\\">delete</button>" +
|
||||
"\"},";
|
||||
}
|
||||
function discordTree() {
|
||||
var treeStr = "[";
|
||||
theModel.DiscordTokens.forEach((token, idx) => {
|
||||
treeStr += discordTokenNode(token, idx);
|
||||
});
|
||||
|
||||
|
||||
console.log(tree);
|
||||
return treeStr;
|
||||
}
|
||||
$('#discordTree').bstreeview({ data: discordTree() });
|
||||
</script>
|
||||
}
|
Loading…
Reference in New Issue
Block a user