Added group reminder

This commit is contained in:
Sarah Faey 2022-12-08 23:27:26 +01:00
parent 83f9b2d0b8
commit 64ce169094
12 changed files with 853 additions and 45 deletions

View file

@ -148,6 +148,7 @@ namespace Lieb.Data
return new List<DiscordServer>(); return new List<DiscordServer>();
} }
#region UserReminder
public async Task SendUserReminder(RaidReminder reminder, Raid raid) public async Task SendUserReminder(RaidReminder reminder, Raid raid)
{ {
if (await SendMessageToRaidUsers(reminder.Message, raid)) if (await SendMessageToRaidUsers(reminder.Message, raid))
@ -183,6 +184,27 @@ namespace Lieb.Data
return false; return false;
} }
public static ApiUserReminder ConvertUserReminder(string message, Raid raid)
{
ApiUserReminder apiReminder = new ApiUserReminder()
{
Message = $"{raid.Title}: {message}"
};
apiReminder.UserIds = new List<ulong>();
HashSet<ulong> userIds = new HashSet<ulong>();
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) public async Task SendChannelReminder(RaidReminder reminder, string raidTitle)
{ {
if (await SendChannelMessage(reminder.DiscordServerId, reminder.DiscordChannelId, reminder.Message, raidTitle)) if (await SendChannelMessage(reminder.DiscordServerId, reminder.DiscordChannelId, reminder.Message, raidTitle))
@ -215,6 +237,63 @@ namespace Lieb.Data
return false; 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<ulong> 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<bool> SendMessageToGroup(string message, string raidTitle, HashSet<ulong> 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<ulong> groupIds)
{
ApiUserReminder apiReminder = new ApiUserReminder()
{
Message = $"{raidTitle}: {message}"
};
apiReminder.UserIds = groupIds.ToList();
return apiReminder;
}
#endregion GroupReminder
private async Task UpdateDiscordMessages(IEnumerable<ApiRaid.DiscordMessage> messages, Raid raid) private async Task UpdateDiscordMessages(IEnumerable<ApiRaid.DiscordMessage> messages, Raid raid)
{ {
foreach(ApiRaid.DiscordMessage message in messages) foreach(ApiRaid.DiscordMessage message in messages)
@ -302,35 +381,6 @@ namespace Lieb.Data
return apiMessages; return apiMessages;
} }
public static ApiUserReminder ConvertUserReminder(string message, Raid raid)
{
ApiUserReminder apiReminder = new ApiUserReminder()
{
Message = $"{raid.Title}: {message}"
};
apiReminder.UserIds = new List<ulong>();
HashSet<ulong> userIds = new HashSet<ulong>();
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) public async Task RenameUser(ulong userId, string name, string account)
{ {
try try

View file

@ -518,6 +518,9 @@ namespace Lieb.Data
case RaidReminder.ReminderType.Channel: case RaidReminder.ReminderType.Channel:
await _discordService.SendChannelReminder(reminder, raid.Title); await _discordService.SendChannelReminder(reminder, raid.Title);
break; break;
case RaidReminder.ReminderType.Group:
await _discordService.SendGroupReminder(reminder, raid.Title);
break;
} }
} }
} }

View file

