diff --git a/DiscoBot/299585558710190101-bdaygreet.db b/DiscoBot/299585558710190101-bdaygreet.db new file mode 100644 index 0000000..b36966e Binary files /dev/null and b/DiscoBot/299585558710190101-bdaygreet.db differ diff --git a/DiscoBot/299585558710190101-calendar.db b/DiscoBot/299585558710190101-calendar.db new file mode 100644 index 0000000..79be177 Binary files /dev/null and b/DiscoBot/299585558710190101-calendar.db differ diff --git a/DiscoBot/299585558710190101-gsmeet.db b/DiscoBot/299585558710190101-gsmeet.db new file mode 100644 index 0000000..4784be8 Binary files /dev/null and b/DiscoBot/299585558710190101-gsmeet.db differ diff --git a/DiscoBot/299585558710190101-rss.db b/DiscoBot/299585558710190101-rss.db new file mode 100644 index 0000000..89307fb Binary files /dev/null and b/DiscoBot/299585558710190101-rss.db differ diff --git a/DiscoBot/615631052047908870-gsmeet.db b/DiscoBot/615631052047908870-gsmeet.db index b43463e..4784be8 100644 Binary files a/DiscoBot/615631052047908870-gsmeet.db and b/DiscoBot/615631052047908870-gsmeet.db differ diff --git a/DiscoBot/98293701175955456-bdaygreet.db b/DiscoBot/98293701175955456-bdaygreet.db index 4f94444..2fbc4c6 100644 Binary files a/DiscoBot/98293701175955456-bdaygreet.db and b/DiscoBot/98293701175955456-bdaygreet.db differ diff --git a/DiscoBot/98293701175955456-calendar.db b/DiscoBot/98293701175955456-calendar.db index c1c315c..79be177 100644 Binary files a/DiscoBot/98293701175955456-calendar.db and b/DiscoBot/98293701175955456-calendar.db differ diff --git a/DiscoBot/98293701175955456-gsmeet.db b/DiscoBot/98293701175955456-gsmeet.db index acdfba9..1c6b7fb 100644 Binary files a/DiscoBot/98293701175955456-gsmeet.db and b/DiscoBot/98293701175955456-gsmeet.db differ diff --git a/DiscoBot/98293701175955456-rss.db b/DiscoBot/98293701175955456-rss.db index 0c4a871..89307fb 100644 Binary files a/DiscoBot/98293701175955456-rss.db and b/DiscoBot/98293701175955456-rss.db differ diff --git a/DiscoBot/DisBot.cs b/DiscoBot/DisBot.cs index ea623ac..867c177 100644 --- a/DiscoBot/DisBot.cs +++ b/DiscoBot/DisBot.cs @@ -191,7 +191,7 @@ namespace DiscoBot if(commands.ContainsKey(command)) commands[command](message, splits); else - message.Channel.SendMessageAsync("Command not found!"); + Console.WriteLine("Command not found!"); }); } else { diff --git a/DiscoBot/IModule.cs b/DiscoBot/IModule.cs index 745f818..db55047 100644 --- a/DiscoBot/IModule.cs +++ b/DiscoBot/IModule.cs @@ -13,5 +13,22 @@ namespace DiscoBot string Name { get; set; } void Initialize(); Task OnNewWebSocketAsync(WebSocket ws, TaskCompletionSource tcs); + string ConcatParameters(string[] parameters) + { + string str = ""; + for (var i = 0; i < parameters.Length; ++i) + { + var s = parameters[i]; + if (str == "") + { + str += s; + } + else + { + str += " " + s; + } + } + return str; + } } } diff --git a/DiscoBot/bdaygreet/BDayGreet.cs b/DiscoBot/bdaygreet/BDayGreet.cs index 9697362..c303133 100644 --- a/DiscoBot/bdaygreet/BDayGreet.cs +++ b/DiscoBot/bdaygreet/BDayGreet.cs @@ -48,7 +48,13 @@ namespace DiscoBot.bdaygreet updateTimer.AutoReset = false; updateTimer.Elapsed += async (sender, e) => { - await Task.Run(() => HandleBDayCheck()); + try + { + await Task.Run(() => HandleBDayCheck()); + } catch(Exception) + { + Console.WriteLine("bday: EXCEPTION IN BDAY CHECK"); + } }; updateTimer.Start(); } @@ -117,20 +123,18 @@ namespace DiscoBot.bdaygreet var gchan = msg.Channel as IGuildChannel; string name = parameters[1]; string date = parameters[2]; - SocketGuildUser user; - try - { - user = guild.Users.Where(u => u.Mention == name).Single(); - } - catch (InvalidOperationException) + try { + var id = MentionUtils.ParseUser(name); + user = guild.Users.Where(u => u.Id == id).Single(); + } catch(Exception) { await msg.Channel.SendMessageAsync("I can't find user " + name + " so I can't add them."); return; } DateTimeOffset d; try { - d = DateTimeOffset.ParseExact(date,new string[] { "dd.MM.", "d.MM", "dd.M", "d.M." }, null, DateTimeStyles.AssumeUniversal); + d = DateTimeOffset.ParseExact(date,new string[] { "dd.MM.", "d.MM.", "dd.M", "d.M." }, null, DateTimeStyles.AssumeUniversal); } catch(FormatException) { await msg.Channel.SendMessageAsync("Sorry I can't parse your date. Please try again!"); return; @@ -203,7 +207,7 @@ namespace DiscoBot.bdaygreet return; } var gchan = msg.Channel as IGuildChannel; - string tag = parameters[1]; + string tag = ((IModule)this).ConcatParameters(parameters[1..]); try { var b = bdayGreetContext.BDays.Where(b => b.DiscordTag == tag).Single(); @@ -216,12 +220,14 @@ namespace DiscoBot.bdaygreet } } - private Task HandleBDayDebugCommand(SocketMessage msg, string[] parameters) + private async Task HandleBDayDebugCommand(SocketMessage msg, string[] parameters) { - Console.WriteLine("Handling test command!"); - string para = string.Join(",", parameters); - msg.Channel.SendMessageAsync("Test succeeded. Params: "+para); - return Task.CompletedTask; + await msg.Channel.SendMessageAsync("DEBUG!"); + string name = parameters[1]; + var id = MentionUtils.ParseUser(name); + var user = guild.Users.Where(u => u.Id == id).Single(); + await msg.Channel.SendMessageAsync("name: " + name); + await msg.Channel.SendMessageAsync("Found user with id" + user.Id+" and mention "+user.Mention+" Username: "+user.Username+" Discriminator: "+user.Discriminator+" DiscriminiatorValue: "+user.DiscriminatorValue); } public void Initialize() diff --git a/DiscoBot/gsmeet/GSMeet.cs b/DiscoBot/gsmeet/GSMeet.cs index fedbfba..2ab2100 100644 --- a/DiscoBot/gsmeet/GSMeet.cs +++ b/DiscoBot/gsmeet/GSMeet.cs @@ -32,7 +32,7 @@ namespace DiscoBot.gsmeet private static readonly string ApplicationName = "DiscoBot"; private SheetsService service; - private Dictionary meetingTimers = new Dictionary(); + private List lastMeetings = null; @@ -73,7 +73,13 @@ namespace DiscoBot.gsmeet timer.AutoReset = true; timer.Elapsed += async (sender, e) => { - await Task.Run(() => HandleSheetCheck(sheet)); + try + { + await Task.Run(() => HandleSheetCheck(sheet)); + } catch(Exception ex) + { + Console.WriteLine("gsmeet: EXCEPTION IN SHEET CHECK"+ex); + } }; timer.Start(); timers.Add(sheet.Db.Name, timer); @@ -133,6 +139,7 @@ namespace DiscoBot.gsmeet var binHash = sha1.ComputeHash(Encoding.ASCII.GetBytes(idString)); var hash = BitConverter.ToString(binHash).Replace("-", string.Empty); meeting.Id = hash; + meeting.FetchTime = DateTimeOffset.Now; return meeting; } @@ -167,6 +174,40 @@ namespace DiscoBot.gsmeet return meetings; } + private string MissingStringForEvent(GSMeeting m) + { + var now = DateTimeOffset.Now; + string s = ""; + for(var i=0;i now.AddDays(7)) + { + continue; + } + var us = ""; + foreach (var user in m.Users) + { + if (user.Signups[i] != "1" && user.Signups[i] != "0" && user.Signups[i] != "0.5") + { + if (user.User != null) + { + us = user.User.Mention + " "; + } + else + { + us += user.Name + " "; + } + } + } + if(us != "") + { + s += date + ": "+ us + "\n"; + } + } + return s; + } + private async Task HandleSheetCheck(GSSheet sheet) { SocketTextChannel c = guild.Channels.Where(g => g.Id == sheet.Db.Channel).Single() as SocketTextChannel; @@ -176,7 +217,33 @@ namespace DiscoBot.gsmeet { Console.WriteLine("No values found."); } - var meetings = await ParseGSMeetSheet(sheet, values); + lastMeetings = await ParseGSMeetSheet(sheet, values); + var ln = sheet.Db.LastNotified; + var now = DateTimeOffset.Now; + if(ln.AddDays(1) > now) + { + Console.WriteLine("It is: "+now+" Next notify is: " + ln.AddDays(1)); + return; + } + Console.WriteLine("Notifying..."); + string missStr = ""; + foreach(var meeting in lastMeetings) + { + missStr += MissingStringForEvent(meeting); + } + if(!string.IsNullOrEmpty(missStr)) + { + string msg = "Heyo! I found the following missing raid signups:\n"; + msg += missStr; + msg += "Please sign up so we can raid! :)"; + await c.SendMessageAsync(msg); + } + //TODO FIXME: Remove the hardcode 18 and read meeting timespan from sheet and use this value + var nextDate = now.AddHours(-now.Hour + 18).AddMinutes(-now.Minute).AddSeconds(-now.Second).AddMilliseconds(-now.Millisecond); + Console.WriteLine("Setting next notify to: " + nextDate); + sheet.Db.LastNotified = nextDate; + gsmeetContext.SaveChanges(); + /* foreach(var meeting in meetings) { if(!sheet.Timers.ContainsKey(meeting.Id)) @@ -187,17 +254,6 @@ namespace DiscoBot.gsmeet sheet.Timers[meeting.Id].UpdateTimers(c, meeting); } Console.WriteLine("Parsed sheet " + sheet.Db.Id); - /* - var str = ""; - foreach (var row in values) - { - foreach (var col in row) - { - str += col + "| "; - } - str += "\n"; - } - c.SendMessageAsync("Result: " + str); */ } @@ -216,6 +272,8 @@ namespace DiscoBot.gsmeet sheet.Id = sheetId; sheet.SheetName = sheetName; sheet.LastChecked = DateTimeOffset.Now; + var now = DateTimeOffset.Now; + sheet.LastNotified = now.AddDays(-1).AddHours(-now.Hour).AddMinutes(-now.Minute).AddSeconds(-now.Second).AddMilliseconds(-now.Millisecond); sheet.CheckInterval = new TimeSpan(0, 0, timeSec); gsmeetContext.GSheets.Add(sheet); try diff --git a/DiscoBot/gsmeet/GSMeetContext.cs b/DiscoBot/gsmeet/GSMeetContext.cs index bd723e9..d663a5c 100644 --- a/DiscoBot/gsmeet/GSMeetContext.cs +++ b/DiscoBot/gsmeet/GSMeetContext.cs @@ -35,6 +35,7 @@ namespace DiscoBot.gsmeet public ulong Channel { get; set; } public TimeSpan CheckInterval { get; set; } public DateTimeOffset LastChecked { get; set; } + public DateTimeOffset LastNotified { get; set; } } public class GSSheet @@ -42,10 +43,8 @@ namespace DiscoBot.gsmeet public GSSheet(DBSheet db) { this.Db = db; - this.Timers = new Dictionary(); } public DBSheet Db { get; set; } - public Dictionary Timers { get; set; } } public class GSMeetingUser @@ -68,6 +67,7 @@ namespace DiscoBot.gsmeet this.Dates = new List(); } public string Id { get; set; } + public DateTimeOffset FetchTime { get; set; } public List Users { get; set; } public List Dates { get; set; } } diff --git a/DiscoBot/rss/Rss.cs b/DiscoBot/rss/Rss.cs index 14811e3..d371a6c 100644 --- a/DiscoBot/rss/Rss.cs +++ b/DiscoBot/rss/Rss.cs @@ -45,7 +45,13 @@ namespace DiscoBot.rss timer.AutoReset = true; timer.Elapsed += async (sender, e) => { - await Task.Run(() => HandleFeedCheck(feed)); + try + { + await Task.Run(() => HandleFeedCheck(feed)); + } catch(Exception) + { + Console.WriteLine("rss: EXCEPTION IN FEED READ!"); + } }; timer.Start(); timers.Add(feed.Name, timer);