public override List<IRCResponse> GetResponse(BotMessage message) { if (!Regex.IsMatch(message.Command, @"^dateof$", RegexOptions.IgnoreCase)) return null; if (message.ParameterList.Count == 0) return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Date of what?", message.ReplyTo) }; List<Events.EventStruct> reversedList = null; Events.EventStruct eventStruct = new Events.EventStruct(); lock (Events.eventListLock) { reversedList = new List<Events.EventStruct>(Events.EventList); eventStruct = Events.EventList.Find(s => s.EventDate > DateTime.UtcNow && Regex.IsMatch(s.EventName, ".*" + message.Parameters + ".*", RegexOptions.IgnoreCase)); } reversedList.Reverse(); if (eventStruct.EventName == null) eventStruct = reversedList.Find(s => s.EventDate <= DateTime.UtcNow && Regex.IsMatch(s.EventName, ".*" + message.Parameters + ".*", RegexOptions.IgnoreCase)); if (eventStruct.EventName == null) return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "No event matching \"" + message.Parameters + "\" found in the events list.", message.ReplyTo) }; return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "The date for \"" + eventStruct.EventName + "\" is " + eventStruct.EventDate.ToString(@"yyyy-MM-dd \a\t HH:mm (UTC)"), message.ReplyTo) }; }
public override List<IRCResponse> GetResponse(BotMessage message) { if (!Regex.IsMatch(message.Command, "^event$", RegexOptions.IgnoreCase)) return null; if (message.ParameterList.Count <= 1) { if (message.ParameterList.Count > 0) return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't give an event!", message.ReplyTo) }; else return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't give a date and event!", message.ReplyTo) }; } Events.EventStruct eventStruct = new Events.EventStruct(); bool parseSuccess = false; if (message.ParameterList[0].StartsWith("(")) { Match dateMessage = Regex.Match(message.Parameters, @"^\((.+)\) (.+)"); if (dateMessage.Success) { DateTimeOffset dateTimeOffset; parseSuccess = DateTimeOffset.TryParse(dateMessage.Groups[1].Value, new CultureInfo("en-GB"), DateTimeStyles.AssumeUniversal, out dateTimeOffset); eventStruct.EventDate = dateTimeOffset.UtcDateTime; eventStruct.EventName = dateMessage.Groups[2].Value; } } else { DateTimeOffset dateTimeOffset; parseSuccess = DateTimeOffset.TryParse(message.ParameterList[0], new CultureInfo("en-GB"), DateTimeStyles.AssumeUniversal, out dateTimeOffset); eventStruct.EventDate = dateTimeOffset.UtcDateTime; eventStruct.EventName = message.Parameters.Remove(0, message.ParameterList[0].Length + 1); } if (!parseSuccess) return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Parsing of date: " + message.ParameterList[0] + " failed, expected format is (yyyy-MM-dd HH:mm +/-offset)", message.ReplyTo) }; eventStruct.EventName = StringUtils.StripIRCFormatChars(eventStruct.EventName); lock (Events.eventListLock) { int index = Events.EventList.FindIndex(s => s.EventName == eventStruct.EventName); if (index >= 0) return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Event \"" + eventStruct.EventName + "\" is already in the event list, on " + Events.EventList[index].EventDate.ToString(@"yyyy-MM-dd \a\t HH:mm (UTC)"), message.ReplyTo) }; Events.EventList.Add(eventStruct); Events.EventList.Sort(Events.EventStruct.CompareEventStructsByDate); } Events.SaveEvents(); return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Added event \"" + eventStruct.EventName + "\" on " + eventStruct.EventDate.ToString(@"yyyy-MM-dd \a\t HH:mm (UTC)"), message.ReplyTo) }; }
public override List <IRCResponse> GetResponse(BotMessage message) { if (!Regex.IsMatch(message.Command, @"^dateof$", RegexOptions.IgnoreCase)) { return(null); } if (message.ParameterList.Count == 0) { return new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "Date of what?", message.ReplyTo) } } ; List <Events.EventStruct> reversedList = null; Events.EventStruct eventStruct = new Events.EventStruct(); lock (Events.eventListLock) { reversedList = new List <Events.EventStruct>(Events.EventList); eventStruct = Events.EventList.Find(s => s.EventDate > DateTime.UtcNow && Regex.IsMatch(s.EventName, ".*" + message.Parameters + ".*", RegexOptions.IgnoreCase)); } reversedList.Reverse(); if (eventStruct.EventName == null) { eventStruct = reversedList.Find(s => s.EventDate <= DateTime.UtcNow && Regex.IsMatch(s.EventName, ".*" + message.Parameters + ".*", RegexOptions.IgnoreCase)); } if (eventStruct.EventName == null) { return new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "No event matching \"" + message.Parameters + "\" found in the events list.", message.ReplyTo) } } ; return(new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "The date for \"" + eventStruct.EventName + "\" is " + eventStruct.EventDate.ToString(@"yyyy-MM-dd \a\t HH:mm (UTC)"), message.ReplyTo) }); } } }
public override List <IRCResponse> GetResponse(BotMessage message) { if ((DateTime.UtcNow - _lastDate).Minutes < 5) { return(null); } lock (Events.eventListLock) { for (int i = 0; i < Events.EventList.Count; i++) { Events.EventStruct autoEvent = Events.EventList[i]; if (autoEvent.EventDate <= _lastDate || autoEvent.EventDate >= DateTime.UtcNow) { continue; } List <IRCResponse> responses = new List <IRCResponse>(); Events.EventStruct lastEvent = autoEvent; while (autoEvent.EventDate < DateTime.UtcNow) { responses.Add(new IRCResponse(ResponseType.Say, "It's time for \"" + autoEvent.EventName + "\"!", message.ReplyTo)); lastEvent = autoEvent; autoEvent = Events.EventList[++i]; } _lastDate = lastEvent.EventDate; if (responses.Count > 1) { return(responses); } break; } } return(null); }
public override List <IRCResponse> GetResponse(BotMessage message) { if (!Regex.IsMatch(message.Command, "^event$", RegexOptions.IgnoreCase)) { return(null); } if (message.ParameterList.Count <= 1) { if (message.ParameterList.Count > 0) { return new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't give an event!", message.ReplyTo) } } ; else { return new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't give a date and event!", message.ReplyTo) } }; } Events.EventStruct eventStruct = new Events.EventStruct(); bool parseSuccess = false; if (message.ParameterList[0].StartsWith("(")) { Match dateMessage = Regex.Match(message.Parameters, @"^\((.+)\) (.+)"); if (dateMessage.Success) { DateTimeOffset dateTimeOffset; parseSuccess = DateTimeOffset.TryParse(dateMessage.Groups[1].Value, new CultureInfo("en-GB"), DateTimeStyles.AssumeUniversal, out dateTimeOffset); eventStruct.EventDate = dateTimeOffset.UtcDateTime; eventStruct.EventName = dateMessage.Groups[2].Value; } } else { DateTimeOffset dateTimeOffset; parseSuccess = DateTimeOffset.TryParse(message.ParameterList[0], new CultureInfo("en-GB"), DateTimeStyles.AssumeUniversal, out dateTimeOffset); eventStruct.EventDate = dateTimeOffset.UtcDateTime; eventStruct.EventName = message.Parameters.Remove(0, message.ParameterList[0].Length + 1); } if (!parseSuccess) { return new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "Parsing of date: " + message.ParameterList[0] + " failed, expected format is (yyyy-MM-dd HH:mm +/-offset)", message.ReplyTo) } } ; eventStruct.EventName = StringUtils.StripIRCFormatChars(eventStruct.EventName); lock (Events.eventListLock) { int index = Events.EventList.FindIndex(s => s.EventName == eventStruct.EventName); if (index >= 0) { return new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "Event \"" + eventStruct.EventName + "\" is already in the event list, on " + Events.EventList[index].EventDate.ToString(@"yyyy-MM-dd \a\t HH:mm (UTC)"), message.ReplyTo) } } ; Events.EventList.Add(eventStruct); Events.EventList.Sort(Events.EventStruct.CompareEventStructsByDate); } Events.SaveEvents(); return(new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "Added event \"" + eventStruct.EventName + "\" on " + eventStruct.EventDate.ToString(@"yyyy-MM-dd \a\t HH:mm (UTC)"), message.ReplyTo) }); } } }