Esempio n. 1
0
        public async Task Start()
        {
            await _storage.Start();

            var state = _storage.ReadObject <PizzaBotState>(STATEFILENAME) ?? new PizzaBotState();

            if (state.OptOutFeatureAnnounced == null)
            {
                _activity.Log("Tried to announce opt out feature, but announcement is disabled");
                return;

                //var channels = new[] { _config.BotRoom, _config.PizzaRoom.Room };
                //foreach (var channel in channels)
                //{
                //    var message = new MessageToSend()
                //    {
                //        ChannelName = channel,
                //        Text = "Apparenly not everyone loves pizza as much as me. It appears not everyone here actually has the time or the ability to meet up for pizza with great friends.\n" +
                //        "That is a great shame, but if that is you then I have just the thing. Starting now I have the ability to remember those that don't want to, or can't make it to our fabulous pizza dates. \n" +
                //        "Try messaging me with the command `opt out` and I'll get you sorted and you won't have to be bothered by me again.\n" +
                //        $"For everyone else: *more pizza for us!*\n" +
                //        $"And if you have complaints or comments, I'm hanging out in #{_config.BotRoom}, so feel free to join me there."
                //    };
                //    await _core.SendMessage(message);
                //    _activity.Log($"Announced feature:OptOut! in {channel}");
                //}
                //state.OptOutFeatureAnnounced = DateTimeOffset.UtcNow;

                //_storage.SaveObject(STATEFILENAME, state);
            }
        }
Esempio n. 2
0
        public async Task Start()
        {
            try
            {
                await _pizzaCore.Start();

                if (!_pizzaCore.IsConnected)
                {
                    throw new OperationCanceledException("Could not connect to slack.");
                }
                var startTasks = _resources.Select(r => r.Start());
                Task.WaitAll(startTasks.ToArray());

                _pizzaCore.AddMessageHandlerToPipeline(_handlers.ToArray());
                _activityLog.Log($"{this.GetType().Name} is up and running.");
            }
            catch (Exception e)
            {
                _logger.Fatal(e, "Error starting PizzaServiceHost.");
                throw;
            }
        }
Esempio n. 3
0
        public async Task Start()
        {
            _logger.Debug("Starting Pizza Planner.");

            if (string.IsNullOrEmpty(_config.PizzaRoom.City))
            {
                throw new ConfigurationErrorsException($"Config element cannot be null 'PizzaRoom.City'");
            }

            if (string.IsNullOrEmpty(_config.PizzaRoom.Room))
            {
                throw new ConfigurationErrorsException($"Config element cannot be null 'PizzaRoom.Room'");
            }

            if (string.IsNullOrEmpty(_config.BotRoom))
            {
                throw new ConfigurationErrorsException($"Config element cannot be null 'BotRoom'");
            }

            var channelName = $"#{_config.PizzaRoom.Room}";

            if (_core.Channels.Any(c => c.name == channelName))
            {
                //var newHub = await _core.SlackConnection.JoinChannel(_config.PizzaRoom.Room);
                var message = $"Bot not in channel {_config.PizzaRoom.Room} and bots cannot join rooms on their own. Invite it!";
                _activityLog.Log(message);
                throw new InvalidOperationException(message);
            }

            await _storage.Start();

            _activePlans = _storage.ReadArray <PizzaPlan>(ACTIVEEVENTSFILE).ToList();

            _pizzaInviter.OnInvitationChanged += HandleInvitationChanged;

            _timer = new Timer(async _ => await PizzaPlannerLoopTick(), null, TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(10));
        }