示例#1
0
        private void OnSub(object sender, OnChannelSubscriptionArgs e)
        {
            try
            {
                if (e.Subscription.Context == "subgift")
                {
                    _logger.LogInformation(
                        $"Gifted Sub! - {e.Subscription.RecipientName} - {e.Subscription.Months ?? 1} months, {e.Subscription.StreakMonths} in a row!");

                    _vipApiClient.GiveSubscriptionVips(new GiveSubscriptionVipsRequest
                    {
                        UserSubDetails = new List <UserSubDetail>
                        {
                            new UserSubDetail
                            {
                                Username         = e.Subscription.RecipientName,
                                SubscriptionTier = VipHelper.GetSubTier(e),
                                TotalSubMonths   = e.Subscription.Months ?? 1
                            }
                        }
                    });

                    // Gifted Sub!
                    OnGiftSub(sender, e);
                }
                else
                {
                    _logger.LogInformation(
                        $"Subscription! - {e.Subscription.Username} - {e.Subscription.CumulativeMonths ?? 1} months, {e.Subscription.StreakMonths} in a row!");

                    _vipApiClient.GiveSubscriptionVips(new GiveSubscriptionVipsRequest
                    {
                        UserSubDetails = new List <UserSubDetail>
                        {
                            new UserSubDetail
                            {
                                Username         = e.Subscription.Username,
                                SubscriptionTier = VipHelper.GetSubTier(e),
                                TotalSubMonths   = e.Subscription.CumulativeMonths ?? 1
                            }
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error on Sub", new { e });
            }
        }