From e6190bc0d759801e74af314124e2d323f27b65ec Mon Sep 17 00:00:00 2001 From: Matthew Olivo Date: Mon, 22 Jan 2024 19:29:22 -0800 Subject: [PATCH] - Connecting unmod and unban options for YouTube to Moderation action --- .../Platform/YouTubeUserPlatformV2Model.cs | 6 +++ MixItUp.Base/Services/ChatService.cs | 10 +++++ .../Services/YouTube/YouTubeChatService.cs | 38 ++++++++++++++++++- .../YouTube/YouTubePlatformService.cs | 2 + 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/MixItUp.Base/Model/User/Platform/YouTubeUserPlatformV2Model.cs b/MixItUp.Base/Model/User/Platform/YouTubeUserPlatformV2Model.cs index 06e7a3f57..d2a59bf17 100644 --- a/MixItUp.Base/Model/User/Platform/YouTubeUserPlatformV2Model.cs +++ b/MixItUp.Base/Model/User/Platform/YouTubeUserPlatformV2Model.cs @@ -18,6 +18,12 @@ public class YouTubeUserPlatformV2Model : UserPlatformV2ModelBase [DataMember] public HashSet MemberLevels { get; set; } = new HashSet(); + [DataMember] + public string ModeratorID { get; set; } + + [DataMember] + public string BanID { get; set; } + private bool initialRefreshCompleted = false; public YouTubeUserPlatformV2Model(Channel channel) diff --git a/MixItUp.Base/Services/ChatService.cs b/MixItUp.Base/Services/ChatService.cs index ef44ff88b..096727d80 100644 --- a/MixItUp.Base/Services/ChatService.cs +++ b/MixItUp.Base/Services/ChatService.cs @@ -302,6 +302,11 @@ public async Task UnmodUser(UserV2ViewModel user) await ServiceManager.Get().UnmodUser(user); } + if (user.Platform == StreamingPlatformTypeEnum.YouTube && ServiceManager.Get().IsUserConnected) + { + await ServiceManager.Get().UnmodUser(user); + } + if (user.Platform == StreamingPlatformTypeEnum.Trovo && ServiceManager.Get().IsUserConnected) { await ServiceManager.Get().UnmodUser(user.Username); @@ -333,6 +338,11 @@ public async Task UnbanUser(UserV2ViewModel user) await ServiceManager.Get().UnbanUser(user); } + if (user.Platform == StreamingPlatformTypeEnum.YouTube && ServiceManager.Get().IsUserConnected) + { + await ServiceManager.Get().UnbanUser(user); + } + if (user.Platform == StreamingPlatformTypeEnum.Trovo && ServiceManager.Get().IsUserConnected) { await ServiceManager.Get().UnbanUser(user.Username); diff --git a/MixItUp.Base/Services/YouTube/YouTubeChatService.cs b/MixItUp.Base/Services/YouTube/YouTubeChatService.cs index 59fdeab97..dcb90c16c 100644 --- a/MixItUp.Base/Services/YouTube/YouTubeChatService.cs +++ b/MixItUp.Base/Services/YouTube/YouTubeChatService.cs @@ -232,11 +232,28 @@ public async Task ModUser(UserV2ViewModel user) { if (ServiceManager.Get().IsLive) { - await this.GetConnection(sendAsStreamer: true).ModChatUser(ServiceManager.Get().Broadcast, new Channel() { Id = user.PlatformID }); + LiveChatModerator moderator = await this.GetConnection(sendAsStreamer: true).ModChatUser(ServiceManager.Get().Broadcast, new Channel() { Id = user.PlatformID }); + if (moderator != null) + { + user.GetPlatformData(StreamingPlatformTypeEnum.YouTube).ModeratorID = moderator.Id; + } } return null; } + public async Task UnmodUser(UserV2ViewModel user) + { + if (ServiceManager.Get().IsLive) + { + string moderatorID = user.GetPlatformData(StreamingPlatformTypeEnum.YouTube)?.ModeratorID; + if (!string.IsNullOrWhiteSpace(moderatorID)) + { + await this.GetConnection(sendAsStreamer: true).UnmodChatUser(new LiveChatModerator() { Id = moderatorID }); + user.GetPlatformData(StreamingPlatformTypeEnum.YouTube).ModeratorID = null; + } + } + } + public async Task TimeoutUser(UserV2ViewModel user, ulong duration) { if (ServiceManager.Get().IsLive) @@ -250,11 +267,28 @@ public async Task BanUser(UserV2ViewModel user) { if (ServiceManager.Get().IsLive) { - await this.GetConnection(sendAsStreamer: true).BanChatUser(ServiceManager.Get().Broadcast, new Channel() { Id = user.PlatformID }); + LiveChatBan ban = await this.GetConnection(sendAsStreamer: true).TimeoutChatUser(ServiceManager.Get().Broadcast, new Channel() { Id = user.PlatformID }, duration); + if (ban != null) + { + user.GetPlatformData(StreamingPlatformTypeEnum.YouTube).BanID = ban.Id; + } } return null; } + public async Task UnbanUser(UserV2ViewModel user) + { + if (ServiceManager.Get().IsLive) + { + string banID = user.GetPlatformData(StreamingPlatformTypeEnum.YouTube)?.BanID; + if (!string.IsNullOrWhiteSpace(banID)) + { + await this.GetConnection(sendAsStreamer: true).UnbanChatUser(new LiveChatBan() { Id = banID }); + user.GetPlatformData(StreamingPlatformTypeEnum.YouTube).BanID = null; + } + } + } + public async Task> GetChatEmotes() { try diff --git a/MixItUp.Base/Services/YouTube/YouTubePlatformService.cs b/MixItUp.Base/Services/YouTube/YouTubePlatformService.cs index 25698bd83..70f0b2799 100644 --- a/MixItUp.Base/Services/YouTube/YouTubePlatformService.cs +++ b/MixItUp.Base/Services/YouTube/YouTubePlatformService.cs @@ -134,5 +134,7 @@ public YouTubePlatformService(YouTubeConnection connection) public async Task TimeoutChatUser(LiveBroadcast broadcast, Channel user, ulong duration) { return await AsyncRunner.RunAsync(this.Connection.LiveChat.TimeoutUser(broadcast, user, duration)); } public async Task BanChatUser(LiveBroadcast broadcast, Channel user) { return await AsyncRunner.RunAsync(this.Connection.LiveChat.BanUser(broadcast, user)); } + + public async Task UnbanChatUser(LiveChatBan ban) { await AsyncRunner.RunAsync(this.Connection.LiveChat.UnbanUser(ban)); } } }