Example #1
0
 public ScheduledJob(SchedulePlugin schedulePlugin, INoobotCore noobotCore, ILog logger, StatsPlugin statsPlugin)
 {
     _schedulePlugin = schedulePlugin;
     _noobotCore = noobotCore;
     _log = logger;
     _statsPlugin = statsPlugin;
 }
Example #2
0
 public SchedulePlugin(StoragePlugin storagePlugin, INoobotCore noobotCore, StatsPlugin statsPlugin, ILog log)
 {
     _storagePlugin = storagePlugin;
     _noobotCore = noobotCore;
     _statsPlugin = statsPlugin;
     _log = log;
 }
Example #3
0
 public SchedulePlugin(StoragePlugin storagePlugin, INoobotCore noobotCore, StatsPlugin statsPlugin, ILog log)
 {
     _storagePlugin = storagePlugin;
     _noobotCore    = noobotCore;
     _statsPlugin   = statsPlugin;
     _log           = log;
 }
Example #4
0
 public ScheduledJob(SchedulePlugin schedulePlugin, INoobotCore noobotCore, ILog logger, StatsPlugin statsPlugin)
 {
     _schedulePlugin = schedulePlugin;
     _noobotCore     = noobotCore;
     _log            = logger;
     _statsPlugin    = statsPlugin;
 }
Example #5
0
        public void Start()
        {
            IContainerFactory containerFactory = new ContainerFactory(_configuration, _configReader, LogManager.GetLogger(GetType()));
            INoobotContainer  container        = containerFactory.CreateContainer();

            _noobotCore = container.GetNoobotCore();

            Console.WriteLine("Connecting...");
            _noobotCore
            .Connect()
            .ContinueWith(task =>
            {
                if (!task.IsCompleted || task.IsFaulted)
                {
                    Console.WriteLine($"Error connecting to Slack: {task.Exception}");
                }

                Settings.ChannelList = _noobotCore.ListChannels();

                var lastRun = DateTime.UtcNow;
                while (true)
                {
                    if (lastRun.AddSeconds(1) <= DateTime.UtcNow)
                    {
                        var check = new MunkCheck();
                        check.CheckForEvents(_noobotCore);

                        lastRun = DateTime.UtcNow;
                    }
                }
            })
            .Wait();
        }
Example #6
0
        public void Setup()
        {
            var containerFactory = new ContainerFactory(new ToolboxConfiguration(), new ConfigReader(), NoobotWrapper.GetLogger());
            _container = containerFactory.CreateContainer();

            _noobotCore = _container.GetNoobotCore();
            _noobotCore.Connect().Wait(TimeSpan.FromMinutes(1));
        }
        public void Setup()
        {
            var containerFactory = new ContainerFactory(new ToolboxConfiguration(), new JsonConfigReader(), NoobotWrapper.GetLogger());

            _container = containerFactory.CreateContainer();

            _noobotCore = _container.GetNoobotCore();
            _noobotCore.Connect().Wait(TimeSpan.FromMinutes(1));
        }
        public void Setup()
        {
            File.Delete(Path.Combine(Environment.CurrentDirectory, "data/schedules.json"));

            var containerFactory = new ContainerFactory(new SchedulerConfig(), new ConfigReader(), NoobotWrapper.GetLogger());
            _container = containerFactory.CreateContainer();

            _noobotCore = _container.GetNoobotCore();
            _noobotCore.Connect().Wait(TimeSpan.FromMinutes(1));
        }
Example #9
0
        public void Setup()
        {
            File.Delete(Path.Combine(Environment.CurrentDirectory, "data/schedules.json"));

            var containerFactory = new ContainerFactory(new SchedulerConfig(), new ConfigReader(), NoobotWrapper.GetLogger());

            _container = containerFactory.CreateContainer();

            _noobotCore = _container.GetNoobotCore();
            _noobotCore.Connect().Wait(TimeSpan.FromMinutes(1));
        }
Example #10
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            IContainerFactory containerFactory = new ContainerFactory(_botConfiguration,
                                                                      _configReader, LogManager.GetLogger(GetType()));
            INoobotContainer container = containerFactory.CreateContainer();

            _noobotCore = container.GetNoobotCore();

            _logger.LogInformation("Connecting..");
            await _noobotCore.Connect();
        }
