Skip to content

Commit

Permalink
feat: hide Discord msg for hidden channels
Browse files Browse the repository at this point in the history
- Add check to ensure `channel.Hide` is not true before sending start recording message in `FC2Service.cs`
- Add check to ensure `channel.Hide` is not true before sending start recording message in `TwitcastingService.cs`
- Add check to ensure `channel.Hide` is not true before sending deleted message in `TwitcastingService.cs`
- Add check to ensure `channel.Hide` is not true before sending start recording message in `TwitchService.cs`
- Add check to ensure `channel.Hide` is not true before sending skipped message in `YoutubeService.cs`
- Add check to ensure `channel.Hide` is not true before sending deleted message in `YoutubeService.cs`
- Add check to ensure `channel.Hide` is not true before sending archived message in `YoutubeService.cs`
- Retrieve channel data before processing finished video in `RecordService.cs`
- Add check to ensure `channel.Hide` is not true before sending archived message in `RecordService.cs`

Signed-off-by: 陳鈞 <[email protected]>
  • Loading branch information
jim60105 committed Oct 25, 2024
1 parent 7795ed6 commit a5f1ede
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
4 changes: 3 additions & 1 deletion ScopedServices/PlatformService/FC2Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ await fC2LiveDLService.CreateJobAsync(video: video,
TypeInfoResolver = SourceGenerationContext.Default
}));

if (null != DiscordService) await DiscordService.SendStartRecordingMessageAsync(video, channel);
if (null != DiscordService
&& channel.Hide != true)
await DiscordService.SendStartRecordingMessageAsync(video, channel);
}
}
else
Expand Down
13 changes: 9 additions & 4 deletions ScopedServices/PlatformService/TwitcastingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ await twitcastingRecorderService.CreateJobAsync(video: video,
video.Status = VideoStatus.Recording;
logger.LogInformation("{channelId} is now lived! Start recording.", channel.id);

if (null != DiscordService) await DiscordService.SendStartRecordingMessageAsync(video, channel);
if (null != DiscordService
&& channel.Hide != true)
await DiscordService.SendStartRecordingMessageAsync(video, channel);
}
}
else
Expand Down Expand Up @@ -192,7 +194,9 @@ await DownloadThumbnailAsync(
{
video.SourceStatus = VideoStatus.Reject;
video.Note = "Video source is detected access required.";
if (null != DiscordService) await DiscordService.SendDeletedMessageAsync(video, channel);
if (null != DiscordService
&& (null == channel || channel.Hide != true))
await DiscordService.SendDeletedMessageAsync(video, channel);

logger.LogInformation("Video source is {status} because it is detected access required.",
Enum.GetName(typeof(VideoStatus), video.SourceStatus));
Expand All @@ -208,9 +212,10 @@ await DownloadThumbnailAsync(
if (video.Status >= VideoStatus.Archived
&& video.Status < VideoStatus.Expired)
{
// First detected
video.SourceStatus = VideoStatus.Deleted;
if (null != DiscordService)
// First detected
if (null != DiscordService
&& (null == channel || channel.Hide != true))
await DiscordService.SendDeletedMessageAsync(video, channel);
}

Expand Down
4 changes: 3 additions & 1 deletion ScopedServices/PlatformService/TwitchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ await streamlinkService.CreateJobAsync(video: video,

video.Status = VideoStatus.Recording;
logger.LogInformation("{channelId} is now lived! Start recording.", channel.id);
if (null != DiscordService) await DiscordService.SendStartRecordingMessageAsync(video, channel);
if (null != DiscordService
&& channel.Hide != true)
await DiscordService.SendStartRecordingMessageAsync(video, channel);
}

await videoRepository.AddOrUpdateAsync(video);
Expand Down
30 changes: 22 additions & 8 deletions ScopedServices/PlatformService/YoutubeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
video.Note = "Video skipped because it is not live stream.";
// First detected
if (video.Status != VideoStatus.Skipped
&& null != DiscordService)
&& null != DiscordService
&& channel.Hide != true)
await DiscordService.SendSkippedMessageAsync(video, channel);

video.Status = VideoStatus.Skipped;
Expand Down Expand Up @@ -219,7 +220,8 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
video.Note = "Video skipped because it is not live stream.";
// First detected
if (video.Status != VideoStatus.Skipped
&& null != DiscordService)
&& null != DiscordService
&& channel.Hide != true)
await DiscordService.SendSkippedMessageAsync(video, channel);

video.Status = VideoStatus.Skipped;
Expand Down Expand Up @@ -296,7 +298,9 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
{
// First detected
video.SourceStatus = VideoStatus.Deleted;
if (null != DiscordService) await DiscordService.SendDeletedMessageAsync(video, channel);
if (null != DiscordService
&& (null == channel || channel.Hide != true))
await DiscordService.SendDeletedMessageAsync(video, channel);
}

video.SourceStatus = VideoStatus.Deleted;
Expand Down Expand Up @@ -327,7 +331,9 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
if (video.Status != VideoStatus.Missing)
{
video.SourceStatus = VideoStatus.Missing;
if (null != DiscordService) await DiscordService.SendSkippedMessageAsync(video, channel);
if (null != DiscordService
&& (null == channel || channel.Hide != true))
await DiscordService.SendSkippedMessageAsync(video, channel);
}

video.Status = VideoStatus.Missing;
Expand Down Expand Up @@ -371,7 +377,9 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
if (video.SourceStatus != VideoStatus.Edited)
{
video.SourceStatus = VideoStatus.Edited;
if (null != DiscordService) await DiscordService.SendDeletedMessageAsync(video, channel);
if (null != DiscordService
&& (null == channel || channel.Hide != true))
await DiscordService.SendDeletedMessageAsync(video, channel);
}

video.SourceStatus = VideoStatus.Edited;
Expand All @@ -392,7 +400,8 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
video.Note = "Video is Skipped because it is detected access required or copyright notice.";
// First detected
if (video.Status != VideoStatus.Skipped
&& null != DiscordService)
&& null != DiscordService
&& (null == channel || channel.Hide != true))
await DiscordService.SendSkippedMessageAsync(video, channel);

