Skip to content

Commit

Permalink
- Fixing bug with YouTube membership gifting not assigning the users …
Browse files Browse the repository at this point in the history
…correctly
  • Loading branch information
SaviorXTanren committed Sep 14, 2023
1 parent 7334af3 commit 77f2886
Showing 1 changed file with 19 additions and 30 deletions.
49 changes: 19 additions & 30 deletions MixItUp.Base/Services/YouTube/YouTubeChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class YouTubeChatEmoteImageURLModel

public class YouTubeMembershipsGiftedModel
{
public UserV2ViewModel User { get; private set; }
public UserV2ViewModel Gifter { get; private set; }

public int Amount { get; set; }

Expand All @@ -52,17 +52,10 @@ public class YouTubeMembershipsGiftedModel

public YouTubeMembershipsGiftedModel(UserV2ViewModel user, LiveChatMembershipGiftingDetails giftingDetails)
{
this.User = user;
this.Gifter = user;
this.Amount = giftingDetails.GiftMembershipsCount.GetValueOrDefault();
this.Tier = giftingDetails.GiftMembershipsLevelName;
}

public YouTubeMembershipsGiftedModel(UserV2ViewModel user, LiveChatGiftMembershipReceivedDetails giftReceivedDetails)
{
this.User = user;
this.Amount = 1;
this.Tier = giftReceivedDetails.MemberLevelName;
}
}

public class YouTubeChatService : StreamingPlatformServiceBase
Expand Down Expand Up @@ -438,7 +431,7 @@ private async Task ProcessMessages(IEnumerable<LiveChatMessage> liveChatMessages
YouTubeMembershipsGiftedModel membershipsGifted = new YouTubeMembershipsGiftedModel(user, liveChatMessage.Snippet.MembershipGiftingDetails);
if (membershipsGifted.Amount > ChannelSession.Settings.MassGiftedSubsFilterAmount)
{
this.userGiftedMembershipDictionary[membershipsGifted.User.PlatformID] = membershipsGifted;
this.userGiftedMembershipDictionary[membershipsGifted.Gifter.PlatformID] = membershipsGifted;

foreach (CurrencyModel currency in ChannelSession.Settings.Currency.Values)
{
Expand Down Expand Up @@ -467,15 +460,16 @@ private async Task ProcessMessages(IEnumerable<LiveChatMessage> liveChatMessages
}
else if (GiftMembershipReceivedEventMessageType.Equals(liveChatMessage.Snippet.Type))
{
ChannelSession.Settings.LatestSpecialIdentifiersData[SpecialIdentifierStringBuilder.LatestSubscriberUserData] = user.ID;
UserV2ViewModel gifter = await ServiceManager.Get<UserService>().GetUserByPlatformID(StreamingPlatformTypeEnum.YouTube, liveChatMessage.Snippet.GiftMembershipReceivedDetails.GifterChannelId, performPlatformSearch: true);
UserV2ViewModel receiver = user;

ChannelSession.Settings.LatestSpecialIdentifiersData[SpecialIdentifierStringBuilder.LatestSubscriberUserData] = receiver.ID;
ChannelSession.Settings.LatestSpecialIdentifiersData[SpecialIdentifierStringBuilder.LatestSubscriberSubMonthsData] = 1;

user.Roles.Add(UserRoleEnum.YouTubeMember);
user.SubscribeDate = DateTimeOffset.Now;
// TODO
//user.SubscriberTier = giftedSubEvent.PlanTierNumber;
user.TotalSubsReceived++;
user.TotalMonthsSubbed++;
receiver.Roles.Add(UserRoleEnum.YouTubeMember);
receiver.SubscribeDate = DateTimeOffset.Now;
receiver.TotalSubsReceived++;
receiver.TotalMonthsSubbed++;

if (this.userGiftedMembershipDictionary.TryGetValue(liveChatMessage.Snippet.GiftMembershipReceivedDetails.GifterChannelId, out YouTubeMembershipsGiftedModel membershipsGifted))
{
Expand All @@ -487,33 +481,28 @@ private async Task ProcessMessages(IEnumerable<LiveChatMessage> liveChatMessages
}
else
{
membershipsGifted = new YouTubeMembershipsGiftedModel(user, liveChatMessage.Snippet.GiftMembershipReceivedDetails);

foreach (CurrencyModel currency in ChannelSession.Settings.Currency.Values)
{
for (int i = 0; i < membershipsGifted.Amount; i++)
{
currency.AddAmount(user, currency.OnSubscribeBonus);
}
currency.AddAmount(receiver, currency.OnSubscribeBonus);
}

foreach (StreamPassModel streamPass in ChannelSession.Settings.StreamPass.Values)
{
if (user.MeetsRole(streamPass.UserPermission))
if (receiver.MeetsRole(streamPass.UserPermission))
{
streamPass.AddAmount(user, streamPass.SubscribeBonus);
streamPass.AddAmount(receiver, streamPass.SubscribeBonus);
}
}

CommandParametersModel parameters = new CommandParametersModel(membershipsGifted.User, StreamingPlatformTypeEnum.YouTube);
CommandParametersModel parameters = new CommandParametersModel(gifter, StreamingPlatformTypeEnum.YouTube);
// TODO
parameters.SpecialIdentifiers["usersubplan"] = liveChatMessage.Snippet.GiftMembershipReceivedDetails.MemberLevelName;
parameters.Arguments.Add(user.Username);
parameters.TargetUser = user;
parameters.Arguments.Add(receiver.Username);
parameters.TargetUser = receiver;
await ServiceManager.Get<EventService>().PerformEvent(EventTypeEnum.YouTubeChannelMembershipGifted, parameters);

await ServiceManager.Get<AlertsService>().AddAlert(new AlertChatMessageViewModel(membershipsGifted.User, string.Format(MixItUp.Base.Resources.AlertSubscriptionGiftedTier, membershipsGifted.User.FullDisplayName, liveChatMessage.Snippet.GiftMembershipReceivedDetails.MemberLevelName, user.FullDisplayName), ChannelSession.Settings.AlertGiftedSubColor));
GlobalEvents.SubscriptionGiftedOccurred(membershipsGifted.User, user);
await ServiceManager.Get<AlertsService>().AddAlert(new AlertChatMessageViewModel(gifter, string.Format(MixItUp.Base.Resources.AlertSubscriptionGiftedTier, gifter.FullDisplayName, liveChatMessage.Snippet.GiftMembershipReceivedDetails.MemberLevelName, receiver.FullDisplayName), ChannelSession.Settings.AlertGiftedSubColor));
GlobalEvents.SubscriptionGiftedOccurred(gifter, receiver);
}
}
else if (SuperChatEventMessageType.Equals(liveChatMessage.Snippet.Type))
Expand Down

0 comments on commit 77f2886

Please sign in to comment.