private async Task ReleaseAsync(IncomingMessage incomingMessage, string resource) { if (string.IsNullOrEmpty(resource)) { var fields = new List <AttachmentField>(); foreach (var key in Brain.Keys) { fields.Add(new AttachmentField { Value = string.Format("{0} is being held captive by @{1}", key, Brain[key]) }); } await Slack.PostAsync(new Attachment { Channel = incomingMessage.ReplyTo(), Text = "Current inmates", Fields = fields, }); return; } string text; object value; if (Brain.TryGetValue(resource, out value)) { if (value.ToString() == incomingMessage.UserName) { Brain.Remove(resource); text = string.Format("{0} was released by @{1}", resource, incomingMessage.UserName); } else { text = string.Format("@{0} you can't release {1} can only be released by @{2}", incomingMessage.UserName, resource, value); } } else { text = string.Format("@{0} {1} has not been captured", incomingMessage.UserName, resource); } await Slack.SendAsync(incomingMessage.ReplyTo(), text); }
private async Task ListFeaturesAsync(IncomingMessage incomingMessage) { var fields = _scope.Resolve <IEnumerable <IHandleMessage> >() .Where(t => t.GetType() != GetType() && t.GetType() != typeof(TeamCityHandler)) .OrderBy(t => t.GetType().Name) .Select(h => new AttachmentField { Value = h.Help() }) .ToArray(); await Slack.PostAsync(new Attachment { Channel = incomingMessage.ReplyTo(), Text = "Availible Features", Fields = fields, }); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogInformation("Service started"); _logger.LogInformation("{@_scheduleOptions}", _scheduleOptions); while (!stoppingToken.IsCancellationRequested) { var current = DateTime.Now; if (current.DayOfWeek == DayOfWeek.Saturday || current.DayOfWeek == DayOfWeek.Sunday) { _logger.LogInformation("Not running on weekend"); await Task.Delay(24 * 60 * 1000, stoppingToken); continue; } if (current.Hour == _scheduleOptions.Hour && current.Minute == _scheduleOptions.Minute && current.Second == _scheduleOptions.Second) { var json = await _slack.PostAsync(_slackOptions.Channel, _slackOptions.Message, asUser : true); if (!json.Ok) { _logger.LogError(json.Error); } else { _logger.LogInformation("Message posted"); } await Task.Delay(1000, stoppingToken); continue; } await Task.Delay(1000, stoppingToken); } }