private async Task SendEventReminderMessage(HexEvent hexEvent, TimeSpan span, bool newEventReminderMessage) { if (newEventReminderMessage) { foreach (KeyValuePair <ulong, ServerSettings> keyValuePair in SettingsManager.settingsDictionary) { if (keyValuePair.Value.EventReminderChannelId != null) { hexEvent.EventMessages.Add(await((SocketTextChannel)discordClient.GetChannel(keyValuePair.Value.EventReminderChannelId.Value)).SendMessageAsync(string.Empty, false, CreateEventReminderEmbed(hexEvent.EventName, span))); } } } else { foreach (RestUserMessage message in hexEvent.EventMessages) { await message.ModifyAsync(msg => msg.Embed = CreateEventReminderEmbed(hexEvent.EventName, span)); } } }
// gets all events from one specific day in the hex calender private void GetEventInfo(DateTime dateTime) { string htmlSource; using (WebClient client = new WebClient()) { htmlSource = client.DownloadString(GetHexCalenderUrl(dateTime)); } List <HexEvent> events = new List <HexEvent>(); string pattern = "box48"; string timeStartPattern = "\"\\s*badge\\s*\"\\s*>\\s*"; string dataPattern = "[^<]*"; string nameStartPattern = "class\\s*=\\s*\"\\s*calendarEventLink\\s*\"\\s*[^>]*>"; string datePattern = "(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d*(st|nd|rd|th) \\d*"; // Fri, May 4th 2018, 11:00am - 2:00pm int lastMatchEnd = 0; Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase); Regex timeStartRgx = new Regex(timeStartPattern, RegexOptions.IgnoreCase); Regex dataRgx = new Regex(dataPattern, RegexOptions.IgnoreCase); Regex nameStartRgx = new Regex(nameStartPattern, RegexOptions.IgnoreCase); Regex dateRgx = new Regex(datePattern, RegexOptions.IgnoreCase); Match match; List <HexEvent> tempEvents; do { match = rgx.Match(htmlSource, lastMatchEnd); if (match.Success) { lastMatchEnd = match.Index + match.Length; Match timeStartMatch = timeStartRgx.Match(htmlSource, match.Index); if (timeStartMatch.Success) { Match timeMatch = dataRgx.Match(htmlSource, timeStartMatch.Index + timeStartMatch.Length); if (timeMatch.Success) { Match nameStartMatch = nameStartRgx.Match(htmlSource, timeMatch.Index + timeMatch.Length); if (nameStartMatch.Success) { Match nameMatch = dataRgx.Match(htmlSource, nameStartMatch.Index + nameStartMatch.Length); if (nameMatch.Success) { Match dateMatch = dateRgx.Match(htmlSource, nameMatch.Index + nameMatch.Length); if (dateMatch.Success) { tempEvents = null; try { tempEvents = HexEvent.ParseEventStrings(dateMatch.Value, nameMatch.Value, timeMatch.Value); //System.Console.WriteLine(string.Format("{0}: {1}, {2}", nameMatch.Value, dateMatch.Value, timeMatch.Value)); } catch (Exception) { } if (tempEvents != null) { events.AddRange(tempEvents); } } } } } } } } while (match.Success); foreach (HexEvent hexEvent in events) { if (hexEvent.EventDateTime.DayOfYear == dateTime.DayOfYear) { if (!eventList.Contains(hexEvent)) { eventList.Add(hexEvent); } } } }