diff --git a/Behavior/Joke.cs b/Behavior/Joke.cs index 6be0178..f7eb1b5 100644 --- a/Behavior/Joke.cs +++ b/Behavior/Joke.cs @@ -38,7 +38,7 @@ public class Joke : Behavior var punchline = thisJoke.Substring(firstIndexAfterQuestionMark, thisJoke.Length - firstIndexAfterQuestionMark).Trim(); Task.WaitAll(message.Channel.SendMessage(straightline)); Thread.Sleep(TimeSpan.FromSeconds(Shared.r.Next(5, 30))); - //if (Shared.r.Next(8) == 0) + if (message.Channel.EffectivePermissions.ReactionsPossible == true && Shared.r.Next(8) == 0) { Behaver.Behaviors.Add(new LaughAtOwnJoke(punchline)); } diff --git a/Configuration.cs b/Configuration.cs index 52bcf24..90b4eff 100644 --- a/Configuration.cs +++ b/Configuration.cs @@ -9,7 +9,7 @@ namespace vassago { public string ExchangePairsLocation { get; set; } public IEnumerable DiscordTokens { get; set; } - public IEnumerable> TwitchTokens { get; set; } + public IEnumerable TwitchConfigs { get; set; } public string DBConnectionString { get; set; } } } \ No newline at end of file diff --git a/ConsoleService.cs b/ConsoleService.cs index 905f22e..427aa0b 100644 --- a/ConsoleService.cs +++ b/ConsoleService.cs @@ -7,13 +7,14 @@ namespace vassago { Configuration config = new Configuration(); private List discords = new List(); + private List twitchs = new List(); public ConsoleService(IConfiguration aspConfig) { config.DBConnectionString = aspConfig["DBConnectionString"]; config.ExchangePairsLocation = aspConfig["ExchangePairsLocation"]; config.DiscordTokens = aspConfig.GetSection("DiscordTokens").Get>(); - //config.TwitchTokens = aspConfig["TwitchTokens"]; + config.TwitchConfigs = aspConfig.GetSection("TwitchConfigs").Get>(); } public async Task StartAsync(CancellationToken cancellationToken) @@ -23,13 +24,22 @@ namespace vassago dbc.Database.EnsureCreated(); Conversion.Converter.Load(config.ExchangePairsLocation); - if (config.DiscordTokens.Any()) + + if (config.DiscordTokens?.Any() ?? false) foreach (var dt in config.DiscordTokens) { var d = new DiscordInterface.DiscordInterface(); await d.Init(dt); discords.Add(d); } + + if (config.TwitchConfigs?.Any() ?? false) + foreach (var tc in config.TwitchConfigs) + { + var t = new TwitchInterface.TwitchInterface(); + await t.Init(tc); + twitchs.Add(t); + } } public Task StopAsync(CancellationToken cancellationToken) diff --git a/DiscordInterface/DiscordInterface.cs b/DiscordInterface/DiscordInterface.cs index 586c638..ffb8280 100644 --- a/DiscordInterface/DiscordInterface.cs +++ b/DiscordInterface/DiscordInterface.cs @@ -52,7 +52,7 @@ public class DiscordInterface try { - protocolAsChannel = _db.Channels.FirstOrDefault(c => c.ParentChannel == null && c.Protocol == "discord"); + protocolAsChannel = _db.Channels.FirstOrDefault(c => c.ParentChannel == null && c.Protocol == PROTOCOL); if (protocolAsChannel == null) { protocolAsChannel = new Channel() @@ -211,7 +211,7 @@ public class DiscordInterface } internal Message UpsertMessage(IUserMessage dMessage) { - var m = _db.Messages.FirstOrDefault(mi => mi.ExternalId == dMessage.Id); + var m = _db.Messages.FirstOrDefault(mi => mi.ExternalId == dMessage.Id.ToString() && mi.Protocol == PROTOCOL); if (m == null) { m = new Message(); @@ -227,7 +227,7 @@ public class DiscordInterface } } m.Content = dMessage.Content; - m.ExternalId = dMessage.Id; + m.ExternalId = dMessage.Id.ToString(); m.Timestamp = dMessage.EditedTimestamp ?? dMessage.CreatedAt; m.Channel = UpsertChannel(dMessage.Channel); m.Author = UpsertAccount(dMessage.Author); @@ -245,7 +245,7 @@ public class DiscordInterface } internal Channel UpsertChannel(IMessageChannel channel) { - Channel c = _db.Channels.FirstOrDefault(ci => ci.ExternalId == channel.Id); + Channel c = _db.Channels.FirstOrDefault(ci => ci.ExternalId == channel.Id.ToString() && ci.Protocol == PROTOCOL); if (c == null) { c = new Channel(); @@ -253,7 +253,7 @@ public class DiscordInterface } c.DisplayName = channel.Name; - c.ExternalId = channel.Id; + c.ExternalId = channel.Id.ToString(); c.IsDM = channel is IPrivateChannel; c.Messages = c.Messages ?? new List(); c.Protocol = PROTOCOL; @@ -278,7 +278,7 @@ public class DiscordInterface } internal Channel UpsertChannel(IGuild channel) { - Channel c = _db.Channels.FirstOrDefault(ci => ci.ExternalId == channel.Id); + Channel c = _db.Channels.FirstOrDefault(ci => ci.ExternalId == channel.Id.ToString() && ci.Protocol == PROTOCOL); if (c == null) { c = new Channel(); @@ -286,7 +286,7 @@ public class DiscordInterface } c.DisplayName = channel.Name; - c.ExternalId = channel.Id; + c.ExternalId = channel.Id.ToString(); c.IsDM = false; c.Messages = c.Messages ?? new List(); c.Protocol = protocolAsChannel.Protocol; @@ -302,7 +302,7 @@ public class DiscordInterface internal Account UpsertAccount(IUser user) { var hadToAdd = false; - var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == user.Id); + var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == user.Id.ToString() && ui.Protocol == PROTOCOL); if (acc == null) { acc = new Account(); @@ -310,7 +310,7 @@ public class DiscordInterface hadToAdd = true; } acc.Username = user.Username; - acc.ExternalId = user.Id; + acc.ExternalId = user.Id.ToString(); acc.IsBot = user.IsBot || user.IsWebhook; acc.Protocol = PROTOCOL; @@ -328,7 +328,7 @@ public class DiscordInterface private Task attemptReact(IUserMessage msg, string e) { - var c = _db.Channels.FirstOrDefault(c => c.ExternalId == msg.Channel.Id); + var c = _db.Channels.FirstOrDefault(c => c.ExternalId == msg.Channel.Id.ToString()); //var preferredEmote = c.EmoteOverrides?[e] ?? e; //TODO: emote overrides var preferredEmote = e; Emoji emoji; diff --git a/Migrations/20230605152343_initial create.Designer.cs b/Migrations/20230605152343_initial create.Designer.cs deleted file mode 100644 index 25ec305..0000000 --- a/Migrations/20230605152343_initial create.Designer.cs +++ /dev/null @@ -1,319 +0,0 @@ -// -using System; -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("20230605152343_initial create")] - partial class initialcreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.5") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("ChannelUser", b => - { - b.Property("OtherUsersId") - .HasColumnType("uuid"); - - b.Property("SeenInChannelsId") - .HasColumnType("uuid"); - - b.HasKey("OtherUsersId", "SeenInChannelsId"); - - b.HasIndex("SeenInChannelsId"); - - b.ToTable("ChannelUser"); - }); - - 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("Discriminator") - .IsRequired() - .HasColumnType("text"); - - b.Property("DisplayName") - .HasColumnType("text"); - - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); - - b.Property("IsDM") - .HasColumnType("boolean"); - - b.Property("ParentChannelId") - .HasColumnType("uuid"); - - b.Property("PermissionsOverridesId") - .HasColumnType("integer"); - - b.Property("ProtocolId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("ParentChannelId"); - - b.HasIndex("PermissionsOverridesId"); - - b.HasIndex("ProtocolId"); - - b.ToTable("Channels"); - - b.HasDiscriminator("Discriminator").HasValue("Channel"); - - b.UseTphMappingStrategy(); - }); - - 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("numeric(20,0)"); - - b.Property("MentionsMe") - .HasColumnType("boolean"); - - b.Property("Timestamp") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("AuthorId"); - - b.HasIndex("ChannelId"); - - b.ToTable("Messages"); - }); - - modelBuilder.Entity("vassago.Models.PermissionSettings", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("LewdnessFilterLevel") - .HasColumnType("integer"); - - b.Property("LinksAllowed") - .HasColumnType("boolean"); - - b.Property("MaxAttachmentBytes") - .HasColumnType("bigint"); - - b.Property("MaxTextChars") - .HasColumnType("bigint"); - - b.Property("MeannessFilterLevel") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.ToTable("PermissionSettings"); - }); - - modelBuilder.Entity("vassago.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); - - b.Property("IsBot") - .HasColumnType("boolean"); - - b.Property("ProtocolId") - .HasColumnType("uuid"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("Username") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("ProtocolId"); - - b.HasIndex("UserId"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("vassago.Models.Protocol", b => - { - b.HasBaseType("vassago.Models.Channel"); - - b.Property("ConnectionToken") - .HasColumnType("text"); - - b.HasDiscriminator().HasValue("Protocol"); - }); - - modelBuilder.Entity("ChannelUser", b => - { - b.HasOne("vassago.Models.User", null) - .WithMany() - .HasForeignKey("OtherUsersId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("vassago.Models.Channel", null) - .WithMany() - .HasForeignKey("SeenInChannelsId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("vassago.Models.Attachment", b => - { - b.HasOne("vassago.Models.Message", "Message") - .WithMany("Attachments") - .HasForeignKey("MessageId"); - - b.Navigation("Message"); - }); - - modelBuilder.Entity("vassago.Models.Channel", b => - { - b.HasOne("vassago.Models.Channel", "ParentChannel") - .WithMany("SubChannels") - .HasForeignKey("ParentChannelId"); - - b.HasOne("vassago.Models.PermissionSettings", "PermissionsOverrides") - .WithMany() - .HasForeignKey("PermissionsOverridesId"); - - b.HasOne("vassago.Models.Protocol", "Protocol") - .WithMany() - .HasForeignKey("ProtocolId"); - - b.Navigation("ParentChannel"); - - b.Navigation("PermissionsOverrides"); - - b.Navigation("Protocol"); - }); - - modelBuilder.Entity("vassago.Models.Message", b => - { - b.HasOne("vassago.Models.User", "Author") - .WithMany() - .HasForeignKey("AuthorId"); - - b.HasOne("vassago.Models.Channel", "Channel") - .WithMany("Messages") - .HasForeignKey("ChannelId"); - - b.Navigation("Author"); - - b.Navigation("Channel"); - }); - - modelBuilder.Entity("vassago.Models.User", b => - { - b.HasOne("vassago.Models.Protocol", "Protocol") - .WithMany() - .HasForeignKey("ProtocolId"); - - b.HasOne("vassago.Models.User", null) - .WithMany("KnownAliases") - .HasForeignKey("UserId"); - - b.Navigation("Protocol"); - }); - - modelBuilder.Entity("vassago.Models.Channel", b => - { - b.Navigation("Messages"); - - b.Navigation("SubChannels"); - }); - - modelBuilder.Entity("vassago.Models.Message", b => - { - b.Navigation("Attachments"); - }); - - modelBuilder.Entity("vassago.Models.User", b => - { - b.Navigation("KnownAliases"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Migrations/20230605161311_protocol as string.Designer.cs b/Migrations/20230605161311_protocol as string.Designer.cs deleted file mode 100644 index c16597c..0000000 --- a/Migrations/20230605161311_protocol as string.Designer.cs +++ /dev/null @@ -1,268 +0,0 @@ -// -using System; -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("20230605161311_protocol as string")] - partial class protocolasstring - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.5") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - 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("DisplayName") - .HasColumnType("text"); - - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); - - b.Property("IsDM") - .HasColumnType("boolean"); - - b.Property("ParentChannelId") - .HasColumnType("uuid"); - - b.Property("PermissionsOverridesId") - .HasColumnType("integer"); - - b.Property("Protocol") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("ParentChannelId"); - - b.HasIndex("PermissionsOverridesId"); - - b.ToTable("Channels"); - }); - - 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("numeric(20,0)"); - - b.Property("MentionsMe") - .HasColumnType("boolean"); - - b.Property("Timestamp") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("AuthorId"); - - b.HasIndex("ChannelId"); - - b.ToTable("Messages"); - }); - - modelBuilder.Entity("vassago.Models.PermissionSettings", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("LewdnessFilterLevel") - .HasColumnType("integer"); - - b.Property("LinksAllowed") - .HasColumnType("boolean"); - - b.Property("MaxAttachmentBytes") - .HasColumnType("bigint"); - - b.Property("MaxTextChars") - .HasColumnType("bigint"); - - b.Property("MeannessFilterLevel") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.ToTable("PermissionSettings"); - }); - - modelBuilder.Entity("vassago.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); - - b.Property("IsBot") - .HasColumnType("boolean"); - - b.Property("Protocol") - .HasColumnType("text"); - - b.Property("SeenInChannelId") - .HasColumnType("uuid"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("Username") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("SeenInChannelId"); - - b.HasIndex("UserId"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("vassago.Models.Attachment", b => - { - b.HasOne("vassago.Models.Message", "Message") - .WithMany("Attachments") - .HasForeignKey("MessageId"); - - b.Navigation("Message"); - }); - - modelBuilder.Entity("vassago.Models.Channel", b => - { - b.HasOne("vassago.Models.Channel", "ParentChannel") - .WithMany("SubChannels") - .HasForeignKey("ParentChannelId"); - - b.HasOne("vassago.Models.PermissionSettings", "PermissionsOverrides") - .WithMany() - .HasForeignKey("PermissionsOverridesId"); - - b.Navigation("ParentChannel"); - - b.Navigation("PermissionsOverrides"); - }); - - modelBuilder.Entity("vassago.Models.Message", b => - { - b.HasOne("vassago.Models.User", "Author") - .WithMany() - .HasForeignKey("AuthorId"); - - b.HasOne("vassago.Models.Channel", "Channel") - .WithMany("Messages") - .HasForeignKey("ChannelId"); - - b.Navigation("Author"); - - b.Navigation("Channel"); - }); - - modelBuilder.Entity("vassago.Models.User", b => - { - b.HasOne("vassago.Models.Channel", "SeenInChannel") - .WithMany("OtherUsers") - .HasForeignKey("SeenInChannelId"); - - b.HasOne("vassago.Models.User", null) - .WithMany("KnownAliases") - .HasForeignKey("UserId"); - - b.Navigation("SeenInChannel"); - }); - - modelBuilder.Entity("vassago.Models.Channel", b => - { - b.Navigation("Messages"); - - b.Navigation("OtherUsers"); - - b.Navigation("SubChannels"); - }); - - modelBuilder.Entity("vassago.Models.Message", b => - { - b.Navigation("Attachments"); - }); - - modelBuilder.Entity("vassago.Models.User", b => - { - b.Navigation("KnownAliases"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Migrations/20230605161311_protocol as string.cs b/Migrations/20230605161311_protocol as string.cs deleted file mode 100644 index 647ff8f..0000000 --- a/Migrations/20230605161311_protocol as string.cs +++ /dev/null @@ -1,154 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace vassago.Migrations -{ - /// - public partial class protocolasstring : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Channels_Channels_ProtocolId", - table: "Channels"); - - migrationBuilder.DropForeignKey( - name: "FK_Users_Channels_ProtocolId", - table: "Users"); - - migrationBuilder.DropTable( - name: "ChannelUser"); - - migrationBuilder.DropIndex( - name: "IX_Channels_ProtocolId", - table: "Channels"); - - migrationBuilder.DropColumn( - name: "Discriminator", - table: "Channels"); - - migrationBuilder.DropColumn( - name: "ProtocolId", - table: "Channels"); - - migrationBuilder.RenameColumn( - name: "ProtocolId", - table: "Users", - newName: "SeenInChannelId"); - - migrationBuilder.RenameIndex( - name: "IX_Users_ProtocolId", - table: "Users", - newName: "IX_Users_SeenInChannelId"); - - migrationBuilder.RenameColumn( - name: "ConnectionToken", - table: "Channels", - newName: "Protocol"); - - migrationBuilder.AddColumn( - name: "Protocol", - table: "Users", - type: "text", - nullable: true); - - migrationBuilder.AddForeignKey( - name: "FK_Users_Channels_SeenInChannelId", - table: "Users", - column: "SeenInChannelId", - principalTable: "Channels", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Users_Channels_SeenInChannelId", - table: "Users"); - - migrationBuilder.DropColumn( - name: "Protocol", - table: "Users"); - - migrationBuilder.RenameColumn( - name: "SeenInChannelId", - table: "Users", - newName: "ProtocolId"); - - migrationBuilder.RenameIndex( - name: "IX_Users_SeenInChannelId", - table: "Users", - newName: "IX_Users_ProtocolId"); - - migrationBuilder.RenameColumn( - name: "Protocol", - table: "Channels", - newName: "ConnectionToken"); - - migrationBuilder.AddColumn( - name: "Discriminator", - table: "Channels", - type: "text", - nullable: false, - defaultValue: ""); - - migrationBuilder.AddColumn( - name: "ProtocolId", - table: "Channels", - type: "uuid", - nullable: true); - - migrationBuilder.CreateTable( - name: "ChannelUser", - columns: table => new - { - OtherUsersId = table.Column(type: "uuid", nullable: false), - SeenInChannelsId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ChannelUser", x => new { x.OtherUsersId, x.SeenInChannelsId }); - table.ForeignKey( - name: "FK_ChannelUser_Channels_SeenInChannelsId", - column: x => x.SeenInChannelsId, - principalTable: "Channels", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ChannelUser_Users_OtherUsersId", - column: x => x.OtherUsersId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Channels_ProtocolId", - table: "Channels", - column: "ProtocolId"); - - migrationBuilder.CreateIndex( - name: "IX_ChannelUser_SeenInChannelsId", - table: "ChannelUser", - column: "SeenInChannelsId"); - - migrationBuilder.AddForeignKey( - name: "FK_Channels_Channels_ProtocolId", - table: "Channels", - column: "ProtocolId", - principalTable: "Channels", - principalColumn: "Id"); - - migrationBuilder.AddForeignKey( - name: "FK_Users_Channels_ProtocolId", - table: "Users", - column: "ProtocolId", - principalTable: "Channels", - principalColumn: "Id"); - } - } -} diff --git a/Migrations/20230605162111_user aliases later.Designer.cs b/Migrations/20230605162111_user aliases later.Designer.cs deleted file mode 100644 index 5d2b85f..0000000 --- a/Migrations/20230605162111_user aliases later.Designer.cs +++ /dev/null @@ -1,254 +0,0 @@ -// -using System; -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("20230605162111_user aliases later")] - partial class useraliaseslater - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.5") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - 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("DisplayName") - .HasColumnType("text"); - - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); - - b.Property("IsDM") - .HasColumnType("boolean"); - - b.Property("ParentChannelId") - .HasColumnType("uuid"); - - b.Property("PermissionsOverridesId") - .HasColumnType("integer"); - - b.Property("Protocol") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("ParentChannelId"); - - b.HasIndex("PermissionsOverridesId"); - - b.ToTable("Channels"); - }); - - 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("numeric(20,0)"); - - b.Property("MentionsMe") - .HasColumnType("boolean"); - - b.Property("Timestamp") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("AuthorId"); - - b.HasIndex("ChannelId"); - - b.ToTable("Messages"); - }); - - modelBuilder.Entity("vassago.Models.PermissionSettings", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("LewdnessFilterLevel") - .HasColumnType("integer"); - - b.Property("LinksAllowed") - .HasColumnType("boolean"); - - b.Property("MaxAttachmentBytes") - .HasColumnType("bigint"); - - b.Property("MaxTextChars") - .HasColumnType("bigint"); - - b.Property("MeannessFilterLevel") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.ToTable("PermissionSettings"); - }); - - modelBuilder.Entity("vassago.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); - - b.Property("IsBot") - .HasColumnType("boolean"); - - b.Property("Protocol") - .HasColumnType("text"); - - b.Property("SeenInChannelId") - .HasColumnType("uuid"); - - b.Property("Username") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("SeenInChannelId"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("vassago.Models.Attachment", b => - { - b.HasOne("vassago.Models.Message", "Message") - .WithMany("Attachments") - .HasForeignKey("MessageId"); - - b.Navigation("Message"); - }); - - modelBuilder.Entity("vassago.Models.Channel", b => - { - b.HasOne("vassago.Models.Channel", "ParentChannel") - .WithMany("SubChannels") - .HasForeignKey("ParentChannelId"); - - b.HasOne("vassago.Models.PermissionSettings", "PermissionsOverrides") - .WithMany() - .HasForeignKey("PermissionsOverridesId"); - - b.Navigation("ParentChannel"); - - b.Navigation("PermissionsOverrides"); - }); - - modelBuilder.Entity("vassago.Models.Message", b => - { - b.HasOne("vassago.Models.User", "Author") - .WithMany() - .HasForeignKey("AuthorId"); - - b.HasOne("vassago.Models.Channel", "Channel") - .WithMany("Messages") - .HasForeignKey("ChannelId"); - - b.Navigation("Author"); - - b.Navigation("Channel"); - }); - - modelBuilder.Entity("vassago.Models.User", b => - { - b.HasOne("vassago.Models.Channel", "SeenInChannel") - .WithMany("OtherUsers") - .HasForeignKey("SeenInChannelId"); - - b.Navigation("SeenInChannel"); - }); - - modelBuilder.Entity("vassago.Models.Channel", b => - { - b.Navigation("Messages"); - - b.Navigation("OtherUsers"); - - b.Navigation("SubChannels"); - }); - - modelBuilder.Entity("vassago.Models.Message", b => - { - b.Navigation("Attachments"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Migrations/20230605162111_user aliases later.cs b/Migrations/20230605162111_user aliases later.cs deleted file mode 100644 index 8c2a7b1..0000000 --- a/Migrations/20230605162111_user aliases later.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace vassago.Migrations -{ - /// - public partial class useraliaseslater : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Users_Users_UserId", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_UserId", - table: "Users"); - - migrationBuilder.DropColumn( - name: "UserId", - table: "Users"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "UserId", - table: "Users", - type: "uuid", - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Users_UserId", - table: "Users", - column: "UserId"); - - migrationBuilder.AddForeignKey( - name: "FK_Users_Users_UserId", - table: "Users", - column: "UserId", - principalTable: "Users", - principalColumn: "Id"); - } - } -} diff --git a/Migrations/20230619144448_permissionsmove.Designer.cs b/Migrations/20230619144448_permissionsmove.Designer.cs deleted file mode 100644 index b58468e..0000000 --- a/Migrations/20230619144448_permissionsmove.Designer.cs +++ /dev/null @@ -1,255 +0,0 @@ -// -using System; -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("20230619144448_permissionsmove")] - partial class permissionsmove - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.5") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - 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("DisplayName") - .HasColumnType("text"); - - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); - - b.Property("IsDM") - .HasColumnType("boolean"); - - b.Property("ParentChannelId") - .HasColumnType("uuid"); - - b.Property("PermissionsId") - .HasColumnType("integer"); - - b.Property("Protocol") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("ParentChannelId"); - - b.HasIndex("PermissionsId"); - - b.ToTable("Channels"); - }); - - 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("numeric(20,0)"); - - b.Property("MentionsMe") - .HasColumnType("boolean"); - - b.Property("Timestamp") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("AuthorId"); - - b.HasIndex("ChannelId"); - - b.ToTable("Messages"); - }); - - modelBuilder.Entity("vassago.Models.PermissionSettings", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("LewdnessFilterLevel") - .HasColumnType("integer"); - - b.Property("LinksAllowed") - .HasColumnType("boolean"); - - b.Property("MaxAttachmentBytes") - .HasColumnType("bigint"); - - b.Property("MaxTextChars") - .HasColumnType("bigint"); - - b.Property("MeannessFilterLevel") - .HasColumnType("integer"); - - b.Property("ReactionsPossible") - .HasColumnType("boolean"); - - b.HasKey("Id"); - - b.ToTable("PermissionSettings"); - }); - - modelBuilder.Entity("vassago.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); - - b.Property("IsBot") - .HasColumnType("boolean"); - - b.Property("Protocol") - .HasColumnType("text"); - - b.Property("SeenInChannelId") - .HasColumnType("uuid"); - - b.Property("Username") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("SeenInChannelId"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("vassago.Models.Attachment", b => - { - b.HasOne("vassago.Models.Message", "Message") - .WithMany("Attachments") - .HasForeignKey("MessageId"); - - b.Navigation("Message"); - }); - - modelBuilder.Entity("vassago.Models.Channel", b => - { - b.HasOne("vassago.Models.Channel", "ParentChannel") - .WithMany("SubChannels") - .HasForeignKey("ParentChannelId"); - - b.HasOne("vassago.Models.PermissionSettings", "Permissions") - .WithMany() - .HasForeignKey("PermissionsId"); - - b.Navigation("ParentChannel"); - - b.Navigation("Permissions"); - }); - - modelBuilder.Entity("vassago.Models.Message", b => - { - b.HasOne("vassago.Models.User", "Author") - .WithMany() - .HasForeignKey("AuthorId"); - - b.HasOne("vassago.Models.Channel", "Channel") - .WithMany("Messages") - .HasForeignKey("ChannelId"); - - b.Navigation("Author"); - - b.Navigation("Channel"); - }); - - modelBuilder.Entity("vassago.Models.User", b => - { - b.HasOne("vassago.Models.Channel", "SeenInChannel") - .WithMany() - .HasForeignKey("SeenInChannelId"); - - b.Navigation("SeenInChannel"); - }); - - modelBuilder.Entity("vassago.Models.Channel", b => - { - b.Navigation("Messages"); - - b.Navigation("SubChannels"); - }); - - modelBuilder.Entity("vassago.Models.Message", b => - { - b.Navigation("Attachments"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Migrations/20230619144448_permissionsmove.cs b/Migrations/20230619144448_permissionsmove.cs deleted file mode 100644 index ae9fd15..0000000 --- a/Migrations/20230619144448_permissionsmove.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace vassago.Migrations -{ - /// - public partial class permissionsmove : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Channels_PermissionSettings_PermissionsOverridesId", - table: "Channels"); - - migrationBuilder.RenameColumn( - name: "PermissionsOverridesId", - table: "Channels", - newName: "PermissionsId"); - - migrationBuilder.RenameIndex( - name: "IX_Channels_PermissionsOverridesId", - table: "Channels", - newName: "IX_Channels_PermissionsId"); - - migrationBuilder.AddColumn( - name: "ReactionsPossible", - table: "PermissionSettings", - type: "boolean", - nullable: true); - - migrationBuilder.AddForeignKey( - name: "FK_Channels_PermissionSettings_PermissionsId", - table: "Channels", - column: "PermissionsId", - principalTable: "PermissionSettings", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Channels_PermissionSettings_PermissionsId", - table: "Channels"); - - migrationBuilder.DropColumn( - name: "ReactionsPossible", - table: "PermissionSettings"); - - migrationBuilder.RenameColumn( - name: "PermissionsId", - table: "Channels", - newName: "PermissionsOverridesId"); - - migrationBuilder.RenameIndex( - name: "IX_Channels_PermissionsId", - table: "Channels", - newName: "IX_Channels_PermissionsOverridesId"); - - migrationBuilder.AddForeignKey( - name: "FK_Channels_PermissionSettings_PermissionsOverridesId", - table: "Channels", - column: "PermissionsOverridesId", - principalTable: "PermissionSettings", - principalColumn: "Id"); - } - } -} diff --git a/Migrations/20230619155657_DistinguishUsersAndAccounts.Designer.cs b/Migrations/20230619155657_DistinguishUsersAndAccounts.Designer.cs deleted file mode 100644 index 7dba788..0000000 --- a/Migrations/20230619155657_DistinguishUsersAndAccounts.Designer.cs +++ /dev/null @@ -1,263 +0,0 @@ -// -using System; -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("20230619155657_DistinguishUsersAndAccounts")] - partial class DistinguishUsersAndAccounts - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.5") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("vassago.Models.Account", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("DisplayName") - .HasColumnType("text"); - - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); - - b.Property("IsBot") - .HasColumnType("boolean"); - - b.Property("PermissionTags") - .HasColumnType("integer[]"); - - b.Property("Protocol") - .HasColumnType("text"); - - b.Property("SeenInChannelId") - .HasColumnType("uuid"); - - b.Property("Username") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("SeenInChannelId"); - - b.ToTable("Users"); - }); - - 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("DisplayName") - .HasColumnType("text"); - - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); - - b.Property("IsDM") - .HasColumnType("boolean"); - - b.Property("ParentChannelId") - .HasColumnType("uuid"); - - b.Property("PermissionsId") - .HasColumnType("integer"); - - b.Property("Protocol") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("ParentChannelId"); - - b.HasIndex("PermissionsId"); - - b.ToTable("Channels"); - }); - - 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("numeric(20,0)"); - - b.Property("MentionsMe") - .HasColumnType("boolean"); - - b.Property("Timestamp") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("AuthorId"); - - b.HasIndex("ChannelId"); - - b.ToTable("Messages"); - }); - - modelBuilder.Entity("vassago.Models.PermissionSettings", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("LewdnessFilterLevel") - .HasColumnType("integer"); - - b.Property("LinksAllowed") - .HasColumnType("boolean"); - - b.Property("MaxAttachmentBytes") - .HasColumnType("bigint"); - - b.Property("MaxTextChars") - .HasColumnType("bigint"); - - b.Property("MeannessFilterLevel") - .HasColumnType("integer"); - - b.Property("ReactionsPossible") - .HasColumnType("boolean"); - - b.HasKey("Id"); - - b.ToTable("PermissionSettings"); - }); - - modelBuilder.Entity("vassago.Models.Account", b => - { - b.HasOne("vassago.Models.Channel", "SeenInChannel") - .WithMany("Users") - .HasForeignKey("SeenInChannelId"); - - b.Navigation("SeenInChannel"); - }); - - modelBuilder.Entity("vassago.Models.Attachment", b => - { - b.HasOne("vassago.Models.Message", "Message") - .WithMany("Attachments") - .HasForeignKey("MessageId"); - - b.Navigation("Message"); - }); - - modelBuilder.Entity("vassago.Models.Channel", b => - { - b.HasOne("vassago.Models.Channel", "ParentChannel") - .WithMany("SubChannels") - .HasForeignKey("ParentChannelId"); - - b.HasOne("vassago.Models.PermissionSettings", "Permissions") - .WithMany() - .HasForeignKey("PermissionsId"); - - b.Navigation("ParentChannel"); - - b.Navigation("Permissions"); - }); - - 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"); - - 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"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Migrations/20230619155657_DistinguishUsersAndAccounts.cs b/Migrations/20230619155657_DistinguishUsersAndAccounts.cs deleted file mode 100644 index f3f57dc..0000000 --- a/Migrations/20230619155657_DistinguishUsersAndAccounts.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace vassago.Migrations -{ - /// - public partial class DistinguishUsersAndAccounts : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "DisplayName", - table: "Users", - type: "text", - nullable: true); - - migrationBuilder.AddColumn( - name: "PermissionTags", - table: "Users", - type: "integer[]", - nullable: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "DisplayName", - table: "Users"); - - migrationBuilder.DropColumn( - name: "PermissionTags", - table: "Users"); - } - } -} diff --git a/Migrations/20230628035812_NotionOfUserAccount.cs b/Migrations/20230628035812_NotionOfUserAccount.cs deleted file mode 100644 index 703a199..0000000 --- a/Migrations/20230628035812_NotionOfUserAccount.cs +++ /dev/null @@ -1,192 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace vassago.Migrations -{ - /// - public partial class NotionOfUserAccount : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Messages_Users_AuthorId", - table: "Messages"); - - migrationBuilder.DropForeignKey( - name: "FK_Users_Channels_SeenInChannelId", - table: "Users"); - - migrationBuilder.DropIndex( - name: "IX_Users_SeenInChannelId", - table: "Users"); - - migrationBuilder.DropColumn( - name: "DisplayName", - table: "Users"); - - migrationBuilder.DropColumn( - name: "ExternalId", - table: "Users"); - - migrationBuilder.DropColumn( - name: "IsBot", - table: "Users"); - - migrationBuilder.DropColumn( - name: "PermissionTags", - table: "Users"); - - migrationBuilder.DropColumn( - name: "Protocol", - table: "Users"); - - migrationBuilder.DropColumn( - name: "SeenInChannelId", - table: "Users"); - - migrationBuilder.DropColumn( - name: "Username", - table: "Users"); - - migrationBuilder.AlterColumn( - name: "MaxAttachmentBytes", - table: "PermissionSettings", - type: "numeric(20,0)", - nullable: true, - oldClrType: typeof(long), - oldType: "bigint", - oldNullable: true); - - migrationBuilder.CreateTable( - name: "Accounts", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - ExternalId = table.Column(type: "numeric(20,0)", nullable: true), - Username = table.Column(type: "text", nullable: true), - DisplayName = table.Column(type: "text", nullable: true), - IsBot = table.Column(type: "boolean", nullable: false), - SeenInChannelId = table.Column(type: "uuid", nullable: true), - PermissionTags = table.Column(type: "integer[]", nullable: true), - Protocol = table.Column(type: "text", nullable: true), - IsUserId = table.Column(type: "uuid", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Accounts", x => x.Id); - table.ForeignKey( - name: "FK_Accounts_Channels_SeenInChannelId", - column: x => x.SeenInChannelId, - principalTable: "Channels", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_Accounts_Users_IsUserId", - column: x => x.IsUserId, - principalTable: "Users", - principalColumn: "Id"); - }); - - migrationBuilder.CreateIndex( - name: "IX_Accounts_IsUserId", - table: "Accounts", - column: "IsUserId"); - - migrationBuilder.CreateIndex( - name: "IX_Accounts_SeenInChannelId", - table: "Accounts", - column: "SeenInChannelId"); - - migrationBuilder.AddForeignKey( - name: "FK_Messages_Accounts_AuthorId", - table: "Messages", - column: "AuthorId", - principalTable: "Accounts", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Messages_Accounts_AuthorId", - table: "Messages"); - - migrationBuilder.DropTable( - name: "Accounts"); - - migrationBuilder.AddColumn( - name: "DisplayName", - table: "Users", - type: "text", - nullable: true); - - migrationBuilder.AddColumn( - name: "ExternalId", - table: "Users", - type: "numeric(20,0)", - nullable: true); - - migrationBuilder.AddColumn( - name: "IsBot", - table: "Users", - type: "boolean", - nullable: false, - defaultValue: false); - - migrationBuilder.AddColumn( - name: "PermissionTags", - table: "Users", - type: "integer[]", - nullable: true); - - migrationBuilder.AddColumn( - name: "Protocol", - table: "Users", - type: "text", - nullable: true); - - migrationBuilder.AddColumn( - name: "SeenInChannelId", - table: "Users", - type: "uuid", - nullable: true); - - migrationBuilder.AddColumn( - name: "Username", - table: "Users", - type: "text", - nullable: true); - - migrationBuilder.AlterColumn( - name: "MaxAttachmentBytes", - table: "PermissionSettings", - type: "bigint", - nullable: true, - oldClrType: typeof(decimal), - oldType: "numeric(20,0)", - oldNullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Users_SeenInChannelId", - table: "Users", - column: "SeenInChannelId"); - - migrationBuilder.AddForeignKey( - name: "FK_Messages_Users_AuthorId", - table: "Messages", - column: "AuthorId", - principalTable: "Users", - principalColumn: "Id"); - - migrationBuilder.AddForeignKey( - name: "FK_Users_Channels_SeenInChannelId", - table: "Users", - column: "SeenInChannelId", - principalTable: "Channels", - principalColumn: "Id"); - } - } -} diff --git a/Migrations/20230628035812_NotionOfUserAccount.Designer.cs b/Migrations/20230704160720_initial.Designer.cs similarity index 95% rename from Migrations/20230628035812_NotionOfUserAccount.Designer.cs rename to Migrations/20230704160720_initial.Designer.cs index f241c74..851e4d9 100644 --- a/Migrations/20230628035812_NotionOfUserAccount.Designer.cs +++ b/Migrations/20230704160720_initial.Designer.cs @@ -12,8 +12,8 @@ using vassago.Models; namespace vassago.Migrations { [DbContext(typeof(ChattingContext))] - [Migration("20230628035812_NotionOfUserAccount")] - partial class NotionOfUserAccount + [Migration("20230704160720_initial")] + partial class initial { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -34,8 +34,8 @@ namespace vassago.Migrations b.Property("DisplayName") .HasColumnType("text"); - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); + b.Property("ExternalId") + .HasColumnType("text"); b.Property("IsBot") .HasColumnType("boolean"); @@ -110,8 +110,8 @@ namespace vassago.Migrations b.Property("DisplayName") .HasColumnType("text"); - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); + b.Property("ExternalId") + .HasColumnType("text"); b.Property("IsDM") .HasColumnType("boolean"); @@ -152,12 +152,15 @@ namespace vassago.Migrations b.Property("Content") .HasColumnType("text"); - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); + b.Property("ExternalId") + .HasColumnType("text"); b.Property("MentionsMe") .HasColumnType("boolean"); + b.Property("Protocol") + .HasColumnType("text"); + b.Property("Timestamp") .HasColumnType("timestamp with time zone"); diff --git a/Migrations/20230605152343_initial create.cs b/Migrations/20230704160720_initial.cs similarity index 69% rename from Migrations/20230605152343_initial create.cs rename to Migrations/20230704160720_initial.cs index 6e02b93..36ae1bb 100644 --- a/Migrations/20230605152343_initial create.cs +++ b/Migrations/20230704160720_initial.cs @@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace vassago.Migrations { /// - public partial class initialcreate : Migration + public partial class initial : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -18,9 +18,10 @@ namespace vassago.Migrations { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - MaxAttachmentBytes = table.Column(type: "bigint", nullable: true), + MaxAttachmentBytes = table.Column(type: "numeric(20,0)", nullable: true), MaxTextChars = table.Column(type: "bigint", nullable: true), LinksAllowed = table.Column(type: "boolean", nullable: true), + ReactionsPossible = table.Column(type: "boolean", nullable: true), LewdnessFilterLevel = table.Column(type: "integer", nullable: true), MeannessFilterLevel = table.Column(type: "integer", nullable: true) }, @@ -29,19 +30,28 @@ namespace vassago.Migrations table.PrimaryKey("PK_PermissionSettings", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Channels", columns: table => new { Id = table.Column(type: "uuid", nullable: false), - ExternalId = table.Column(type: "numeric(20,0)", nullable: true), + ExternalId = table.Column(type: "text", nullable: true), DisplayName = table.Column(type: "text", nullable: true), IsDM = table.Column(type: "boolean", nullable: false), - PermissionsOverridesId = table.Column(type: "integer", nullable: true), + PermissionsId = table.Column(type: "integer", nullable: true), ParentChannelId = table.Column(type: "uuid", nullable: true), - ProtocolId = table.Column(type: "uuid", nullable: true), - Discriminator = table.Column(type: "text", nullable: false), - ConnectionToken = table.Column(type: "text", nullable: true) + Protocol = table.Column(type: "text", nullable: true) }, constraints: table => { @@ -52,73 +62,48 @@ namespace vassago.Migrations principalTable: "Channels", principalColumn: "Id"); table.ForeignKey( - name: "FK_Channels_Channels_ProtocolId", - column: x => x.ProtocolId, - principalTable: "Channels", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_Channels_PermissionSettings_PermissionsOverridesId", - column: x => x.PermissionsOverridesId, + name: "FK_Channels_PermissionSettings_PermissionsId", + column: x => x.PermissionsId, principalTable: "PermissionSettings", principalColumn: "Id"); }); migrationBuilder.CreateTable( - name: "Users", + name: "Accounts", columns: table => new { Id = table.Column(type: "uuid", nullable: false), - ExternalId = table.Column(type: "numeric(20,0)", nullable: true), + ExternalId = table.Column(type: "text", nullable: true), Username = table.Column(type: "text", nullable: true), + DisplayName = table.Column(type: "text", nullable: true), IsBot = table.Column(type: "boolean", nullable: false), - ProtocolId = table.Column(type: "uuid", nullable: true), - UserId = table.Column(type: "uuid", nullable: true) + SeenInChannelId = table.Column(type: "uuid", nullable: true), + PermissionTags = table.Column(type: "integer[]", nullable: true), + Protocol = table.Column(type: "text", nullable: true), + IsUserId = table.Column(type: "uuid", nullable: true) }, constraints: table => { - table.PrimaryKey("PK_Users", x => x.Id); + table.PrimaryKey("PK_Accounts", x => x.Id); table.ForeignKey( - name: "FK_Users_Channels_ProtocolId", - column: x => x.ProtocolId, + name: "FK_Accounts_Channels_SeenInChannelId", + column: x => x.SeenInChannelId, principalTable: "Channels", principalColumn: "Id"); table.ForeignKey( - name: "FK_Users_Users_UserId", - column: x => x.UserId, + name: "FK_Accounts_Users_IsUserId", + column: x => x.IsUserId, principalTable: "Users", principalColumn: "Id"); }); - migrationBuilder.CreateTable( - name: "ChannelUser", - columns: table => new - { - OtherUsersId = table.Column(type: "uuid", nullable: false), - SeenInChannelsId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ChannelUser", x => new { x.OtherUsersId, x.SeenInChannelsId }); - table.ForeignKey( - name: "FK_ChannelUser_Channels_SeenInChannelsId", - column: x => x.SeenInChannelsId, - principalTable: "Channels", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ChannelUser_Users_OtherUsersId", - column: x => x.OtherUsersId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - migrationBuilder.CreateTable( name: "Messages", columns: table => new { Id = table.Column(type: "uuid", nullable: false), - ExternalId = table.Column(type: "numeric(20,0)", nullable: true), + Protocol = table.Column(type: "text", nullable: true), + ExternalId = table.Column(type: "text", nullable: true), Content = table.Column(type: "text", nullable: true), MentionsMe = table.Column(type: "boolean", nullable: false), Timestamp = table.Column(type: "timestamp with time zone", nullable: false), @@ -129,16 +114,16 @@ namespace vassago.Migrations constraints: table => { table.PrimaryKey("PK_Messages", x => x.Id); + table.ForeignKey( + name: "FK_Messages_Accounts_AuthorId", + column: x => x.AuthorId, + principalTable: "Accounts", + principalColumn: "Id"); table.ForeignKey( name: "FK_Messages_Channels_ChannelId", column: x => x.ChannelId, principalTable: "Channels", principalColumn: "Id"); - table.ForeignKey( - name: "FK_Messages_Users_AuthorId", - column: x => x.AuthorId, - principalTable: "Users", - principalColumn: "Id"); }); migrationBuilder.CreateTable( @@ -165,6 +150,16 @@ namespace vassago.Migrations principalColumn: "Id"); }); + migrationBuilder.CreateIndex( + name: "IX_Accounts_IsUserId", + table: "Accounts", + column: "IsUserId"); + + migrationBuilder.CreateIndex( + name: "IX_Accounts_SeenInChannelId", + table: "Accounts", + column: "SeenInChannelId"); + migrationBuilder.CreateIndex( name: "IX_Attachments_MessageId", table: "Attachments", @@ -176,19 +171,9 @@ namespace vassago.Migrations column: "ParentChannelId"); migrationBuilder.CreateIndex( - name: "IX_Channels_PermissionsOverridesId", + name: "IX_Channels_PermissionsId", table: "Channels", - column: "PermissionsOverridesId"); - - migrationBuilder.CreateIndex( - name: "IX_Channels_ProtocolId", - table: "Channels", - column: "ProtocolId"); - - migrationBuilder.CreateIndex( - name: "IX_ChannelUser_SeenInChannelsId", - table: "ChannelUser", - column: "SeenInChannelsId"); + column: "PermissionsId"); migrationBuilder.CreateIndex( name: "IX_Messages_AuthorId", @@ -199,16 +184,6 @@ namespace vassago.Migrations name: "IX_Messages_ChannelId", table: "Messages", column: "ChannelId"); - - migrationBuilder.CreateIndex( - name: "IX_Users_ProtocolId", - table: "Users", - column: "ProtocolId"); - - migrationBuilder.CreateIndex( - name: "IX_Users_UserId", - table: "Users", - column: "UserId"); } /// @@ -217,18 +192,18 @@ namespace vassago.Migrations migrationBuilder.DropTable( name: "Attachments"); - migrationBuilder.DropTable( - name: "ChannelUser"); - migrationBuilder.DropTable( name: "Messages"); migrationBuilder.DropTable( - name: "Users"); + name: "Accounts"); migrationBuilder.DropTable( name: "Channels"); + migrationBuilder.DropTable( + name: "Users"); + migrationBuilder.DropTable( name: "PermissionSettings"); } diff --git a/Migrations/ChattingContextModelSnapshot.cs b/Migrations/ChattingContextModelSnapshot.cs index fa29f04..d87ec09 100644 --- a/Migrations/ChattingContextModelSnapshot.cs +++ b/Migrations/ChattingContextModelSnapshot.cs @@ -31,8 +31,8 @@ namespace vassago.Migrations b.Property("DisplayName") .HasColumnType("text"); - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); + b.Property("ExternalId") + .HasColumnType("text"); b.Property("IsBot") .HasColumnType("boolean"); @@ -107,8 +107,8 @@ namespace vassago.Migrations b.Property("DisplayName") .HasColumnType("text"); - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); + b.Property("ExternalId") + .HasColumnType("text"); b.Property("IsDM") .HasColumnType("boolean"); @@ -149,12 +149,15 @@ namespace vassago.Migrations b.Property("Content") .HasColumnType("text"); - b.Property("ExternalId") - .HasColumnType("numeric(20,0)"); + b.Property("ExternalId") + .HasColumnType("text"); b.Property("MentionsMe") .HasColumnType("boolean"); + b.Property("Protocol") + .HasColumnType("text"); + b.Property("Timestamp") .HasColumnType("timestamp with time zone"); diff --git a/Models/Account.cs b/Models/Account.cs index 7b14c4c..63554f1 100644 --- a/Models/Account.cs +++ b/Models/Account.cs @@ -9,7 +9,7 @@ public class Account { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } - public ulong? ExternalId { get; set; } + public string ExternalId { get; set; } public string Username { get; set; } private string _displayName = null; public string DisplayName diff --git a/Models/Channel.cs b/Models/Channel.cs index 74b2086..ce509b9 100644 --- a/Models/Channel.cs +++ b/Models/Channel.cs @@ -11,7 +11,7 @@ public class Channel { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } - public ulong? ExternalId { get; set; } + public string ExternalId { get; set; } public string DisplayName { get; set; } public bool IsDM { get; set; } public PermissionSettings Permissions { get; set; } diff --git a/Models/Message.cs b/Models/Message.cs index 1ff1ae3..ebfa68f 100644 --- a/Models/Message.cs +++ b/Models/Message.cs @@ -11,12 +11,9 @@ public class Message { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } - public ulong? ExternalId { get; set; } + public string Protocol { get; set; } + public string ExternalId { get; set; } public string Content { get; set; } - /* - * TODO: more general "talking to me". current impl is platform's capital m Mention, but I'd like it if they use my name without "properly" - * mentioning me, and also if it's just me and them in a channel - */ public bool MentionsMe { get; set; } public DateTimeOffset Timestamp { get; set; } public bool ActedOn { get; set; } diff --git a/TwitchInterface/TwitchConfig.cs b/TwitchInterface/TwitchConfig.cs new file mode 100644 index 0000000..eb849f4 --- /dev/null +++ b/TwitchInterface/TwitchConfig.cs @@ -0,0 +1,7 @@ +public class TwitchConfig +{ + public string username {get; set;} + public string clientId {get; set;} + public string secret {get; set;} + public string oauth {get; set;} +} \ No newline at end of file diff --git a/TwitchInterface/TwitchInterface.cs b/TwitchInterface/TwitchInterface.cs new file mode 100644 index 0000000..da93043 --- /dev/null +++ b/TwitchInterface/TwitchInterface.cs @@ -0,0 +1,253 @@ +using System.Text.RegularExpressions; +using RestSharp; +using TwitchLib.Api; +using TwitchLib.Api.Helix.Models.Users.GetUsers; +using TwitchLib.Client; +using TwitchLib.Client.Events; +using TwitchLib.Client.Models; +using TwitchLib.Communication.Clients; +using TwitchLib.Communication.Models; +using vassago.Behavior; +using vassago.Models; + +namespace vassago.TwitchInterface; + +public class TwitchInterface +{ + internal const string PROTOCOL = "Twitch"; + private bool eventsSignedUp = false; + private ChattingContext _db; + private static SemaphoreSlim twitchChannelSetup = new SemaphoreSlim(1, 1); + private Channel protocolAsChannel; + TwitchClient client; + + public TwitchInterface() + { + _db = new ChattingContext(); + } + private async Task SetupTwitchChannel() + { + await twitchChannelSetup.WaitAsync(); + + try + { + protocolAsChannel = _db.Channels.FirstOrDefault(c => c.ParentChannel == null && c.Protocol == PROTOCOL); + if (protocolAsChannel == null) + { + protocolAsChannel = new Channel() + { + DisplayName = "discord (itself)", + Permissions = new PermissionSettings() + { + MeannessFilterLevel = 1, + LewdnessFilterLevel = 3, + MaxTextChars = 500, + MaxAttachmentBytes = 0, + LinksAllowed = false, + ReactionsPossible = false + }, + ExternalId = null, + Protocol = PROTOCOL, + SubChannels = new List() + }; + protocolAsChannel.SendMessage = (t) => { throw new InvalidOperationException($"twitch itself cannot accept text"); }; + protocolAsChannel.SendFile = (f, t) => { throw new InvalidOperationException($"twitch itself cannot send file"); }; + _db.Channels.Add(protocolAsChannel); + _db.SaveChanges(); + } + } + finally + { + twitchChannelSetup.Release(); + } + } + + ///https://www.twitchapps.com/tmi/ + public async Task Init(TwitchConfig tc) + { + await SetupTwitchChannel(); + + WebSocketClient customClient = new WebSocketClient(new ClientOptions + { + MessagesAllowedInPeriod = 750, + ThrottlingPeriod = TimeSpan.FromSeconds(30) + } + ); + client = new TwitchClient(customClient); + client.Initialize(new ConnectionCredentials(tc.username, tc.oauth, capabilities: new Capabilities())); + + client.OnLog += Client_OnLog; + client.OnJoinedChannel += Client_OnJoinedChannel; + client.OnMessageReceived += Client_OnMessageReceivedAsync; + client.OnWhisperReceived += Client_OnWhisperReceivedAsync; + client.OnConnected += Client_OnConnected; + + Console.WriteLine("twitch client connecting..."); + client.Connect(); + Console.WriteLine("twitch client connected"); + + } + + private async void Client_OnWhisperReceivedAsync(object sender, OnWhisperReceivedArgs e) + { + Console.WriteLine($"whisper#{e.WhisperMessage.Username}[{DateTime.Now}][{e.WhisperMessage.DisplayName} [id={e.WhisperMessage.Username}]][msg id: {e.WhisperMessage.MessageId}] {e.WhisperMessage.Message}"); + var m = UpsertMessage(e.WhisperMessage); + m.Channel.IsDM = true; + + m.MentionsMe = Regex.IsMatch(e.WhisperMessage.Message?.ToLower(), $"\\b@{e.WhisperMessage.BotUsername.ToLower()}\\b"); + + if (await Behaver.Instance.ActOn(m)) + { + m.ActedOn = true; + } + _db.SaveChanges(); + } + + private async void Client_OnMessageReceivedAsync(object sender, OnMessageReceivedArgs e) + { + Console.WriteLine($"#{e.ChatMessage.Channel}[{DateTime.Now}][{e.ChatMessage.DisplayName} [id={e.ChatMessage.Username}]][msg id: {e.ChatMessage.Id}] {e.ChatMessage.Message}"); + var m = UpsertMessage(e.ChatMessage); + + m.MentionsMe = Regex.IsMatch(e.ChatMessage.Message?.ToLower(), $"@{e.ChatMessage.BotUsername.ToLower()}\\b") || + e.ChatMessage.ChatReply?.ParentUserLogin == e.ChatMessage.BotUsername; + + if (await Behaver.Instance.ActOn(m)) + { + m.ActedOn = true; + } + _db.SaveChanges(); + } + + private async void Client_OnConnected(object sender, OnConnectedArgs e) + { + var selfUser = UpsertAccount(e.BotUsername); + selfUser.SeenInChannel = protocolAsChannel; + + await _db.SaveChangesAsync(); + Behaver.Instance.Selves.Add(selfUser); + + client.JoinChannel("#homeburger"); + client.JoinChannel("homeburger"); + Console.WriteLine($"Connected to {e.AutoJoinChannel}"); + } + + private void Client_OnJoinedChannel(object sender, OnJoinedChannelArgs e) + { + client.SendMessage(e.Channel, "beep boop"); + } + + private void Client_OnLog(object sender, OnLogArgs e) + { + Console.WriteLine($"{e.DateTime.ToString()}: {e.BotUsername} - {e.Data}"); + } + + private Account UpsertAccount(string username) + { + var hadToAdd = false; + var acc = _db.Accounts.FirstOrDefault(ui => ui.ExternalId == username); + if (acc == null) + { + acc = new Account(); + _db.Accounts.Add(acc); + hadToAdd = true; + } + acc.Username = username; + acc.ExternalId = username; + //acc.IsBot = + acc.Protocol = PROTOCOL; + + if(hadToAdd) + { + acc.IsUser = _db.Users.FirstOrDefault(u => u.Accounts.Any(a => a.ExternalId == acc.ExternalId && a.Protocol == acc.Protocol)); + if(acc.IsUser == null) + { + acc.IsUser = new vassago.Models.User() { Accounts = new List() { acc } }; + _db.Users.Add(acc.IsUser); + } + } + return acc; + } + + private Channel UpsertChannel(string channelName) + { + Channel c = _db.Channels.FirstOrDefault(ci => ci.ExternalId == channelName && ci.Protocol == PROTOCOL); + if (c == null) + { + c = new Channel(); + _db.Channels.Add(c); + } + c.DisplayName = channelName; + c.ExternalId = channelName; + c.IsDM = false; + c.Messages = c.Messages ?? new List(); + c.Protocol = PROTOCOL; + c.ParentChannel = protocolAsChannel; + c.SubChannels = c.SubChannels ?? new List(); + c.SendMessage = (t) => { return Task.Run(() => {client.SendMessage(channelName, t); }); }; + c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); }; + return c; + throw new NotImplementedException(); + } + private Channel UpsertDMChannel(string whisperWith) + { + Channel c = _db.Channels.FirstOrDefault(ci => ci.ExternalId == $"w_{whisperWith}" && ci.Protocol == PROTOCOL); + if (c == null) + { + c = new Channel(); + _db.Channels.Add(c); + } + c.DisplayName = $"Whisper: {whisperWith}"; + c.ExternalId = $"w_{whisperWith}"; + c.IsDM = true; + c.Messages = c.Messages ?? new List(); + c.Protocol = PROTOCOL; + c.ParentChannel = protocolAsChannel; + c.SubChannels = c.SubChannels ?? new List(); + c.SendMessage = (t) => { return Task.Run(() => {client.SendWhisper(whisperWith, t); }); }; + c.SendFile = (f, t) => { throw new InvalidOperationException($"twitch cannot send files"); }; + return c; + throw new NotImplementedException(); + } + + private Message UpsertMessage(ChatMessage chatMessage) + { + var m = _db.Messages.FirstOrDefault(mi => mi.ExternalId == chatMessage.Id); + if (m == null) + { + m = new Message(); + _db.Messages.Add(m); + m.Timestamp =(DateTimeOffset)DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); + } + + m.Content = chatMessage.Message; + m.ExternalId = chatMessage.Id; + m.Channel = UpsertChannel(chatMessage.Channel); + m.Author = UpsertAccount(chatMessage.Username); + m.Author.SeenInChannel = m.Channel; + + m.Reply = (t) => { return Task.Run(() => { client.SendReply(chatMessage.Channel, chatMessage.Id, t); }); }; + m.React = (e) => { throw new InvalidOperationException($"twitch cannot react"); }; + return m; + } + private Message UpsertMessage(WhisperMessage whisperMessage) + { + var m = _db.Messages.FirstOrDefault(mi => mi.ExternalId == whisperMessage.MessageId); + if (m == null) + { + m = new Message(); + _db.Messages.Add(m); + m.Timestamp =(DateTimeOffset)DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); + } + + m.Content = whisperMessage.Message; + m.ExternalId = whisperMessage.MessageId; + m.Channel = UpsertDMChannel(whisperMessage.Username); + m.Channel.IsDM = true; + m.Author = UpsertAccount(whisperMessage.Username); + m.Author.SeenInChannel = m.Channel; + + m.Reply = (t) => { return Task.Run(() => {client.SendWhisper(whisperMessage.Username, t); });}; + m.React = (e) => { throw new InvalidOperationException($"twitch cannot react"); }; + return m; + } +} \ No newline at end of file diff --git a/appsettings.json b/appsettings.json index e26e975..632e525 100644 --- a/appsettings.json +++ b/appsettings.json @@ -7,10 +7,9 @@ }, "AllowedHosts": "*", "DiscordTokens": [ - "70 chars" + ], - "TwitchTokens": [ - {"user": "token"} + "TwitchConfigs": [ ], "exchangePairsLocation": "assets/exchangepairs.json", "DBConnectionString": "Host=localhost;Database=db;Username=db;Password=db" diff --git a/vassago.csproj b/vassago.csproj index 81c67a3..b9bec3c 100644 --- a/vassago.csproj +++ b/vassago.csproj @@ -17,6 +17,8 @@ + +