diff --git a/src/src/StevesBot.Webhook/YouTube/DiscordNotificationOptions.cs b/src/src/StevesBot.Webhook/YouTube/DiscordNotificationOptions.cs new file mode 100644 index 0000000..b373411 --- /dev/null +++ b/src/src/StevesBot.Webhook/YouTube/DiscordNotificationOptions.cs @@ -0,0 +1,10 @@ +namespace StevesBot.Webhook.YouTube; + +internal sealed record DiscordNotificationOptions +{ + [Required] + public string ChannelId { get; init; } = string.Empty; + + [Required] + public string MessageFormat { get; init; } = string.Empty; +} \ No newline at end of file diff --git a/src/src/StevesBot.Webhook/Handlers/NotificationHandler.cs b/src/src/StevesBot.Webhook/YouTube/Handlers/NotificationHandler.cs similarity index 73% rename from src/src/StevesBot.Webhook/Handlers/NotificationHandler.cs rename to src/src/StevesBot.Webhook/YouTube/Handlers/NotificationHandler.cs index 00a86e4..4226558 100644 --- a/src/src/StevesBot.Webhook/Handlers/NotificationHandler.cs +++ b/src/src/StevesBot.Webhook/YouTube/Handlers/NotificationHandler.cs @@ -1,10 +1,5 @@ -using StevesBot.Library.Discord.Rest; -using StevesBot.Library.Discord.Rest.Requests; +namespace StevesBot.Webhook.YouTube.Handlers; -namespace StevesBot.Webhook.Handlers; - -// TODO: Implement logic to do the following: -// - if is stream create discord message internal static class NotificationHandler { public static async Task HandleAsync( @@ -12,6 +7,7 @@ internal static class NotificationHandler [FromServices] ILogger logger, [FromServices] IYouTubeDataApiClient youTubeDataApiClient, [FromServices] IDiscordRestClient discordRestClient, + [FromServices] IOptionsMonitor discordNotificationOptions, CancellationToken cancellationToken ) { @@ -43,13 +39,22 @@ internal static class NotificationHandler return Results.Ok(); } - logger.LogInformation("Video ID {VideoId} is a live stream.", videoId); + logger.LogInformation( + "Video ID {VideoId} is a live stream. Creating discord message in channel {ChannelId}", + videoId, + discordNotificationOptions.CurrentValue.ChannelId + ); + + var msg = string.Format( + CultureInfo.InvariantCulture, + discordNotificationOptions.CurrentValue.MessageFormat, + videoId + ); await discordRestClient.CreateMessageAsync( - channelId: "1372680179121524778", + channelId: discordNotificationOptions.CurrentValue.ChannelId, request: new CreateMessageRequest( - Content: "@everyone Stevan is trying to be a streamer again! " + - $"Check out the stream here: https://www.youtube.com/watch?v={videoId}", + Content: msg, MessageReference: null ), cancellationToken: cancellationToken diff --git a/src/src/StevesBot.Webhook/Handlers/VerifySubscriptionHandler.cs b/src/src/StevesBot.Webhook/YouTube/Handlers/VerifySubscriptionHandler.cs similarity index 97% rename from src/src/StevesBot.Webhook/Handlers/VerifySubscriptionHandler.cs rename to src/src/StevesBot.Webhook/YouTube/Handlers/VerifySubscriptionHandler.cs index 14282bf..a334b25 100644 --- a/src/src/StevesBot.Webhook/Handlers/VerifySubscriptionHandler.cs +++ b/src/src/StevesBot.Webhook/YouTube/Handlers/VerifySubscriptionHandler.cs @@ -1,4 +1,4 @@ -namespace StevesBot.Webhook.Handlers; +namespace StevesBot.Webhook.YouTube.Handlers; internal static class VerifySubscriptionHandler { diff --git a/src/src/StevesBot.Webhook/appsettings.Example.json b/src/src/StevesBot.Webhook/appsettings.Example.json index 56defff..db3a004 100644 --- a/src/src/StevesBot.Webhook/appsettings.Example.json +++ b/src/src/StevesBot.Webhook/appsettings.Example.json @@ -16,5 +16,14 @@ }, "PubSubClientOptions": { "BaseUrl": "BaseUrl" + }, + "DiscordClientOptions": { + "ApiUrl": "ApiUrl", + "AppToken": "AppToken", + "Intents": 0 + }, + "DiscordNotificationOptions": { + "ChannelId": "ChannelId", + "MessageFormat": "MessageFormat" } }