private void Server_Message_Log_Check(object sender, ElapsedEventArgs e) { var guilds = ServerMessageLogs.GetAllLogs(); int i = 0; int i2 = 0; foreach (var guild in guilds) { i2++; if (guild.ID > 0) { ServerMessageLog srvrLog = ServerMessageLogs.GetLog(guild.ID); var twoWeeks = DateTime.Now - TimeSpan.FromDays(14); for (int j = srvrLog.LastThousandMessages.Count() - 1; j >= 0; j--) //Reverse for loop to remove items from list { var line = srvrLog.LastThousandMessages.ElementAt(j); if (line.Contains(twoWeeks.ToShortDateString())) { srvrLog.LastThousandMessages.Remove(line); i++; } } } } ServerMessageLogs.SaveServerLogging(); logger.ConsoleTimerElapsed($"Removed {i} lines across {i2} server message logs."); }
public Task MessageCache(SocketMessage s) //Called whenever a message is sent in a guild. Adds the message to a list. { if (s != null) { var msg = s as SocketUserMessage; Config.bot.LastSeenMessage = DateTime.Now; if (msg != null && !msg.Author.IsBot) { if (msg.Channel is SocketTextChannel) { var guild = (msg.Author as SocketGuildUser).Guild; if (guild != null) { ServerMessageLog currentLog = ServerMessageLogs.GetLog(guild); currentLog.AddMessage(msg); ServerMessageLogs.SaveServerLogging(); return(Task.CompletedTask); } else { logger.ConsoleCriticalAdvisory($"Failed to cache message for {guild.Name} with ID: {guild.Id}! [REMOVING!!!] Thrown from KaguyaLogMethods.cs line 139!"); ServerMessageLogs.RemoveLog(guild.Id); return(Task.CompletedTask); } } } } return(Task.CompletedTask); }