@ -235,6 +235,16 @@ namespace Lieb.Data
.ToList(); .ToList();
} }
public List<LiebRole> 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) public async Task AddRole(LiebRole role)
{ {
using var context = _contextFactory.CreateDbContext(); using var context = _contextFactory.CreateDbContext();

View file

@ -0,0 +1,653 @@
// <auto-generated />
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<ulong>("DiscordSettingsId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("ChangeUserNames")
.HasColumnType("INTEGER");
b.Property<ulong>("DiscordLogChannel")
.HasColumnType("INTEGER");
b.HasKey("DiscordSettingsId");
b.ToTable("DiscordSettings", (string)null);
});
modelBuilder.Entity("Lieb.Models.GuildWars2.Equipped", b =>
{
b.Property<int>("EquippedId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("CanTank")
.HasColumnType("INTEGER");
b.Property<int>("GuildWars2AccountId")
.HasColumnType("INTEGER");
b.Property<int>("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<int>("GuildWars2AccountId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("AccountName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ApiKey")
.IsRequired()
.HasColumnType("TEXT");
b.Property<ulong?>("LiebUserId")
.HasColumnType("INTEGER");
b.HasKey("GuildWars2AccountId");
b.HasIndex("LiebUserId");
b.ToTable("GuildWars2Account", (string)null);
});
modelBuilder.Entity("Lieb.Models.GuildWars2.GuildWars2Build", b =>
{
b.Property<int>("GuildWars2BuildId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<bool>("Alacrity")
.HasColumnType("INTEGER");
b.Property<string>("BuildName")
.IsRequired()
.HasMaxLength(60)
.HasColumnType("TEXT");
b.Property<int>("Class")
.HasColumnType("INTEGER");
b.Property<int>("DamageType")
.HasColumnType("INTEGER");
b.Property<int>("EliteSpecialization")
.HasColumnType("INTEGER");
b.Property<bool>("Might")
.HasColumnType("INTEGER");
b.Property<bool>("Quickness")
.HasColumnType("INTEGER");
b.Property<string>("Source")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("SourceLink")
.IsRequired()
.HasColumnType("TEXT");
b.Property<bool>("UseInRandomRaid")
.HasColumnType("INTEGER");
b.HasKey("GuildWars2BuildId");
b.ToTable("GuildWars2Build", (string)null);
});
modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.DiscordRaidMessage", b =>
{
b.Property<int>("DiscordRaidMessageId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<ulong>("DiscordChannelId")
.HasColumnType("INTEGER");
b.Property<ulong>("DiscordGuildId")
.HasColumnType("INTEGER");
b.Property<ulong>("DiscordMessageId")
.HasColumnType("INTEGER");
b.Property<int?>("RaidId")
.HasColumnType("INTEGER");
b.Property<int?>("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<int>("RaidId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(1000)
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("EndTimeUTC")
.HasColumnType("TEXT");
b.Property<int>("EventType")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("FreeForAllTimeUTC")
.HasColumnType("TEXT");
b.Property<string>("Guild")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<bool>("MoveFlexUsers")
.HasColumnType("INTEGER");
b.Property<string>("Organizer")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<ulong?>("RaidOwnerId")
.HasColumnType("INTEGER");
b.Property<int>("RaidType")
.HasColumnType("INTEGER");
b.Property<string>("RequiredRole")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("StartTimeUTC")
.HasColumnType("TEXT");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("VoiceChat")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("RaidId");
b.ToTable("Raid", (string)null);
});
modelBuilder.Entity("Lieb.Models.GuildWars2.Raid.RaidReminder", b =>
{
b.Property<int>("RaidReminderId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<ulong>("DiscordChannelId")
.HasColumnType("INTEGER");
b.Property<ulong>("DiscordServerId")
.HasColumnType("INTEGER");
b.Property<string>("Message")
.IsRequired()
.HasMaxLength(1000)
.HasColumnType("TEXT");
b.Property<int?>("RaidId")
.HasColumnType("INTEGER");
b.Property<int?>("RaidTemplateId")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("ReminderTimeUTC")
.HasColumnType("TEXT");
b.Property<int>("RoleId")
.HasColumnType("INTEGER");
b.Property<bool>("Sent")
.HasColumnType("INTEGER");
b.Property<int>("TimeType")
.HasColumnType("INTEGER");
b.Property<int>("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<int>("RaidRoleId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<bool>("IsRandomSignUpRole")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("TEXT");
b.Property<int?>("RaidId")
.HasColumnType("INTEGER");
b.Property<int?>("RaidTemplateId")
.HasColumnType("INTEGER");
b.Property<int>("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<int>("RaidSignUpId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ExternalUserName")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int?>("GuildWars2AccountId")
.HasColumnType("INTEGER");
b.Property<ulong?>("LiebUserId")
.HasColumnType("INTEGER");
b.Property<int>("RaidId")
.HasColumnType("INTEGER");
b.Property<int>("RaidRoleId")
.HasColumnType("INTEGER");
b.Property<int>("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<int>("RaidTemplateId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("CreateDaysBefore")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(1000)
.HasColumnType("TEXT");
b.Property<DateTime>("EndTime")
.HasColumnType("TEXT");
b.Property<int>("EventType")
.HasColumnType("INTEGER");
b.Property<DateTime>("FreeForAllTime")
.HasColumnType("TEXT");
b.Property<string>("Guild")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<int>("Interval")
.HasColumnType("INTEGER");
b.Property<bool>("MoveFlexUsers")
.HasColumnType("INTEGER");
b.Property<string>("Organizer")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<ulong?>("RaidOwnerId")
.HasColumnType("INTEGER");
b.Property<int>("RaidType")
.HasColumnType("INTEGER");
b.Property<string>("RequiredRole")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTime>("StartTime")
.HasColumnType("TEXT");
b.Property<string>("TimeZone")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("VoiceChat")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("RaidTemplateId");
b.ToTable("RaidTemplate", (string)null);
});
modelBuilder.Entity("Lieb.Models.LiebRole", b =>
{
b.Property<int>("LiebRoleId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Level")
.HasColumnType("INTEGER");
b.Property<int>("LevelToAssign")
.HasColumnType("INTEGER");
b.Property<string>("RoleName")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("LiebRoleId");
b.ToTable("LiebRole", (string)null);
});
modelBuilder.Entity("Lieb.Models.LiebUser", b =>
{
b.Property<ulong>("Id")
.HasColumnType("INTEGER");
b.Property<bool>("AlwaysSignUpWithMainAccount")
.HasColumnType("INTEGER");
b.Property<DateTime?>("BannedUntil")
.HasColumnType("TEXT");
b.Property<DateTime?>("Birthday")
.HasColumnType("TEXT");
b.Property<DateTime>("CreatedAt")
.HasColumnType("TEXT");
b.Property<DateTime?>("LastSignUpAt")
.HasColumnType("TEXT");
b.Property<int>("MainGW2Account")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("TEXT");
b.Property<string>("Pronouns")
.IsRequired()
.HasMaxLength(60)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("LiebUser", (string)null);
});
modelBuilder.Entity("Lieb.Models.RoleAssignment", b =>
{
b.Property<int>("RoleAssignmentId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("LiebRoleId")
.HasColumnType("INTEGER");
b.Property<ulong>("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
}
}
}

View file

@ -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<int>(
name: "RoleId",
table: "RaidReminder",
type: "INTEGER",
nullable: false,
defaultValue: 0);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "RoleId",
table: "RaidReminder");
}
}
}

View file

@ -244,6 +244,9 @@ namespace Lieb.Migrations
b.Property<DateTimeOffset>("ReminderTimeUTC") b.Property<DateTimeOffset>("ReminderTimeUTC")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<int>("RoleId")
.HasColumnType("INTEGER");
b.Property<bool>("Sent") b.Property<bool>("Sent")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");

View file

@ -102,7 +102,8 @@ namespace Lieb.Models.GuildWars2.Raid
Message = reminder.Message, Message = reminder.Message,
Sent = false, Sent = false,
Type = reminder.Type, Type = reminder.Type,
TimeType = reminder.TimeType TimeType = reminder.TimeType,
RoleId = reminder.RoleId
}); });
} }
foreach (DiscordRaidMessage message in template.DiscordRaidMessages) foreach (DiscordRaidMessage message in template.DiscordRaidMessages)

