コード例 #1
0
ファイル: Host.cs プロジェクト: ragazzon/slackbot
        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();
        }
コード例 #2
0
ファイル: AdminMiddleware.cs プロジェクト: thuijer/noobot
        private IEnumerable <ResponseMessage> ChannelsHandler(IncomingMessage message, string matchedHandle)
        {
            if (!_adminPlugin.AuthenticateUser(message.UserId))
            {
                yield return(message.ReplyToChannel($"Sorry {message.Username}, only admins can use this function."));

                yield break;
            }

            Dictionary <string, string> channels = _noobotCore.ListChannels();

            yield return(message.ReplyToChannel("All Connected Channels:"));

            yield return(message.ReplyToChannel(">>>" + string.Join("\n", channels.Select(x => $"{x.Key}: {x.Value}"))));
        }