|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Globalization; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Net.WebSockets; |
|
|
@ -28,6 +29,8 @@ namespace DiscoBot.gsmeet |
|
|
|
private static readonly string ApplicationName = "DiscoBot"; |
|
|
|
private SheetsService service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public GSMeet(SocketGuild guild) |
|
|
|
{ |
|
|
|
this.guild = guild; |
|
|
@ -48,6 +51,7 @@ namespace DiscoBot.gsmeet |
|
|
|
foreach(var f in gsmeetContext.GSheets) |
|
|
|
{ |
|
|
|
InitializeSheet(f); |
|
|
|
HandleSheetCheck(f); |
|
|
|
} |
|
|
|
|
|
|
|
Commands.Add("gsmeetadd", HandleGSMeetAddCommand); |
|
|
@ -56,7 +60,7 @@ namespace DiscoBot.gsmeet |
|
|
|
Commands.Add("gsmeetdebug", HandleGSMeetDebugCommand); |
|
|
|
} |
|
|
|
|
|
|
|
private Task InitializeSheet(GSheet sheet) |
|
|
|
private Task InitializeSheet(DBSheet sheet) |
|
|
|
{ |
|
|
|
Console.WriteLine("Found sheet " + sheet.Name); |
|
|
|
Timer timer = new Timer(sheet.CheckInterval.TotalMilliseconds); |
|
|
@ -70,7 +74,7 @@ namespace DiscoBot.gsmeet |
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
|
|
|
|
private Task DeinitializeSheets(GSheet sheet) |
|
|
|
private Task DeinitializeSheets(DBSheet sheet) |
|
|
|
{ |
|
|
|
/* |
|
|
|
Timer t = timers[feed.Name]; |
|
|
@ -80,16 +84,85 @@ namespace DiscoBot.gsmeet |
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
|
|
|
|
private Task HandleSheetCheck(GSheet sheet) |
|
|
|
private Task ParseGSMeetSheet(GSMeetSheetData sheetData, IList<IList<object>> values) |
|
|
|
{ |
|
|
|
var daterow = values[1]; |
|
|
|
var time = TimeSpan.Parse((string)daterow[0]); |
|
|
|
var events = new List<DateTimeOffset>(); |
|
|
|
var users = new List<GSMeetUser>(); |
|
|
|
for (int i = 2; i < daterow.Count; ++i) |
|
|
|
{ |
|
|
|
var col = daterow[i]; |
|
|
|
var d = DateTimeOffset.Parse((string)col, null, DateTimeStyles.AssumeUniversal); |
|
|
|
events.Add(d + time); |
|
|
|
} |
|
|
|
for (int i = 2; i < values.Count; ++i) |
|
|
|
{ |
|
|
|
var row = values[i]; |
|
|
|
GSMeetUser u = new GSMeetUser(); |
|
|
|
u.DiscordTag = (string)row[0]; |
|
|
|
u.Name = (string)row[1]; |
|
|
|
for (int j = 2; j < row.Count; ++j) |
|
|
|
{ |
|
|
|
var str = (string)row[j]; |
|
|
|
if(str != "") |
|
|
|
u.Signups.Add(events[j - 2], str); |
|
|
|
} |
|
|
|
users.Add(u); |
|
|
|
} |
|
|
|
sheetData.Dates = events; |
|
|
|
sheetData.Users = users; |
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
|
|
|
|
private async Task SignupNotify(SocketTextChannel chan, GSMeetSheetData sheetData) |
|
|
|
{ |
|
|
|
foreach(var date in sheetData.Dates) |
|
|
|
{ |
|
|
|
|
|
|
|
if(DateTimeOffset.UtcNow + new TimeSpan(4,0,0,0) > date) |
|
|
|
{ |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async Task RaidNotify(SocketTextChannel chan, GSMeetSheetData sheetData) |
|
|
|
{ |
|
|
|
foreach (var date in sheetData.Dates) |
|
|
|
{ |
|
|
|
|
|
|
|
if (DateTimeOffset.UtcNow + new TimeSpan(2,0,0,0) > date) |
|
|
|
{ |
|
|
|
await chan.SendMessageAsync("I should raid notify for " + date); |
|
|
|
//
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task HandleSheetCheck(DBSheet sheet) |
|
|
|
{ |
|
|
|
var sheetData = new GSMeetSheetData(sheet); |
|
|
|
SocketTextChannel c = guild.Channels.Where(g => g.Id == sheet.Channel).Single() as SocketTextChannel; |
|
|
|
c.SendMessageAsync("Checking sheet " + sheet.SheetId + " :3"); |
|
|
|
var values = FetchRangeFromSheet(sheet.SheetId, $"{sheet.SheetName}!A1:I10"); |
|
|
|
await c.SendMessageAsync("Checking sheet " + sheet.Id + " :3"); |
|
|
|
var values = FetchRangeFromSheet(sheet.Id, $"{sheet.SheetName}!A1:I10"); |
|
|
|
if (values == null || values.Count < 1) |
|
|
|
{ |
|
|
|
c.SendMessageAsync("No values found."); |
|
|
|
return Task.CompletedTask; |
|
|
|
await c.SendMessageAsync("No values found."); |
|
|
|
} |
|
|
|
await ParseGSMeetSheet(sheetData, values); |
|
|
|
await c.SendMessageAsync("Parsed sheet " + sheet.Id); |
|
|
|
await SignupNotify(c, sheetData); |
|
|
|
await RaidNotify(c, sheetData); |
|
|
|
/* |
|
|
|
var str = ""; |
|
|
|
foreach (var row in values) |
|
|
|
{ |
|
|
@ -100,7 +173,7 @@ namespace DiscoBot.gsmeet |
|
|
|
str += "\n"; |
|
|
|
} |
|
|
|
c.SendMessageAsync("Result: " + str); |
|
|
|
return Task.CompletedTask; |
|
|
|
*/ |
|
|
|
} |
|
|
|
|
|
|
|
private Task HandleGSMeetAddCommand(SocketMessage msg, string[] parameters) |
|
|
@ -112,10 +185,10 @@ namespace DiscoBot.gsmeet |
|
|
|
try |
|
|
|
{ |
|
|
|
int timeSec = Int32.Parse(parameters[4]); |
|
|
|
GSheet sheet = new GSheet(); |
|
|
|
DBSheet sheet = new DBSheet(); |
|
|
|
sheet.Channel = gchan.Id; |
|
|
|
sheet.Name = name; |
|
|
|
sheet.SheetId = sheetId; |
|
|
|
sheet.Id = sheetId; |
|
|
|
sheet.SheetName = sheetName; |
|
|
|
sheet.LastChecked = DateTimeOffset.Now; |
|
|
|
sheet.CheckInterval = new TimeSpan(0, 0, timeSec); |
|
|
@ -124,7 +197,7 @@ namespace DiscoBot.gsmeet |
|
|
|
{ |
|
|
|
gsmeetContext.SaveChanges(); |
|
|
|
InitializeSheet(sheet); |
|
|
|
msg.Channel.SendMessageAsync("Sheet " + sheet.Name + " with id " + sheet.SheetId + " saved."); |
|
|
|
msg.Channel.SendMessageAsync("Sheet " + sheet.Name + " with id " + sheet.Id + " saved."); |
|
|
|
} |
|
|
|
catch (InvalidOperationException) |
|
|
|
{ |
|
|
|