Notify werks delete not
This commit is contained in:
		
							parent
							
								
									096bcb7d59
								
							
						
					
					
						commit
						f2ca526678
					
				
										
											Binary file not shown.
										
									
								
							| @ -12,6 +12,7 @@ using Discord; | |||||||
| using Discord.WebSocket; | using Discord.WebSocket; | ||||||
| using Google.Apis.Auth.OAuth2; | using Google.Apis.Auth.OAuth2; | ||||||
| using Google.Apis.Sheets.v4; | using Google.Apis.Sheets.v4; | ||||||
|  | using Microsoft.EntityFrameworkCore; | ||||||
| 
 | 
 | ||||||
| namespace DiscoBot.gsmeet | namespace DiscoBot.gsmeet | ||||||
| { | { | ||||||
| @ -48,8 +49,19 @@ namespace DiscoBot.gsmeet | |||||||
|                 ApplicationName = ApplicationName |                 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<GSMeetUserNotification>(); | ||||||
|  |                 } | ||||||
|  |                 if(f.NotifiedEvents == null) | ||||||
|  |                 { | ||||||
|  |                     f.NotifiedEvents = new List<GSMeetEventNotification>(); | ||||||
|  |                 } | ||||||
|                 InitializeSheet(f); |                 InitializeSheet(f); | ||||||
|                 HandleSheetCheck(f); |                 HandleSheetCheck(f); | ||||||
|             } |             } | ||||||
| @ -120,14 +132,29 @@ namespace DiscoBot.gsmeet | |||||||
|             foreach(var date in sheetData.Dates) |             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); |                     await chan.SendMessageAsync("I should signup notify for " + date); | ||||||
|                     foreach (var user in sheetData.Users) |                     foreach (var user in sheetData.Users) | ||||||
|                     { |                     { | ||||||
|                         if (!user.Signups.ContainsKey(date)) |                         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) |         private async Task HandleSheetCheck(DBSheet sheet) | ||||||
|         { |         { | ||||||
| @ -162,6 +211,8 @@ namespace DiscoBot.gsmeet | |||||||
|             await c.SendMessageAsync("Parsed sheet " + sheet.Id); |             await c.SendMessageAsync("Parsed sheet " + sheet.Id); | ||||||
|             await SignupNotify(c, sheetData); |             await SignupNotify(c, sheetData); | ||||||
|             await RaidNotify(c, sheetData); |             await RaidNotify(c, sheetData); | ||||||
|  |             gsmeetContext.SaveChanges(); | ||||||
|  |             CleanupNotifyDB(sheetData); | ||||||
|             /* |             /* | ||||||
|             var str = ""; |             var str = ""; | ||||||
|             foreach (var row in values) |             foreach (var row in values) | ||||||
|  | |||||||
| @ -35,7 +35,7 @@ namespace DiscoBot.gsmeet | |||||||
|         public TimeSpan CheckInterval { get; set; } |         public TimeSpan CheckInterval { get; set; } | ||||||
|         public DateTimeOffset LastChecked { get; set; } |         public DateTimeOffset LastChecked { get; set; } | ||||||
|         public List<GSMeetEventNotification> NotifiedEvents { get; set; } |         public List<GSMeetEventNotification> NotifiedEvents { get; set; } | ||||||
|         public List<GSMeetUserNotification> NotifiedDates { get; set; } |         public List<GSMeetUserNotification> NotifiedUsers { get; set; } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public class GSMeetEventNotification |     public class GSMeetEventNotification | ||||||
| @ -49,6 +49,11 @@ namespace DiscoBot.gsmeet | |||||||
| 
 | 
 | ||||||
|     public class GSMeetUserNotification |     public class GSMeetUserNotification | ||||||
|     { |     { | ||||||
|  |         public GSMeetUserNotification(string discordTag, DateTimeOffset date) | ||||||
|  |         { | ||||||
|  |             this.DiscordTag = discordTag; | ||||||
|  |             this.Date = date; | ||||||
|  |         } | ||||||
|         [ScaffoldColumn(false)] |         [ScaffoldColumn(false)] | ||||||
|         [DatabaseGenerated(DatabaseGeneratedOption.Identity)] |         [DatabaseGenerated(DatabaseGeneratedOption.Identity)] | ||||||
|         [Key] |         [Key] | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user