Ejemplo n.º 1
0
        public void Execute(IJobExecutionContext context)
        {
            Guid guid     = Guid.Parse(context.JobDetail.JobDataMap["guid"].ToString());
            var  schedule = _schedulePlugin.ListAllSchedules().First(x => x.Guid == guid);

            _statsPlugin.IncrementState("schedules:run");
            _log.Info($"Running schedule: {schedule}");

            SlackChatHubType channelType = schedule.ChannelType == ResponseType.Channel
                ? SlackChatHubType.Channel
                : SlackChatHubType.DM;

            var slackMessage = new SlackMessage
            {
                Text = schedule.Command,
                User = new SlackUser {
                    Id = schedule.UserId, Name = schedule.UserName
                },
                ChatHub = new SlackChatHub {
                    Id = schedule.Channel, Type = channelType
                },
            };

            _noobotCore.MessageReceived(slackMessage);
            schedule.LastRun = DateTime.Now;
        }
Ejemplo n.º 2
0
        private async IAsyncEnumerable <ResponseMessage> SchedulesListHandler(IncomingMessage message, IValidHandle matchedHandle)
        {
            if (!_adminPlugin.AuthenticateUser(message.UserId))
            {
                yield return(await Task.FromResult(message.ReplyToChannel($"Sorry {message.Username}, only admins can use this function.")));

                yield break;
            }

            var schedules       = _schedulePlugin.ListAllSchedules();
            var scheduleStrings = schedules.Select(x => $"Guid: '{x.Guid}' Channel: '{x.Channel}'.").ToArray();

            yield return(message.ReplyToChannel("All Schedules:"));

            yield return(message.ReplyToChannel(">>>" + string.Join("\n", scheduleStrings)));
        }
Ejemplo n.º 3
0
        private IEnumerable <ResponseMessage> SchedulesListHandler(IncomingMessage message, string matchedHandle)
        {
            if (!_adminPlugin.AuthenticateUser(message.UserId))
            {
                yield return(message.ReplyToChannel($"Sorry {message.Username}, only admins can use this function."));

                yield break;
            }

            var schedules = _schedulePlugin.ListAllSchedules();

            string[] scheduleStrings = schedules.Select((x, i) => x.ToString(i) + $" Channel: '{x.Channel}'.").ToArray();

            yield return(message.ReplyToChannel("All Schedules:"));

            yield return(message.ReplyToChannel(">>>" + string.Join("\n", scheduleStrings)));
        }