Example #11
0
        private static async Task RunBot()
        {
            var environmentReader = new EnvironmentReader();
            var botConfiguration  = new BotConfiguration(environmentReader);

            var containerFactory = new ContainerFactory(botConfiguration, environmentReader, GetLogger());
            var container        = containerFactory.CreateContainer();

            _noobotCore = container.GetNoobotCore();

            await _noobotCore.Connect();
        }
Example #12
0
        public async void CheckForEvents(INoobotCore _core)
        {
            var request       = Slackbot.Client.GetAsync($"?p={Settings.SitePass}&u=bot&c=ping").Result;
            var response      = request.Content.ReadAsStringAsync().Result.Clean();
            var splitResponse = response.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var text in splitResponse)
            {
                var message = ConstructMessage(_core, text);
                await _core.SendMessage(message).ContinueWith(task => { });
            }
        }
Example #13
0
        private static async Task RunNoobot()
        {
            var containerFactory = new ContainerFactory(
                new MiddlewareConfiguration(),
                new JsonConfigReader(_noobotConfigFilePath),
                GetLogger());

            INoobotContainer container = containerFactory.CreateContainer();

            _noobotCore = container.GetNoobotCore();

            await _noobotCore.Connect();
        }
Example #14
0
        private static async Task RunNoobot()
        {
            var containerFactory = new ContainerFactory(
                new ConfigurationBase(),
                JsonConfigReader.DefaultLocation(),
                GetLogger());

            INoobotContainer container = containerFactory.CreateContainer();

            _noobotCore = container.GetNoobotCore();

            await _noobotCore.Connect();
        }
        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
                }
            };
        }
Example #16
0
        public HelpMiddleware(IMiddleware next, INoobotCore noobotCore) : base(next)
        {
            _noobotCore = noobotCore;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles = new[] {"help", "yo tell me more"},
                    Description = "Returns supported commands and descriptions of how to use them",
                    EvaluatorFunc = HelpHandler
                }
            };
        }
Example #17
0
        public HelpMiddleware(IMiddleware next, INoobotCore noobotCore) : base(next)
        {
            _noobotCore = noobotCore;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles  = new[] { "help", "yo tell me more" },
                    Description   = "Returns supported commands and descriptions of how to use them",
                    EvaluatorFunc = HelpHandler
                }
            };
        }
Example #18
0
        public void Start()
        {
            IContainerFactory containerFactory = new ContainerFactory(_configuration, _configReader, new ConsoleLog());
            INoobotContainer container = containerFactory.CreateContainer();
            _noobotCore = container.GetNoobotCore();

            Console.WriteLine("Connecting...");
            _noobotCore
                .Connect()
                .ContinueWith(task =>
                {
                    if (!task.IsCompleted || task.IsFaulted)
                    {
                        Console.WriteLine($"Error connecting to Slack: {task.Exception}");
                    }
                });
        }
        public MultipleCommandsMiddleware(IMiddleware next, INoobotCore noobotCore) : base(next)
        {
            _noobotCore = noobotCore;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles = new IValidHandle[]
                    {
                        new StartsWithHandle("test")
                    },
                    Description   = "Returns supported commands and descriptions of how to use them",
                    EvaluatorFunc = MultipleCommandsHandler
                }
            };
        }
Example #20
0
        public AdminMiddleware(IMiddleware next, AdminPlugin adminPlugin, SchedulePlugin schedulePlugin, INoobotCore noobotCore, ILog log) : base(next)
        {
            _adminPlugin = adminPlugin;
            _schedulePlugin = schedulePlugin;
            _noobotCore = noobotCore;
            _log = log;

            HandlerMappings = new[]
            {
                new HandlerMapping
                {
                    ValidHandles = new []{ "admin pin" },
                    EvaluatorFunc = PinHandler,
                    Description = "This function is used to authenticate a user as admin",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles = new []{ "admin schedules list" },
                    EvaluatorFunc = SchedulesListHandler,
                    Description = "[Requires authentication] Will return a list of all schedules.",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles = new []{ "admin schedules delete" },
                    EvaluatorFunc = DeleteSchedulesHandler,
                    Description = "[Requires authentication] This will delete all schedules.",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles = new []{ "admin channels" },
                    EvaluatorFunc = ChannelsHandler,
                    Description = "[Requires authentication] Will return all channels connected.",
                    VisibleInHelp = false
                },
                new HandlerMapping
                {
                    ValidHandles = new []{"admin help", "admin list"},
                    EvaluatorFunc = AdminHelpHandler,
                    Description = "[Requires authentication] Lists all available admin functions",
                    VisibleInHelp = false
                }
            };
        }
