void ManageChannels(object o) { Attempts.Where(c => DateTime.UtcNow.Subtract(c.Timestamp).TotalHours >= 1).ToList().ForEach((item) => Attempts.Remove(item)); // Get Open Channels var channels = API.GetOpenChatRooms().ToList(); if (channels.Count == 0) { return; } // Get Open Connections on WinMX.exe var connections = NetworkInfo.GetActiveConnections(ProcessInfo.GetWinMXProcessID()).ToList(); channels.ForEach((room) => { if (!connections.Contains(HashCode.HashToEndPoint(room))) { if (!ExcludedChannels.Contains(room)) { if (MaximumAttempts == -1 || Attempts.Count(c => c.Channel == room) < MaximumAttempts) { API.JoinChatRoom(room); Attempts.Add(new JoinAttempt() { Channel = room, Timestamp = DateTime.UtcNow }); } } } }); }
void ManageAutoRejoinMessages(object o) { // If auto rejoin message is turned on and the message is not null or empty. if (SendAutoRejoinMessage && AutoRejoinMessage?.Length > 0) { // Get most attempts (most recent per channel) in the last minute. var attempts = Attempts.Where(c => DateTime.UtcNow.Subtract(c.Timestamp).TotalMinutes < 1).OrderByDescending(c => c.Timestamp).GroupBy(d => d.Channel).Select(e => e.First()).ToList(); // Get active connections var connections = NetworkInfo.GetActiveConnections(ProcessInfo.GetWinMXProcessID()).ToList(); attempts.ForEach((item) => { if (!item.SentMessage && connections.Contains(HashCode.HashToEndPoint(item.Channel))) { API.SendTextToChatRoom(item.Channel, AutoRejoinMessage); item.SentMessage = true; } }); } }