private async Task <ResponseMessage> CreateSchedule(IncomingMessage message, string command, string cronSchedule)
        {
            var schedule = new ScheduleEntry
            {
                Guid         = Guid.NewGuid(),
                Channel      = message.Channel,
                ChannelType  = message.ChannelType,
                Command      = command,
                CronSchedule = cronSchedule,
                UserId       = message.UserId,
                UserName     = message.Username,
                Created      = DateTime.Now
            };

            if (!CronExpression.IsValidExpression(cronSchedule))
            {
                return(await Task.FromResult(message.ReplyToChannel($"Unknown cron schedule `'{cronSchedule}'`")));
            }

            if (string.IsNullOrEmpty(schedule.Command))
            {
                return(message.ReplyToChannel("Please enter a command to be scheduled."));
            }

            _schedulePlugin.AddSchedule(schedule);
            return(message.ReplyToChannel($"Schedule created for command '{schedule.Command}'."));
        }
Example #2
0
        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));
        }
Example #3
0
        private ResponseMessage CreateSchedule(IncomingMessage message, string matchedHandle, TimeSpan timeSpan, bool runOnlyAtNight)
        {
            var schedule = new SchedulePlugin.ScheduleEntry
            {
                Channel        = message.Channel,
                ChannelType    = message.ChannelType,
                Command        = message.TargetedText.Substring(matchedHandle.Length).Trim(),
                RunEvery       = timeSpan,
                UserId         = message.UserId,
                UserName       = message.Username,
                LastRun        = DateTime.Now,
                RunOnlyAtNight = runOnlyAtNight
            };

            if (string.IsNullOrEmpty(schedule.Command))
            {
                return(message.ReplyToChannel("Please enter a command to be scheduled."));
            }
            else
            {
                _schedulePlugin.AddSchedule(schedule);
                return(message.ReplyToChannel($"Schedule created for command '{schedule.Command}'."));
            }
        }