video.Status = VideoStatus.Skipped;
Expand All @@ -404,7 +413,9 @@ public override async Task UpdateVideoDataAsync(Video video, CancellationToken c
{
video.SourceStatus = VideoStatus.Reject;
video.Note = "Video source is detected access required or copyright notice.";
if (null != DiscordService) await DiscordService.SendDeletedMessageAsync(video, channel);
if (null != DiscordService
&& (null == channel || channel.Hide != true))
await DiscordService.SendDeletedMessageAsync(video, channel);
}

video.SourceStatus = VideoStatus.Reject;
Expand All @@ -425,7 +436,10 @@ await ytarchiveService.CreateJobAsync(video: video,

video.Status = VideoStatus.Recording;
logger.LogInformation("{videoId} is now lived! Start recording.", video.id);
if (null != DiscordService) await DiscordService.SendStartRecordingMessageAsync(video, channel);
if (null != DiscordService
&& (null == channel
|| channel.Hide != true))
await DiscordService.SendStartRecordingMessageAsync(video, channel);
}

if (video.Status < 0)
Expand Down
9 changes: 5 additions & 4 deletions SingletonServices/RecordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public async Task ProcessFinishedVideoAsync(VideoService videoService,
using IDisposable __ = LogContext.PushProperty("videoId", video.id);

await channelService.UpdateChannelLatestVideoAsync(video);
Channel? channel = await channelService.GetByChannelIdAndSourceAsync(video.ChannelId, video.Source);

try
{
Expand All @@ -312,10 +313,10 @@ public async Task ProcessFinishedVideoAsync(VideoService videoService,
_logger.LogInformation("Video {videoId} is successfully uploaded to Storage.", video.id);
await videoService.UpdateVideoArchivedTimeAsync(video);

if (_discordService != null)
await _discordService.SendArchivedMessageAsync(
video,
await channelService.GetByChannelIdAndSourceAsync(video.ChannelId, video.Source));
if (null != _discordService
&& (null == channel
|| channel.Hide != true))
await _discordService.SendArchivedMessageAsync(video, channel);
}
catch (Exception e)
{
Expand Down

0 comments on commit a5f1ede

Please sign in to comment.