Browse Source

Notify werks delete not

master
amki 5 years ago
parent
commit
f2ca526678
  1. BIN
      DiscoBot/98293701175955456-gsmeet.db
  2. 57
      DiscoBot/gsmeet/GSMeet.cs
  3. 7
      DiscoBot/gsmeet/GSMeetContext.cs

BIN
DiscoBot/98293701175955456-gsmeet.db

Binary file not shown.

57
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<GSMeetUserNotification>();
}
if(f.NotifiedEvents == null)
{
f.NotifiedEvents = new List<GSMeetEventNotification>();
}
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)

7
DiscoBot/gsmeet/GSMeetContext.cs

@ -35,7 +35,7 @@ namespace DiscoBot.gsmeet
public TimeSpan CheckInterval { get; set; }
public DateTimeOffset LastChecked { get; set; }
public List<GSMeetEventNotification> NotifiedEvents { get; set; }
public List<GSMeetUserNotification> NotifiedDates { get; set; }
public List<GSMeetUserNotification> 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]

Loading…
Cancel
Save