View file

@ -8,7 +8,8 @@ namespace Lieb.Models.GuildWars2.Raid
public enum ReminderType public enum ReminderType
{ {
User = 1, User = 1,
Channel = 2 Channel = 2,
Group = 3
} }
public enum ReminderTimeType public enum ReminderTimeType
@ -20,7 +21,7 @@ namespace Lieb.Models.GuildWars2.Raid
public int RaidReminderId { get; set; } public int RaidReminderId { get; set; }
[Required] [Required]
[Range(1, 2, ErrorMessage = "Please select a reminder type")] [Range(1, 3, ErrorMessage = "Please select a reminder type")]
public ReminderType Type { get; set; } public ReminderType Type { get; set; }
[Required] [Required]
@ -38,6 +39,8 @@ namespace Lieb.Models.GuildWars2.Raid
public ulong DiscordChannelId { get; set; } public ulong DiscordChannelId { get; set; }
public int RoleId {get; set; }
public bool Sent { get; set; } = false; public bool Sent { get; set; } = false;
} }

View file

@ -14,21 +14,38 @@
<th>Hours</th> <th>Hours</th>
<th>Minutes</th> <th>Minutes</th>
<th>Type</th> <th>Type</th>
@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)
{ {
<th>Group</th>
<th>Server</th> <th>Server</th>
<th>Channel</th> <th>Channel</th>
} }
else if(channelReminderExists)
{
<th></th>
<th>Server</th>
<th>Channel</th>
}
else if(groupReminderExists)
{
<th>Group</th>
<th></th>
<th></th>
}
else else
{ {
<th></th> <th></th>
<th></th> <th></th>
<th></th>
} }
<th>Message</th> <th>Message</th>
</tr> </tr>
@foreach( DynamicRaidReminder reminder in _raidReminders) @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;
<tr> <tr>
<td><InputNumber @bind-Value="reminder.DaysBeforeRaid" /></td> <td><InputNumber @bind-Value="reminder.DaysBeforeRaid" /></td>
<td><InputNumber @bind-Value="reminder.HoursBeforeRaid" /></td> <td><InputNumber @bind-Value="reminder.HoursBeforeRaid" /></td>
@ -42,7 +59,15 @@
</InputSelect> </InputSelect>
</td> </td>
<td> <td>
<InputSelect @bind-Value="reminder.DiscordServerId" hidden="@hidden"> <InputSelect @bind-Value="reminder.RoleId" hidden="@groupHidden">
@foreach(LiebRole role in _availableRoles)
{
<option value="@role.LiebRoleId">@role.RoleName</option>
}
</InputSelect>
</td>
<td>
<InputSelect @bind-Value="reminder.DiscordServerId" hidden="@discordHidden">
@foreach(DiscordServer item in _discordServers) @foreach(DiscordServer item in _discordServers)
{ {
<option value="@item.Id">@item.Name</option> <option value="@item.Id">@item.Name</option>
@ -50,7 +75,7 @@
</InputSelect> </InputSelect>
</td> </td>
<td> <td>
<InputSelect @bind-Value="reminder.DiscordChannelId" hidden="@hidden"> <InputSelect @bind-Value="reminder.DiscordChannelId" hidden="@discordHidden">
@if(reminder.DiscordServerId > 0) @if(reminder.DiscordServerId > 0)
{ {
List<DiscordChannel> channels = _discordServers.Where(s => s.Id == reminder.DiscordServerId).FirstOrDefault(new DiscordServer()).Channels; List<DiscordChannel> channels = _discordServers.Where(s => s.Id == reminder.DiscordServerId).FirstOrDefault(new DiscordServer()).Channels;
@ -81,6 +106,9 @@
[Parameter] [Parameter]
public List<RaidReminder> _remindersToDelete {get; set; } public List<RaidReminder> _remindersToDelete {get; set; }
[Parameter]
public List<LiebRole> _availableRoles {get; set; }
async Task AddReminderClicked() async Task AddReminderClicked()
{ {

View file

@ -167,8 +167,8 @@
<DiscordMessageEdit _raid=@_raid _discordServers=@_discordServers _messagesToDelete=@_messagesToDelete ></DiscordMessageEdit> <DiscordMessageEdit _raid=@_raid _discordServers=@_discordServers _messagesToDelete=@_messagesToDelete ></DiscordMessageEdit>
<StaticReminderEdit _raidReminders=@_staticReminders _discordServers=@_discordServers _remindersToDelete=@_remindersToDelete ></StaticReminderEdit> <StaticReminderEdit _raidReminders=@_staticReminders _discordServers=@_discordServers _remindersToDelete=@_remindersToDelete _availableRoles=@_availabeGroups></StaticReminderEdit>
<DynamicReminderEdit _raidReminders=@_dynamicReminders _discordServers=@_discordServers _remindersToDelete=@_remindersToDelete ></DynamicReminderEdit> <DynamicReminderEdit _raidReminders=@_dynamicReminders _discordServers=@_discordServers _remindersToDelete=@_remindersToDelete _availableRoles=@_availabeGroups></DynamicReminderEdit>
<ValidationSummary /> <ValidationSummary />
<label class="validation-message" >@_errorMessage</label> <label class="validation-message" >@_errorMessage</label>
@ -203,7 +203,7 @@
private List<DynamicRaidReminder> _dynamicReminders = new List<DynamicRaidReminder>(); private List<DynamicRaidReminder> _dynamicReminders = new List<DynamicRaidReminder>();
private List<DiscordServer> _discordServers = new List<DiscordServer>(); private List<DiscordServer> _discordServers = new List<DiscordServer>();
private List<LiebRole> _availabeGroups = new List<LiebRole>();
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
@ -267,6 +267,7 @@
} }
_discordServers = await DiscordService.GetServers(); _discordServers = await DiscordService.GetServers();
_availabeGroups = UserService.GetUserRoles(_user.Id).Where(u => u.Type == RoleType.UserDefinedRole).ToList();
} }
async Task AddRoleClicked() async Task AddRoleClicked()

View file

@ -189,8 +189,8 @@
} }
<DiscordMessageEdit _raid=@_template _discordServers=@_discordServers _messagesToDelete=@_messagesToDelete ></DiscordMessageEdit> <DiscordMessageEdit _raid=@_template _discordServers=@_discordServers _messagesToDelete=@_messagesToDelete ></DiscordMessageEdit>
<StaticReminderEdit _raidReminders=@_staticReminders _discordServers=@_discordServers _remindersToDelete=@_remindersToDelete ></StaticReminderEdit> <StaticReminderEdit _raidReminders=@_staticReminders _discordServers=@_discordServers _remindersToDelete=@_remindersToDelete _availableRoles=@_availabeGroups></StaticReminderEdit>
<DynamicReminderEdit _raidReminders=@_dynamicReminders _discordServers=@_discordServers _remindersToDelete=@_remindersToDelete ></DynamicReminderEdit> <DynamicReminderEdit _raidReminders=@_dynamicReminders _discordServers=@_discordServers _remindersToDelete=@_remindersToDelete _availableRoles=@_availabeGroups></DynamicReminderEdit>
<ValidationSummary /> <ValidationSummary />
<label class="validation-message" >@_errorMessage</label> <label class="validation-message" >@_errorMessage</label>
@ -232,6 +232,7 @@
private List<DynamicRaidReminder> _dynamicReminders = new List<DynamicRaidReminder>(); private List<DynamicRaidReminder> _dynamicReminders = new List<DynamicRaidReminder>();
private List<DiscordServer> _discordServers = new List<DiscordServer>(); private List<DiscordServer> _discordServers = new List<DiscordServer>();
private List<LiebRole> _availabeGroups = new List<LiebRole>();
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
@ -300,6 +301,7 @@
} }
_userTimeZone = await TimeZoneService.GetUserTimeZone(); _userTimeZone = await TimeZoneService.GetUserTimeZone();
_discordServers = await DiscordService.GetServers(); _discordServers = await DiscordService.GetServers();
_availabeGroups = UserService.GetUserRoles(_user.Id).Where(u => u.Type == RoleType.UserDefinedRole).ToList();
} }
async Task AddRoleClicked() async Task AddRoleClicked()

