Skip to content

Commit

Permalink
- Connecting unmod and unban options for YouTube to Moderation action
Browse files Browse the repository at this point in the history
  • Loading branch information
SaviorXTanren committed Jan 23, 2024
1 parent 76b96d2 commit e6190bc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class YouTubeUserPlatformV2Model : UserPlatformV2ModelBase
[DataMember]
public HashSet<string> MemberLevels { get; set; } = new HashSet<string>();

[DataMember]
public string ModeratorID { get; set; }

[DataMember]
public string BanID { get; set; }

private bool initialRefreshCompleted = false;

public YouTubeUserPlatformV2Model(Channel channel)
Expand Down
10 changes: 10 additions & 0 deletions MixItUp.Base/Services/ChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ public async Task UnmodUser(UserV2ViewModel user)
await ServiceManager.Get<TwitchChatService>().UnmodUser(user);
}

if (user.Platform == StreamingPlatformTypeEnum.YouTube && ServiceManager.Get<YouTubeChatService>().IsUserConnected)
{
await ServiceManager.Get<YouTubeChatService>().UnmodUser(user);
}

if (user.Platform == StreamingPlatformTypeEnum.Trovo && ServiceManager.Get<TrovoChatEventService>().IsUserConnected)
{
await ServiceManager.Get<TrovoChatEventService>().UnmodUser(user.Username);
Expand Down Expand Up @@ -333,6 +338,11 @@ public async Task UnbanUser(UserV2ViewModel user)
await ServiceManager.Get<TwitchChatService>().UnbanUser(user);
}

if (user.Platform == StreamingPlatformTypeEnum.YouTube && ServiceManager.Get<YouTubeChatService>().IsUserConnected)
{
await ServiceManager.Get<YouTubeChatService>().UnbanUser(user);
}

if (user.Platform == StreamingPlatformTypeEnum.Trovo && ServiceManager.Get<TrovoChatEventService>().IsUserConnected)
{
await ServiceManager.Get<TrovoChatEventService>().UnbanUser(user.Username);
Expand Down
38 changes: 36 additions & 2 deletions MixItUp.Base/Services/YouTube/YouTubeChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,28 @@ public async Task<LiveChatModerator> ModUser(UserV2ViewModel user)
{
if (ServiceManager.Get<YouTubeSessionService>().IsLive)
{
await this.GetConnection(sendAsStreamer: true).ModChatUser(ServiceManager.Get<YouTubeSessionService>().Broadcast, new Channel() { Id = user.PlatformID });
LiveChatModerator moderator = await this.GetConnection(sendAsStreamer: true).ModChatUser(ServiceManager.Get<YouTubeSessionService>().Broadcast, new Channel() { Id = user.PlatformID });
if (moderator != null)
{
user.GetPlatformData<YouTubeUserPlatformV2Model>(StreamingPlatformTypeEnum.YouTube).ModeratorID = moderator.Id;
}
}
return null;
}

public async Task UnmodUser(UserV2ViewModel user)
{
if (ServiceManager.Get<YouTubeSessionService>().IsLive)
{
string moderatorID = user.GetPlatformData<YouTubeUserPlatformV2Model>(StreamingPlatformTypeEnum.YouTube)?.ModeratorID;
if (!string.IsNullOrWhiteSpace(moderatorID))
{
await this.GetConnection(sendAsStreamer: true).UnmodChatUser(new LiveChatModerator() { Id = moderatorID });
user.GetPlatformData<YouTubeUserPlatformV2Model>(StreamingPlatformTypeEnum.YouTube).ModeratorID = null;
}
}
}

public async Task<LiveChatBan> TimeoutUser(UserV2ViewModel user, ulong duration)
{
if (ServiceManager.Get<YouTubeSessionService>().IsLive)
Expand All @@ -250,11 +267,28 @@ public async Task<LiveChatBan> BanUser(UserV2ViewModel user)
{
if (ServiceManager.Get<YouTubeSessionService>().IsLive)
{
await this.GetConnection(sendAsStreamer: true).BanChatUser(ServiceManager.Get<YouTubeSessionService>().Broadcast, new Channel() { Id = user.PlatformID });
LiveChatBan ban = await this.GetConnection(sendAsStreamer: true).TimeoutChatUser(ServiceManager.Get<YouTubeSessionService>().Broadcast, new Channel() { Id = user.PlatformID }, duration);
if (ban != null)
{
user.GetPlatformData<YouTubeUserPlatformV2Model>(StreamingPlatformTypeEnum.YouTube).BanID = ban.Id;
}
}
return null;
}

public async Task UnbanUser(UserV2ViewModel user)
{
if (ServiceManager.Get<YouTubeSessionService>().IsLive)
{
string banID = user.GetPlatformData<YouTubeUserPlatformV2Model>(StreamingPlatformTypeEnum.YouTube)?.BanID;
if (!string.IsNullOrWhiteSpace(banID))
{
await this.GetConnection(sendAsStreamer: true).UnbanChatUser(new LiveChatBan() { Id = banID });
user.GetPlatformData<YouTubeUserPlatformV2Model>(StreamingPlatformTypeEnum.YouTube).BanID = null;
}
}
}

public async Task<IEnumerable<YouTubeChatEmoteModel>> GetChatEmotes()
{
try
Expand Down
2 changes: 2 additions & 0 deletions MixItUp.Base/Services/YouTube/YouTubePlatformService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,7 @@ public YouTubePlatformService(YouTubeConnection connection)
public async Task<LiveChatBan> TimeoutChatUser(LiveBroadcast broadcast, Channel user, ulong duration) { return await AsyncRunner.RunAsync(this.Connection.LiveChat.TimeoutUser(broadcast, user, duration)); }

public async Task<LiveChatBan> 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)); }
}
}

0 comments on commit e6190bc

Please sign in to comment.