Exemplo n.º 1
0
        public AdminMiddleware(IMiddleware next, AdminPlugin adminPlugin, SchedulePlugin schedulePlugin, ISlackWrapper slackWrapper) : base(next)
        {
            _adminPlugin    = adminPlugin;
            _schedulePlugin = schedulePlugin;
            _slackWrapper   = slackWrapper;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles  = new [] { "admin pin" },
                    EvaluatorFunc = PinHandler
                },
                new HandlerMapping
                {
                    ValidHandles  = new [] { "admin schedules list" },
                    EvaluatorFunc = SchedulesListHandler
                },
                new HandlerMapping
                {
                    ValidHandles  = new [] { "admin schedules delete" },
                    EvaluatorFunc = DeleteSchedulesHandler
                },
                new HandlerMapping
                {
                    ValidHandles  = new [] { "admin channels" },
                    EvaluatorFunc = ChannelsHandler
                }
            };
        }
Exemplo n.º 2
0
 public ScheduledJob(SchedulePlugin schedulePlugin, INoobotCore noobotCore, ILog logger, StatsPlugin statsPlugin)
 {
     _schedulePlugin = schedulePlugin;
     _noobotCore     = noobotCore;
     _log            = logger;
     _statsPlugin    = statsPlugin;
 }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
 public ScheduledJob(SchedulePlugin schedulePlugin, INoobotCore noobotCore, ILog logger, StatsPlugin statsPlugin)
 {
     _schedulePlugin = schedulePlugin;
     _noobotCore = noobotCore;
     _log = logger;
     _statsPlugin = statsPlugin;
 }
Exemplo n.º 5
0
        public AdminMiddleware(
            IMiddleware next,
            AdminPlugin adminPlugin,
            SchedulePlugin schedulePlugin,
            INoobotCore noobotCore,
            ILogger log) : base(next)
        {
            _adminPlugin    = adminPlugin;
            _schedulePlugin = schedulePlugin;
            _noobotCore     = noobotCore;
            _log            = log;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("admin pin"),
                    EvaluatorFunc = PinHandler,
                    Description   = "This function is used to authenticate a user as admin",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("admin schedules list"),
                    EvaluatorFunc = SchedulesListHandler,
                    Description   = "[Requires authentication] Will return a list of all schedules.",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("admin schedules delete"),
                    EvaluatorFunc = DeleteSchedulesHandler,
                    Description   = "[Requires authentication] This will delete all schedules.",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("admin channels"),
                    EvaluatorFunc = ChannelsHandler,
                    Description   = "[Requires authentication] Will return all channels connected.",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("admin help", "admin list"),
                    EvaluatorFunc = AdminHelpHandler,
                    Description   = "[Requires authentication] Lists all available admin functions",
                    VisibleInHelp = false
                }
            };
        }
Exemplo n.º 6
0
        public ScheduleMiddleware(IMiddleware next, SchedulePlugin schedulePlugin) : base(next)
        {
            _schedulePlugin = schedulePlugin;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles  = StartsWithHandle.For("schedule hourly"),
                    Description   = "Schedule a command to execute every hour on the current channel. Usage: `@{bot} schedule hourly @{bot} tell me a joke`",
                    EvaluatorFunc = HourlyHandler,
                },
                new HandlerMapping
                {
                    ValidHandles  = StartsWithHandle.For("schedule daily"),
                    Description   = "Schedule a command to execute every day on the current channel. Usage: `@{bot} schedule daily @{bot} tell me a joke`",
                    EvaluatorFunc = DayHandler,
                },
                new HandlerMapping
                {
                    ValidHandles  = StartsWithHandle.For("schedule cronjob"),
                    Description   = "Schedule a cron job for this channel. Usage: `@{bot} schedule cronjob '0 15 10 * * ?' @{bot} tell me a joke`",
                    EvaluatorFunc = CronHandler,
                },
                new HandlerMapping
                {
                    ValidHandles  = ExactMatchHandle.For("schedule list"),
                    Description   = "List all schedules on the current channel",
                    EvaluatorFunc = ListHandlerForChannel,
                },
                new HandlerMapping
                {
                    ValidHandles  = StartsWithHandle.For("schedule delete"),
                    Description   = "Delete a schedule in this channel. You must enter a valid {guid}",
                    EvaluatorFunc = DeleteHandlerForChannel,
                },
            };
        }
Exemplo n.º 7
0
        public ScheduleMiddleware(IMiddleware next, SchedulePlugin schedulePlugin) : base(next)
        {
            _schedulePlugin = schedulePlugin;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles  = new [] { "schedule hourly" },
                    Description   = "Schedule a command to execute every hour on the current channel. Usage: _schedule hourly @{bot} tell me a joke_",
                    EvaluatorFunc = HourlyHandler,
                },
                new HandlerMapping
                {
                    ValidHandles  = new [] { "schedule daily" },
                    Description   = "Schedule a command to execute every day on the current channel. Usage: _schedule daily @{bot} tell me a joke_",
                    EvaluatorFunc = DayHandler,
                },
                new HandlerMapping
                {
                    ValidHandles  = new [] { "schedule nightly" },
                    Description   = "Schedule a command to execute every day on the current channel. Usage: _schedule nightly @{bot} tell me a joke_",
                    EvaluatorFunc = NightlyHandler,
                },
                new HandlerMapping
                {
                    ValidHandles  = new [] { "schedule list" },
                    Description   = "List all schedules on the current channel",
                    EvaluatorFunc = ListHandlerForChannel,
                },
                new HandlerMapping
                {
                    ValidHandles  = new [] { "schedule delete" },
                    Description   = "Delete a schedule in this channel. You must enter a valid {id}",
                    EvaluatorFunc = DeleteHandlerForChannel,
                },
            };
        }