diff --git a/DiscoBot/98293701175955456-gsmeet.db b/DiscoBot/98293701175955456-gsmeet.db index 60dff19..301f705 100644 Binary files a/DiscoBot/98293701175955456-gsmeet.db and b/DiscoBot/98293701175955456-gsmeet.db differ diff --git a/DiscoBot/gsmeet/GSMeet.cs b/DiscoBot/gsmeet/GSMeet.cs index 01ab1c3..a6228e9 100644 --- a/DiscoBot/gsmeet/GSMeet.cs +++ b/DiscoBot/gsmeet/GSMeet.cs @@ -12,6 +12,7 @@ using Discord; using Discord.WebSocket; using Google.Apis.Auth.OAuth2; using Google.Apis.Sheets.v4; +using Microsoft.EntityFrameworkCore; namespace DiscoBot.gsmeet { @@ -48,8 +49,19 @@ namespace DiscoBot.gsmeet ApplicationName = ApplicationName }); - foreach(var f in gsmeetContext.GSheets) + gsmeetContext.GSheets.Include(s => s.NotifiedEvents).Load(); + gsmeetContext.GSheets.Include(s => s.NotifiedUsers).Load(); + + foreach (var f in gsmeetContext.GSheets) { + if(f.NotifiedUsers == null) + { + f.NotifiedUsers = new List(); + } + if(f.NotifiedEvents == null) + { + f.NotifiedEvents = new List(); + } InitializeSheet(f); HandleSheetCheck(f); } @@ -120,14 +132,29 @@ namespace DiscoBot.gsmeet foreach(var date in sheetData.Dates) { - if(DateTimeOffset.UtcNow + new TimeSpan(4,0,0,0) > date) + if(DateTimeOffset.UtcNow + new TimeSpan(4,0,0,0) > date && date > DateTimeOffset.UtcNow) { await chan.SendMessageAsync("I should signup notify for " + date); foreach (var user in sheetData.Users) { if (!user.Signups.ContainsKey(date)) { - await chan.SendMessageAsync("Hey " + user.DiscordTag + " please sign up for our raid on " + date); + bool doNotify = true; + foreach(var notification in sheetData.Sheet.NotifiedUsers) + { + if(notification.Date == date && notification.DiscordTag == user.DiscordTag) + { + Console.WriteLine("User already notified."); + doNotify = false; + break; + } + } + if (doNotify) + { + await chan.SendMessageAsync("Hey " + user.DiscordTag + " please sign up for our raid on " + date); + var n = new GSMeetUserNotification(user.DiscordTag, date); + sheetData.Sheet.NotifiedUsers.Add(n); + } } } } @@ -147,6 +174,28 @@ namespace DiscoBot.gsmeet } } + private Task CleanupNotifyDB(GSMeetSheetData sheetData) + { + /* + foreach(var n in sheetData.Sheet.NotifiedEvents) + { + if(DateTimeOffset.UtcNow > n.Date) + { + sheetData.Sheet.NotifiedEvents.Remove(n); + } + } + foreach (var n in sheetData.Sheet.NotifiedUsers) + { + if (DateTimeOffset.UtcNow > n.Date) + { + sheetData.Sheet.NotifiedUsers.Remove(n); + } + } + gsmeetContext.SaveChanges(); + */ + return Task.CompletedTask; + } + private async Task HandleSheetCheck(DBSheet sheet) { @@ -162,6 +211,8 @@ namespace DiscoBot.gsmeet await c.SendMessageAsync("Parsed sheet " + sheet.Id); await SignupNotify(c, sheetData); await RaidNotify(c, sheetData); + gsmeetContext.SaveChanges(); + CleanupNotifyDB(sheetData); /* var str = ""; foreach (var row in values) diff --git a/DiscoBot/gsmeet/GSMeetContext.cs b/DiscoBot/gsmeet/GSMeetContext.cs index ad605ad..0ed1f2e 100644 --- a/DiscoBot/gsmeet/GSMeetContext.cs +++ b/DiscoBot/gsmeet/GSMeetContext.cs @@ -35,7 +35,7 @@ namespace DiscoBot.gsmeet public TimeSpan CheckInterval { get; set; } public DateTimeOffset LastChecked { get; set; } public List NotifiedEvents { get; set; } - public List NotifiedDates { get; set; } + public List NotifiedUsers { get; set; } } public class GSMeetEventNotification @@ -49,6 +49,11 @@ namespace DiscoBot.gsmeet public class GSMeetUserNotification { + public GSMeetUserNotification(string discordTag, DateTimeOffset date) + { + this.DiscordTag = discordTag; + this.Date = date; + } [ScaffoldColumn(false)] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] [Key]