reminders now always include the raid name

This commit is contained in:
Sarah Faey 2022-12-03 11:02:59 +01:00
parent f9e05ab545
commit 2a9cd89783
2 changed files with 14 additions and 14 deletions

View file

@ -182,9 +182,9 @@ namespace Lieb.Data
return false; return false;
} }
public async Task SendChannelReminder(RaidReminder reminder) public async Task SendChannelReminder(RaidReminder reminder, string raidTitle)
{ {
if (await SendChannelMessage(reminder.DiscordServerId, reminder.DiscordChannelId, reminder.Message)) if (await SendChannelMessage(reminder.DiscordServerId, reminder.DiscordChannelId, reminder.Message, raidTitle))
{ {
reminder.Sent = true; reminder.Sent = true;
using var context = _contextFactory.CreateDbContext(); using var context = _contextFactory.CreateDbContext();
@ -193,13 +193,13 @@ namespace Lieb.Data
} }
} }
public async Task<bool> SendChannelMessage(ulong discordServerId, ulong discordChannelId, string message) public async Task<bool> SendChannelMessage(ulong discordServerId, ulong discordChannelId, string message, string raidTitle)
{ {
try try
{ {
var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName); var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName);
ApiChannelReminder apiReminder = ConvertChannelReminder(discordServerId, discordChannelId, message); ApiChannelReminder apiReminder = ConvertChannelReminder(discordServerId, discordChannelId, message, raidTitle);
var raidItemJson = new StringContent( var raidItemJson = new StringContent(
JsonSerializer.Serialize(apiReminder), JsonSerializer.Serialize(apiReminder),
@ -305,7 +305,7 @@ namespace Lieb.Data
{ {
ApiUserReminder apiReminder = new ApiUserReminder() ApiUserReminder apiReminder = new ApiUserReminder()
{ {
Message = message Message = $"{raid.Title}: {message}"
}; };
apiReminder.UserIds = new List<ulong>(); apiReminder.UserIds = new List<ulong>();
HashSet<ulong> userIds = new HashSet<ulong>(); HashSet<ulong> userIds = new HashSet<ulong>();
@ -320,13 +320,13 @@ namespace Lieb.Data
return apiReminder; return apiReminder;
} }
public static ApiChannelReminder ConvertChannelReminder(ulong discordServerId, ulong discordChannelId, string message) public static ApiChannelReminder ConvertChannelReminder(ulong discordServerId, ulong discordChannelId, string message, string raidTitle)
{ {
return new ApiChannelReminder() return new ApiChannelReminder()
{ {
DiscordServerId = discordServerId, DiscordServerId = discordServerId,
DiscordChannelId = discordChannelId, DiscordChannelId = discordChannelId,
Message = message Message = $"{raidTitle}: {message}"
}; };
} }

View file

@ -477,13 +477,13 @@ namespace Lieb.Data
signedUpByUserName = signedUpByUser.Name; signedUpByUserName = signedUpByUser.Name;
} }
string message = $"{raid.Title}: {signedUpByUserName} signed up {userName} as {signUp.SignUpType.ToString()}"; string message = $"{signedUpByUserName} signed up {userName} as {signUp.SignUpType.ToString()}";
foreach(DiscordRaidMessage discordMessage in raid.DiscordRaidMessages) foreach(DiscordRaidMessage discordMessage in raid.DiscordRaidMessages)
{ {
DiscordSettings settings = _discordService.GetDiscordSettings(discordMessage.DiscordGuildId); DiscordSettings settings = _discordService.GetDiscordSettings(discordMessage.DiscordGuildId);
if(settings.DiscordLogChannel > 0) if(settings.DiscordLogChannel > 0)
{ {
await _discordService.SendChannelMessage(discordMessage.DiscordGuildId, settings.DiscordLogChannel, message); await _discordService.SendChannelMessage(discordMessage.DiscordGuildId, settings.DiscordLogChannel, message, raid.Title);
} }
} }
} }
@ -500,17 +500,17 @@ namespace Lieb.Data
DateTimeOffset utcNow = DateTimeOffset.UtcNow; DateTimeOffset utcNow = DateTimeOffset.UtcNow;
foreach(RaidReminder reminder in reminders.Where(r => r.ReminderTimeUTC < utcNow)) foreach(RaidReminder reminder in reminders.Where(r => r.ReminderTimeUTC < utcNow))
{ {
switch(reminder.Type)
{
case RaidReminder.ReminderType.User:
Raid raid = context.Raids Raid raid = context.Raids
.Include(r => r.SignUps) .Include(r => r.SignUps)
.Include(r => r.Reminders) .Include(r => r.Reminders)
.First(r => r.Reminders.Where(re => re.RaidReminderId == reminder.RaidReminderId).Any()); .First(r => r.Reminders.Where(re => re.RaidReminderId == reminder.RaidReminderId).Any());
switch(reminder.Type)
{
case RaidReminder.ReminderType.User:
await _discordService.SendUserReminder(reminder, raid); await _discordService.SendUserReminder(reminder, raid);
break; break;
case RaidReminder.ReminderType.Channel: case RaidReminder.ReminderType.Channel:
await _discordService.SendChannelReminder(reminder); await _discordService.SendChannelReminder(reminder, raid.Title);
break; break;
} }
} }