Added sign up logging to discord
This commit is contained in:
parent
c3ed05fa7e
commit
25a381124d
1 changed files with 36 additions and 0 deletions
|
@ -96,6 +96,7 @@ namespace Lieb.Data
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
context.Raids.Remove(raid);
|
context.Raids.Remove(raid);
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
await _discordService.DeleteRaidMessages(raid);
|
await _discordService.DeleteRaidMessages(raid);
|
||||||
if(raid.EndTimeUTC > DateTimeOffset.UtcNow)
|
if(raid.EndTimeUTC > DateTimeOffset.UtcNow)
|
||||||
{
|
{
|
||||||
|
@ -423,6 +424,41 @@ namespace Lieb.Data
|
||||||
using var context = _contextFactory.CreateDbContext();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
await context.RaidLogs.AddAsync(log);
|
await context.RaidLogs.AddAsync(log);
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
|
await SendDiscordSignUpLogMessage(signUp, userName, signedUpBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SendDiscordSignUpLogMessage(RaidSignUp signUp, string userName, ulong signedUpBy = 0)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
|
||||||
|
Raid raid = context.Raids
|
||||||
|
.Include(r => r.DiscordRaidMessages)
|
||||||
|
.ToList()
|
||||||
|
.FirstOrDefault(r => r.RaidId == signUp.RaidId, new Raid());
|
||||||
|
|
||||||
|
if(raid.DiscordRaidMessages.Count > 0)
|
||||||
|
{
|
||||||
|
string signedUpByUserName = userName;
|
||||||
|
if(signedUpBy > 0)
|
||||||
|
{
|
||||||
|
LiebUser signedUpByUser = context.LiebUsers
|
||||||
|
.ToList()
|
||||||
|
.FirstOrDefault(u => u.Id == signedUpBy, new LiebUser());
|
||||||
|
signedUpByUserName = signedUpByUser.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
string message = $"{raid.Title}: {signedUpByUserName} signed up {userName} as {signUp.SignUpType.ToString()}";
|
||||||
|
foreach(DiscordRaidMessage discordMessage in raid.DiscordRaidMessages)
|
||||||
|
{
|
||||||
|
DiscordSettings settings = _discordService.GetDiscordSettings(discordMessage.DiscordGuildId);
|
||||||
|
if(settings.DiscordLogChannel > 0)
|
||||||
|
{
|
||||||
|
await _discordService.SendChannelMessage(discordMessage.DiscordGuildId, settings.DiscordLogChannel, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendReminders()
|
public async Task SendReminders()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue