public async Task Run([ServiceBusTrigger("%DiscordNotificationQueueName%", Connection = "StreamingServiceBus")] string message, ILogger logger)
        {
            try
            {
                logger.LogInformation($"Discord notification started");
                var discordMessage = JsonConvert.DeserializeObject <DiscordMessage>(message);
                await _discordNotificationService.SendNotification(discordMessage.WebhookId, discordMessage.WebhookToken, discordMessage.Notification);

                logger.LogInformation($"Discord notification succeeded");
            }
            catch (Exception e)
            {
                logger.LogError($"Discord notification failed: {e.Message}\n{message}");
            }
        }
Beispiel #2
0
        private async Task SendClipsAsync(string broadcasterId, DateTime startedAt, DateTime endedAt, ILogger logger)
        {
            var clips = await _twitchApiService.GetClipsByBroadcasterAsync(broadcasterId, startedAt, endedAt);

            var succeeded = 0;
            await Task.WhenAll(clips.OrderBy(x => x.CreatedAt).Select(async clip =>
            {
                var games        = await _twitchApiService.GetGamesAsync(clip.GameId);
                var notification = TwitchClipToDiscordNotificationTranslator.Translate(clip, games.First());
                try
                {
                    logger.LogInformation($"Clip notification {notification.Embeds[0].Title} started");
                    await _discordNotificationService.SendNotification(_discordwebhookId, _discordwebhookToken, notification);
                    succeeded++;
                    logger.LogInformation($"Clip notification {notification.Embeds[0].Title} succeeded");
                }
                catch (Exception e)
                {
                    logger.LogError($"Clip notification {notification.Embeds[0].Title} failed: {e.Message}");
                }
            }));
        }
        protected override async Task <IActionResult> HandleMessageAsync(StreamOnlineEvent message)
        {
            try
            {
                _logger.LogInformation("StreamChangeWebhook execution started");
                var channel = await _twitchApiService.GetChannelInfoAsync(message.BroadcasterUserId);

                var games = await _twitchApiService.GetGamesAsync(channel.GameId);

                var notification = TwitchStreamChangeToDiscordNotificationTranslator.Translate(message, channel, games.First());
                _logger.LogInformation("Sending stream change notification to discord server");
                await _discordNotificationService.SendNotification(_discordwebhookId, _discordwebhookToken, notification);

                _logger.LogInformation("StreamChangeSubscribe execution succeeded: Notification sent");
                return(new OkResult());
            }
            catch (Exception e)
            {
                _logger.LogError($"StreamChangeSubscribe execution failed: {e.Message}");
                throw;
            }
        }
Beispiel #4
0
        private async Task SendHighlightsAsync(string broadcasterId, DateTime startedAt, ILogger logger)
        {
            var videos = await _twitchApiService.GetHighlightsByBroadcasterAsync(broadcasterId);

            var filteredVideos = videos.Where(video => video.PublishedAt >= startedAt && video.Viewable == "public").OrderBy(video => video.PublishedAt);

            foreach (var video in filteredVideos)
            {
                var notification = _translator.Translate(video);
                try
                {
                    logger.LogInformation($"Highlight notification {notification.Embeds[0].Title} started");
                    await _discordNotificationService.SendNotification(_discordwebhookId, _discordwebhookToken, notification);

                    logger.LogInformation($"Highlight notification {notification.Embeds[0].Title} succeeded");
                }
                catch (Exception e)
                {
                    logger.LogError($"Highlight notification {notification.Embeds[0].Title} failed: {e.Message}");
                }
            }
        }
 public async Task Consume(ConsumeContext <BuildDetails> context)
 {
     await notificationService.SendNotification(context.Message);
 }
Beispiel #6
0
 private async Task SendDiscordNotifications(string username, string channelOfOrigin, Guid ruleId)
 {
     await discordNotificationService.SendNotification(username, channelOfOrigin, ruleId).ConfigureAwait(false);
 }