feat: add Discord notification options and handlers for YouTube events
This commit is contained in:
@@ -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;
|
||||
}
|
||||
+15
-10
@@ -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<IResult> HandleAsync(
|
||||
@@ -12,6 +7,7 @@ internal static class NotificationHandler
|
||||
[FromServices] ILogger<Program> logger,
|
||||
[FromServices] IYouTubeDataApiClient youTubeDataApiClient,
|
||||
[FromServices] IDiscordRestClient discordRestClient,
|
||||
[FromServices] IOptionsMonitor<DiscordNotificationOptions> 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
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace StevesBot.Webhook.Handlers;
|
||||
namespace StevesBot.Webhook.YouTube.Handlers;
|
||||
|
||||
internal static class VerifySubscriptionHandler
|
||||
{
|
||||
@@ -16,5 +16,14 @@
|
||||
},
|
||||
"PubSubClientOptions": {
|
||||
"BaseUrl": "BaseUrl"
|
||||
},
|
||||
"DiscordClientOptions": {
|
||||
"ApiUrl": "ApiUrl",
|
||||
"AppToken": "AppToken",
|
||||
"Intents": 0
|
||||
},
|
||||
"DiscordNotificationOptions": {
|
||||
"ChannelId": "ChannelId",
|
||||
"MessageFormat": "MessageFormat"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user