public void should_do_a_thing() { // given SchedulePlugin schedulePlugin = _container.GetPlugin <SchedulePlugin>(); Guid guid = Guid.NewGuid(); const string cronSchedule = "*/20 * * * * ?"; // every 5 seconds // when schedulePlugin.AddSchedule(new ScheduleEntry { Guid = guid, CronSchedule = cronSchedule, Channel = _noobotCore.GetChannelId("#general"), ChannelType = ResponseType.Channel, Command = $"@{_noobotCore.GetBotUserName()} joke", UserId = _noobotCore.GetUserIdForUsername("simon"), UserName = "******" }); // then Thread.Sleep(TimeSpan.FromMinutes(1)); // when schedulePlugin.DeleteSchedule(guid); // then Thread.Sleep(TimeSpan.FromMinutes(1)); }
private IEnumerable <ResponseMessage> DeleteHandlerForChannel(IncomingMessage message, string matchedHandle) { string idString = message.TargetedText.Substring(matchedHandle.Length).Trim(); int?id = ConvertToInt(idString); if (id.HasValue) { SchedulePlugin.ScheduleEntry[] schedules = _schedulePlugin.ListSchedulesForChannel(message.Channel); if (id < 0 || id > (schedules.Length - 1)) { yield return(message.ReplyToChannel($"Woops, unable to delete schedule with id of `{id.Value}`")); } else { _schedulePlugin.DeleteSchedule(schedules[id.Value]); yield return(message.ReplyToChannel($"Removed schedule: {schedules[id.Value]}")); } } else { yield return(message.ReplyToChannel($"Invalid id entered. Try using `schedule list`. ({idString})")); } }
private IEnumerable <ResponseMessage> DeleteHandlerForChannel(IncomingMessage message, IValidHandle matchedHandle) { string idString = message.TargetedText.Substring(matchedHandle.HandleHelpText.Length).Trim(); Guid guid; if (Guid.TryParse(idString, out guid)) { ScheduleEntry[] schedules = _schedulePlugin.ListSchedulesForChannel(message.Channel); ScheduleEntry scheduleToDelete = schedules.FirstOrDefault(x => x.Guid == guid); if (scheduleToDelete == null) { yield return(message.ReplyToChannel($"Unable to find schedule with GUID: `'{guid}'`")); } else { _schedulePlugin.DeleteSchedule(guid); yield return(message.ReplyToChannel($"Removed schedule: `{scheduleToDelete}`")); } } else { yield return(message.ReplyToChannel($"Invalid id entered. Try using `schedule list`. (`{idString}`)")); } }