Exemple #1
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;
            }
        }