View file

@ -13,21 +13,38 @@
<th>Date</th> <th>Date</th>
<th>Time</th> <th>Time</th>
<th>Type</th> <th>Type</th>
@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)
{ {
<th>Group</th>
<th>Server</th> <th>Server</th>
<th>Channel</th> <th>Channel</th>
} }
else if(channelReminderExists)
{
<th></th>
<th>Server</th>
<th>Channel</th>
}
else if(groupReminderExists)
{
<th>Group</th>
<th></th>
<th></th>
}
else else
{ {
<th></th> <th></th>
<th></th> <th></th>
<th></th>
} }
<th>Message</th> <th>Message</th>
</tr> </tr>
@foreach( StaticRaidReminder reminder in _raidReminders) @foreach( StaticRaidReminder reminder in _raidReminders)
{ {
bool hidden = reminder.Type == RaidReminder.ReminderType.User; bool groupHidden = reminder.Type != RaidReminder.ReminderType.Group;
bool discordHidden = reminder.Type != RaidReminder.ReminderType.Channel;
<tr> <tr>
<td> <td>
<label> <label>
@ -49,7 +66,15 @@
</InputSelect> </InputSelect>
</td> </td>
<td> <td>
<InputSelect @bind-Value="reminder.DiscordServerId" hidden="@hidden"> <InputSelect @bind-Value="reminder.RoleId" hidden="@groupHidden">
@foreach(LiebRole role in _availableRoles)
{
<option value="@role.LiebRoleId">@role.RoleName</option>
}
</InputSelect>
</td>
<td>
<InputSelect @bind-Value="reminder.DiscordServerId" hidden="@discordHidden">
@foreach(DiscordServer item in _discordServers) @foreach(DiscordServer item in _discordServers)
{ {
<option value="@item.Id">@item.Name</option> <option value="@item.Id">@item.Name</option>
@ -57,7 +82,7 @@
</InputSelect> </InputSelect>
</td> </td>
<td> <td>
<InputSelect @bind-Value="reminder.DiscordChannelId" hidden="@hidden"> <InputSelect @bind-Value="reminder.DiscordChannelId" hidden="@discordHidden">
@if(reminder.DiscordServerId > 0) @if(reminder.DiscordServerId > 0)
{ {
List<DiscordChannel> channels = _discordServers.Where(s => s.Id == reminder.DiscordServerId).FirstOrDefault(new DiscordServer()).Channels; List<DiscordChannel> channels = _discordServers.Where(s => s.Id == reminder.DiscordServerId).FirstOrDefault(new DiscordServer()).Channels;
@ -88,6 +113,9 @@
[Parameter] [Parameter]
public List<RaidReminder> _remindersToDelete {get; set; } public List<RaidReminder> _remindersToDelete {get; set; }
[Parameter]
public List<LiebRole> _availableRoles {get; set; }
async Task AddReminderClicked() async Task AddReminderClicked()
{ {