Example #21
0
        public INoobotHost Start()
        {
            INoobotContainer container = _containerFactory.CreateContainer();
            _noobotCore = container.GetNoobotCore();

            Console.WriteLine("Connecting...");
            _noobotCore
                .Connect()
                .ContinueWith(task =>
                {
                    if (!task.IsCompleted || task.IsFaulted)
                    {
                        Console.WriteLine($"Error connecting to Slack: {task.Exception}");
                    }
                });

            return this;
        }
Example #22
0
        public void Start()
        {
            IContainerFactory containerFactory = new ContainerFactory(_configuration, _configReader, new ConsoleLog());
            INoobotContainer  container        = containerFactory.CreateContainer();

            _noobotCore = container.GetNoobotCore();

            Console.WriteLine("Connecting...");
            _noobotCore
            .Connect()
            .ContinueWith(task =>
            {
                if (!task.IsCompleted || task.IsFaulted)
                {
                    Console.WriteLine($"Error connecting to Slack: {task.Exception}");
                }
            });
        }
Example #23
0
        public void Start(ILog log)
        {
            IContainerFactory containerFactory = new ContainerFactory(_configuration, _configReader, log);
            INoobotContainer  container        = containerFactory.CreateContainer();

            _noobotCore = container.GetNoobotCore();

            _noobotCore
            .Connect()
            .ContinueWith(task =>
            {
                if (!task.IsCompleted || task.IsFaulted)
                {
                    Debug.WriteLine($"Error connecting to Slack: {task.Exception}");
                }
            })
            .GetAwaiter()
            .GetResult();
        }
Example #24
0
        public INoobotHost Start()
        {
            INoobotContainer container = _containerFactory.CreateContainer();

            _noobotCore = container.GetNoobotCore();

            Console.WriteLine("Connecting...");
            _noobotCore
            .Connect()
            .ContinueWith(task =>
            {
                if (!task.IsCompleted || task.IsFaulted)
                {
                    Console.WriteLine($"Error connecting to Slack: {task.Exception}");
                }
            });

            return(this);
        }
Example #25
0
        public ResponseMessage ConstructMessage(INoobotCore _core, string textToSend)
        {
            var toCustomChannel = textToSend.Contains("#PM#");

            if (!toCustomChannel)
            {
                return(new ResponseMessage()
                {
                    ResponseType = ResponseType.Channel,
                    Text = textToSend,
                    Channel = Settings.ChannelList.FirstOrDefault(e => e.Value == Settings.DefaultChannel).Key,
                });
            }

            textToSend = textToSend.Replace("#PM#", "");
            var index  = textToSend.IndexOf("%&%");
            var target = textToSend.Substring(0, index);

            textToSend = textToSend.Replace("%&%", "").Replace(target, "");

            var message = new ResponseMessage()
            {
                ResponseType = ResponseType.Channel,
                Text         = textToSend
            };

            var channelId = Settings.ChannelList.FirstOrDefault(e => e.Value == target).Key;

            if (channelId == null)
            {
                var userId = _core.GetUserIdForUsername(target);
                message.UserId       = userId;
                message.ResponseType = ResponseType.DirectMessage;
            }
            else
            {
                message.Channel = channelId;
            }
            return(message);
        }
Example #26
0
 public LearnPlugin(INoobotCore noobotCore, StoragePlugin storagePlugin)
 {
     _noobotCore    = noobotCore;
     _storagePlugin = storagePlugin;
 }
 public PingPlugin(INoobotCore noobotCore, JsonStoragePlugin storagePlugin)
 {
     _noobotCore    = noobotCore;
     _storagePlugin = storagePlugin;
 }
Example #28
0
 public PingPlugin(INoobotCore noobotCore, JsonStoragePlugin storagePlugin)
 {
     _noobotCore = noobotCore;
     _storagePlugin = storagePlugin;
 }
Example #29
0
 public NoobotHealthCheck(INoobotCore noobot)
     : base("Noobot Health")
 {
     _noobot = noobot ?? throw new ArgumentNullException(nameof(noobot));
 }
Example #30
0
 public NoobotHost(INoobotCore noobotCore)
 {
     _noobotCore = noobotCore;
 }
Example #31
0
 public OldbotHostedService(INoobotCore noobotCore)
 {
     _noobotCore = noobotCore;
 }