From 64ce169094927a5da93c757a0e008c8e637053ca Mon Sep 17 00:00:00 2001 From: Sarah Faey Date: Thu, 8 Dec 2022 23:27:26 +0100 Subject: [PATCH] Added group reminder --- Lieb/Data/DiscordService.cs | 108 ++- Lieb/Data/RaidService.cs | 3 + Lieb/Data/UserService.cs | 10 + ...208222423_AddReminderTypeGroup.Designer.cs | 653 ++++++++++++++++++ .../20221208222423_AddReminderTypeGroup.cs | 26 + Lieb/Migrations/LiebContextModelSnapshot.cs | 3 + Lieb/Models/GuildWars2/Raid/RaidBase.cs | 3 +- Lieb/Models/GuildWars2/Raid/RaidReminder.cs | 7 +- .../Raids/RaidEdit/DynamicReminderEdit.razor | 36 +- Lieb/Pages/Raids/RaidEdit/RaidEdit.razor | 7 +- .../Raids/RaidEdit/RaidTemplateEdit.razor | 6 +- .../Raids/RaidEdit/StaticReminderEdit.razor | 36 +- 12 files changed, 853 insertions(+), 45 deletions(-) create mode 100644 Lieb/Migrations/20221208222423_AddReminderTypeGroup.Designer.cs create mode 100644 Lieb/Migrations/20221208222423_AddReminderTypeGroup.cs diff --git a/Lieb/Data/DiscordService.cs b/Lieb/Data/DiscordService.cs index 39ff6b5..b432e1e 100644 --- a/Lieb/Data/DiscordService.cs +++ b/Lieb/Data/DiscordService.cs @@ -148,6 +148,7 @@ namespace Lieb.Data return new List(); } +#region UserReminder public async Task SendUserReminder(RaidReminder reminder, Raid raid) { if (await SendMessageToRaidUsers(reminder.Message, raid)) @@ -183,6 +184,27 @@ namespace Lieb.Data return false; } + public static ApiUserReminder ConvertUserReminder(string message, Raid raid) + { + ApiUserReminder apiReminder = new ApiUserReminder() + { + Message = $"{raid.Title}: {message}" + }; + apiReminder.UserIds = new List(); + HashSet userIds = new HashSet(); + foreach(RaidSignUp signUp in raid.SignUps) + { + if(signUp.LiebUserId.HasValue) + { + userIds.Add(signUp.LiebUserId.Value); + } + } + apiReminder.UserIds = userIds.ToList(); + return apiReminder; + } +#endregion UserReminder + +#region ChannelReminder public async Task SendChannelReminder(RaidReminder reminder, string raidTitle) { if (await SendChannelMessage(reminder.DiscordServerId, reminder.DiscordChannelId, reminder.Message, raidTitle)) @@ -215,6 +237,63 @@ namespace Lieb.Data return false; } + public static ApiChannelReminder ConvertChannelReminder(ulong discordServerId, ulong discordChannelId, string message, string raidTitle) + { + return new ApiChannelReminder() + { + DiscordServerId = discordServerId, + DiscordChannelId = discordChannelId, + Message = $"{raidTitle}: {message}" + }; + } + +#endregion ChannelReminder + +#region GroupReminder + public async Task SendGroupReminder(RaidReminder reminder, string raidTitle) + { + using var context = _contextFactory.CreateDbContext(); + HashSet groupMembers = context.LiebUsers.Where(u => u.RoleAssignments.Where(r => r.LiebRole.LiebRoleId == reminder.RoleId).Any()).Select(u => u.Id).ToHashSet(); + if (await SendMessageToGroup(reminder.Message, raidTitle, groupMembers)) + { + reminder.Sent = true; + context.Update(reminder); + await context.SaveChangesAsync(); + } + } + + public async Task SendMessageToGroup(string message, string raidTitle, HashSet userIds) + { + try + { + var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName); + + ApiUserReminder apiReminder = ConvertGroupReminder(message, raidTitle, userIds); + + var raidItemJson = new StringContent( + JsonSerializer.Serialize(apiReminder), + Encoding.UTF8, + Application.Json); + + var httpResponseMessage = await httpClient.PostAsync("raid/SendUserReminder", raidItemJson); + + return httpResponseMessage.IsSuccessStatusCode; + } + catch {} + return false; + } + + public static ApiUserReminder ConvertGroupReminder(string message, string raidTitle, HashSet groupIds) + { + ApiUserReminder apiReminder = new ApiUserReminder() + { + Message = $"{raidTitle}: {message}" + }; + apiReminder.UserIds = groupIds.ToList(); + return apiReminder; + } +#endregion GroupReminder + private async Task UpdateDiscordMessages(IEnumerable messages, Raid raid) { foreach(ApiRaid.DiscordMessage message in messages) @@ -302,35 +381,6 @@ namespace Lieb.Data return apiMessages; } - public static ApiUserReminder ConvertUserReminder(string message, Raid raid) - { - ApiUserReminder apiReminder = new ApiUserReminder() - { - Message = $"{raid.Title}: {message}" - }; - apiReminder.UserIds = new List(); - HashSet userIds = new HashSet(); - foreach(RaidSignUp signUp in raid.SignUps) - { - if(signUp.LiebUserId.HasValue) - { - userIds.Add(signUp.LiebUserId.Value); - } - } - apiReminder.UserIds = userIds.ToList(); - return apiReminder; - } - - public static ApiChannelReminder ConvertChannelReminder(ulong discordServerId, ulong discordChannelId, string message, string raidTitle) - { - return new ApiChannelReminder() - { - DiscordServerId = discordServerId, - DiscordChannelId = discordChannelId, - Message = $"{raidTitle}: {message}" - }; - } - public async Task RenameUser(ulong userId, string name, string account) { try diff --git a/Lieb/Data/RaidService.cs b/Lieb/Data/RaidService.cs index 22c4e24..988c328 100644 --- a/Lieb/Data/RaidService.cs +++ b/Lieb/Data/RaidService.cs @@ -518,6 +518,9 @@ namespace Lieb.Data case RaidReminder.ReminderType.Channel: await _discordService.SendChannelReminder(reminder, raid.Title); break; + case RaidReminder.ReminderType.Group: + await _discordService.SendGroupReminder(reminder, raid.Title); + break; } } } diff --git a/Lieb/Data/UserService.cs b/Lieb/Data/UserService.cs index 0c68820..61ae279 100644 --- a/Lieb/Data/UserService.cs +++ b/Lieb/Data/UserService.cs @@ -235,6 +235,16 @@ namespace Lieb.Data .ToList(); } + public List GetUserRoles(ulong userId) + { + using var context = _contextFactory.CreateDbContext(); + return context.LiebRoles + .Include(u => u.RoleAssignments) + .ThenInclude(r => r.LiebUser) + .Where(r => r.RoleAssignments.Where(a => a.LiebUserId == userId).Any()) + .ToList(); + } + public async Task AddRole(LiebRole role) { using var context = _contextFactory.CreateDbContext(); diff --git a/Lieb/Migrations/20221208222423_AddReminderTypeGroup.Designer.cs b/Lieb/Migrations/20221208222423_AddReminderTypeGroup.Designer.cs new file mode 100644 index 0000000..eae12b1 --- /dev/null +++ b/Lieb/Migrations/20221208222423_AddReminderTypeGroup.Designer.cs @@ -0,0 +1,653 @@ +// +using System; +using Lieb.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Lieb.Migrations +{ + [DbContext(typeof(LiebContext))] + [Migration("20221208222423_AddReminderTypeGroup")] + partial class AddReminderTypeGroup + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.10"); + + modelBuilder.Entity("Lieb.Models.DiscordSettings", b => + { + b.Property("DiscordSettingsId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ChangeUserNames") + .HasColumnType("INTEGER"); + + b.Property("DiscordLogChannel") + .HasColumnType("INTEGER"); + + b.HasKey("DiscordSettingsId"); + + b.ToTable("DiscordSettings", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Equipped", b => + { + b.Property("EquippedId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CanTank") + .HasColumnType("INTEGER"); + + b.Property("GuildWars2AccountId") + .HasColumnType("INTEGER"); + + b.Property("GuildWars2BuildId") + .HasColumnType("INTEGER"); + + b.HasKey("EquippedId"); + + b.HasIndex("GuildWars2AccountId"); + + b.HasIndex("GuildWars2BuildId"); + + b.ToTable("Equipped", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Account", b => + { + b.Property("GuildWars2AccountId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AccountName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ApiKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LiebUserId") + .HasColumnType("INTEGER"); + + b.HasKey("GuildWars2AccountId"); + + b.HasIndex("LiebUserId"); + + b.ToTable("GuildWars2Account", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Build", b => + { + b.Property("GuildWars2BuildId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Alacrity") + .HasColumnType("INTEGER"); + + b.Property("BuildName") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("TEXT"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.Property("DamageType") + .HasColumnType("INTEGER"); + + b.Property("EliteSpecialization") + .HasColumnType("INTEGER"); + + b.Property("Might") + .HasColumnType("INTEGER"); + + b.Property("Quickness") + .HasColumnType("INTEGER"); + + b.Property("Source") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SourceLink") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("UseInRandomRaid") + .HasColumnType("INTEGER"); + + b.HasKey("GuildWars2BuildId"); + + b.ToTable("GuildWars2Build", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.DiscordRaidMessage", b => + { + b.Property("DiscordRaidMessageId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DiscordChannelId") + .HasColumnType("INTEGER"); + + b.Property("DiscordGuildId") + .HasColumnType("INTEGER"); + + b.Property("DiscordMessageId") + .HasColumnType("INTEGER"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidTemplateId") + .HasColumnType("INTEGER"); + + b.HasKey("DiscordRaidMessageId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidTemplateId"); + + b.ToTable("DiscordRaidMessage", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.Raid", b => + { + b.Property("RaidId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("TEXT"); + + b.Property("EndTimeUTC") + .HasColumnType("TEXT"); + + b.Property("EventType") + .HasColumnType("INTEGER"); + + b.Property("FreeForAllTimeUTC") + .HasColumnType("TEXT"); + + b.Property("Guild") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("MoveFlexUsers") + .HasColumnType("INTEGER"); + + b.Property("Organizer") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("RaidOwnerId") + .HasColumnType("INTEGER"); + + b.Property("RaidType") + .HasColumnType("INTEGER"); + + b.Property("RequiredRole") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("StartTimeUTC") + .HasColumnType("TEXT"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("VoiceChat") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("RaidId"); + + b.ToTable("Raid", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidReminder", b => + { + b.Property("RaidReminderId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("DiscordChannelId") + .HasColumnType("INTEGER"); + + b.Property("DiscordServerId") + .HasColumnType("INTEGER"); + + b.Property("Message") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("TEXT"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidTemplateId") + .HasColumnType("INTEGER"); + + b.Property("ReminderTimeUTC") + .HasColumnType("TEXT"); + + b.Property("RoleId") + .HasColumnType("INTEGER"); + + b.Property("Sent") + .HasColumnType("INTEGER"); + + b.Property("TimeType") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("RaidReminderId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidTemplateId"); + + b.ToTable("RaidReminder", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidRole", b => + { + b.Property("RaidRoleId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsRandomSignUpRole") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidTemplateId") + .HasColumnType("INTEGER"); + + b.Property("Spots") + .HasColumnType("INTEGER"); + + b.HasKey("RaidRoleId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidTemplateId"); + + b.ToTable("RaidRole", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidSignUp", b => + { + b.Property("RaidSignUpId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ExternalUserName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("GuildWars2AccountId") + .HasColumnType("INTEGER"); + + b.Property("LiebUserId") + .HasColumnType("INTEGER"); + + b.Property("RaidId") + .HasColumnType("INTEGER"); + + b.Property("RaidRoleId") + .HasColumnType("INTEGER"); + + b.Property("SignUpType") + .HasColumnType("INTEGER"); + + b.HasKey("RaidSignUpId"); + + b.HasIndex("GuildWars2AccountId"); + + b.HasIndex("LiebUserId"); + + b.HasIndex("RaidId"); + + b.HasIndex("RaidRoleId"); + + b.ToTable("RaidSignUp", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidTemplate", b => + { + b.Property("RaidTemplateId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreateDaysBefore") + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("TEXT"); + + b.Property("EndTime") + .HasColumnType("TEXT"); + + b.Property("EventType") + .HasColumnType("INTEGER"); + + b.Property("FreeForAllTime") + .HasColumnType("TEXT"); + + b.Property("Guild") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Interval") + .HasColumnType("INTEGER"); + + b.Property("MoveFlexUsers") + .HasColumnType("INTEGER"); + + b.Property("Organizer") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("RaidOwnerId") + .HasColumnType("INTEGER"); + + b.Property("RaidType") + .HasColumnType("INTEGER"); + + b.Property("RequiredRole") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("StartTime") + .HasColumnType("TEXT"); + + b.Property("TimeZone") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("VoiceChat") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("RaidTemplateId"); + + b.ToTable("RaidTemplate", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.LiebRole", b => + { + b.Property("LiebRoleId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Level") + .HasColumnType("INTEGER"); + + b.Property("LevelToAssign") + .HasColumnType("INTEGER"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("LiebRoleId"); + + b.ToTable("LiebRole", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.LiebUser", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("AlwaysSignUpWithMainAccount") + .HasColumnType("INTEGER"); + + b.Property("BannedUntil") + .HasColumnType("TEXT"); + + b.Property("Birthday") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("LastSignUpAt") + .HasColumnType("TEXT"); + + b.Property("MainGW2Account") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("TEXT"); + + b.Property("Pronouns") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("LiebUser", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.RoleAssignment", b => + { + b.Property("RoleAssignmentId") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("LiebRoleId") + .HasColumnType("INTEGER"); + + b.Property("LiebUserId") + .HasColumnType("INTEGER"); + + b.HasKey("RoleAssignmentId"); + + b.HasIndex("LiebRoleId"); + + b.HasIndex("LiebUserId"); + + b.ToTable("RoleAssignment", (string)null); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Equipped", b => + { + b.HasOne("Lieb.Models.GuildWars2.GuildWars2Account", "GuildWars2Account") + .WithMany("EquippedBuilds") + .HasForeignKey("GuildWars2AccountId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lieb.Models.GuildWars2.GuildWars2Build", "GuildWars2Build") + .WithMany("EquippedRoles") + .HasForeignKey("GuildWars2BuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("GuildWars2Account"); + + b.Navigation("GuildWars2Build"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Account", b => + { + b.HasOne("Lieb.Models.LiebUser", null) + .WithMany("GuildWars2Accounts") + .HasForeignKey("LiebUserId"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.DiscordRaidMessage", b => + { + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", null) + .WithMany("DiscordRaidMessages") + .HasForeignKey("RaidId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", null) + .WithMany("DiscordRaidMessages") + .HasForeignKey("RaidTemplateId"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidReminder", b => + { + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", null) + .WithMany("Reminders") + .HasForeignKey("RaidId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", null) + .WithMany("Reminders") + .HasForeignKey("RaidTemplateId"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidRole", b => + { + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", null) + .WithMany("Roles") + .HasForeignKey("RaidId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidTemplate", null) + .WithMany("Roles") + .HasForeignKey("RaidTemplateId"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidSignUp", b => + { + b.HasOne("Lieb.Models.GuildWars2.GuildWars2Account", "GuildWars2Account") + .WithMany() + .HasForeignKey("GuildWars2AccountId"); + + b.HasOne("Lieb.Models.LiebUser", "LiebUser") + .WithMany() + .HasForeignKey("LiebUserId"); + + b.HasOne("Lieb.Models.GuildWars2.Raid.Raid", "Raid") + .WithMany("SignUps") + .HasForeignKey("RaidId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lieb.Models.GuildWars2.Raid.RaidRole", "RaidRole") + .WithMany() + .HasForeignKey("RaidRoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("GuildWars2Account"); + + b.Navigation("LiebUser"); + + b.Navigation("Raid"); + + b.Navigation("RaidRole"); + }); + + modelBuilder.Entity("Lieb.Models.RoleAssignment", b => + { + b.HasOne("Lieb.Models.LiebRole", "LiebRole") + .WithMany("RoleAssignments") + .HasForeignKey("LiebRoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Lieb.Models.LiebUser", "LiebUser") + .WithMany("RoleAssignments") + .HasForeignKey("LiebUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("LiebRole"); + + b.Navigation("LiebUser"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Account", b => + { + b.Navigation("EquippedBuilds"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Build", b => + { + b.Navigation("EquippedRoles"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.Raid", b => + { + b.Navigation("DiscordRaidMessages"); + + b.Navigation("Reminders"); + + b.Navigation("Roles"); + + b.Navigation("SignUps"); + }); + + modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidTemplate", b => + { + b.Navigation("DiscordRaidMessages"); + + b.Navigation("Reminders"); + + b.Navigation("Roles"); + }); + + modelBuilder.Entity("Lieb.Models.LiebRole", b => + { + b.Navigation("RoleAssignments"); + }); + + modelBuilder.Entity("Lieb.Models.LiebUser", b => + { + b.Navigation("GuildWars2Accounts"); + + b.Navigation("RoleAssignments"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Lieb/Migrations/20221208222423_AddReminderTypeGroup.cs b/Lieb/Migrations/20221208222423_AddReminderTypeGroup.cs new file mode 100644 index 0000000..4f1debb --- /dev/null +++ b/Lieb/Migrations/20221208222423_AddReminderTypeGroup.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Lieb.Migrations +{ + public partial class AddReminderTypeGroup : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "RoleId", + table: "RaidReminder", + type: "INTEGER", + nullable: false, + defaultValue: 0); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "RoleId", + table: "RaidReminder"); + } + } +} diff --git a/Lieb/Migrations/LiebContextModelSnapshot.cs b/Lieb/Migrations/LiebContextModelSnapshot.cs index d93895c..6acfa23 100644 --- a/Lieb/Migrations/LiebContextModelSnapshot.cs +++ b/Lieb/Migrations/LiebContextModelSnapshot.cs @@ -244,6 +244,9 @@ namespace Lieb.Migrations b.Property("ReminderTimeUTC") .HasColumnType("TEXT"); + b.Property("RoleId") + .HasColumnType("INTEGER"); + b.Property("Sent") .HasColumnType("INTEGER"); diff --git a/Lieb/Models/GuildWars2/Raid/RaidBase.cs b/Lieb/Models/GuildWars2/Raid/RaidBase.cs index 38d7f4b..228e0e3 100644 --- a/Lieb/Models/GuildWars2/Raid/RaidBase.cs +++ b/Lieb/Models/GuildWars2/Raid/RaidBase.cs @@ -102,7 +102,8 @@ namespace Lieb.Models.GuildWars2.Raid Message = reminder.Message, Sent = false, Type = reminder.Type, - TimeType = reminder.TimeType + TimeType = reminder.TimeType, + RoleId = reminder.RoleId }); } foreach (DiscordRaidMessage message in template.DiscordRaidMessages) diff --git a/Lieb/Models/GuildWars2/Raid/RaidReminder.cs b/Lieb/Models/GuildWars2/Raid/RaidReminder.cs index f1d3568..c32117c 100644 --- a/Lieb/Models/GuildWars2/Raid/RaidReminder.cs +++ b/Lieb/Models/GuildWars2/Raid/RaidReminder.cs @@ -8,7 +8,8 @@ namespace Lieb.Models.GuildWars2.Raid public enum ReminderType { User = 1, - Channel = 2 + Channel = 2, + Group = 3 } public enum ReminderTimeType @@ -20,7 +21,7 @@ namespace Lieb.Models.GuildWars2.Raid public int RaidReminderId { get; set; } [Required] - [Range(1, 2, ErrorMessage = "Please select a reminder type")] + [Range(1, 3, ErrorMessage = "Please select a reminder type")] public ReminderType Type { get; set; } [Required] @@ -38,6 +39,8 @@ namespace Lieb.Models.GuildWars2.Raid public ulong DiscordChannelId { get; set; } + public int RoleId {get; set; } + public bool Sent { get; set; } = false; } diff --git a/Lieb/Pages/Raids/RaidEdit/DynamicReminderEdit.razor b/Lieb/Pages/Raids/RaidEdit/DynamicReminderEdit.razor index 7a48671..889b568 100644 --- a/Lieb/Pages/Raids/RaidEdit/DynamicReminderEdit.razor +++ b/Lieb/Pages/Raids/RaidEdit/DynamicReminderEdit.razor @@ -14,21 +14,38 @@ Hours Minutes Type - @if(_raidReminders.Where(r => r.Type == RaidReminder.ReminderType.Channel).Any()) + @{bool channelReminderExists = _raidReminders.Where(r => r.Type == RaidReminder.ReminderType.Channel).Any(); + bool groupReminderExists = _raidReminders.Where(r => r.Type == RaidReminder.ReminderType.Group).Any();} + @if(channelReminderExists && groupReminderExists) { + Group Server Channel } + else if(channelReminderExists) + { + + Server + Channel + } + else if(groupReminderExists) + { + Group + + + } else { + } Message @foreach( DynamicRaidReminder reminder in _raidReminders) { - bool hidden = reminder.Type == RaidReminder.ReminderType.User; + bool groupHidden = reminder.Type != RaidReminder.ReminderType.Group; + bool discordHidden = reminder.Type != RaidReminder.ReminderType.Channel; @@ -42,7 +59,15 @@ -