Esempio n. 1
0
        internal static Task HandleUsernoticeMessage(IrcClient client, IrcMessage message)
        {
            string        channelName = message.Parameters[0].Substring(1);
            TwitchChannel channel     = (TwitchChannel)client.Channels[channelName];

            if (message.Tags.ContainsKey("login"))
            {
                TwitchUser user = new TwitchUser(client, message.Tags["login"], message.Tags);

                if (message.Tags.ContainsKey("msg-id"))
                {
                    string noticeType = message.Tags["msg-id"];

                    if (noticeType == "sub" | noticeType == "resub")
                    {
                        int totalMonthsSubscribed = Convert.ToInt32(message.Tags["msg-param-cumulative-months"]);
                        TwitchSubscriptionPlan subscriptionPlan = TwitchUtils.ConvertSubscriptionPlan(message.Tags["msg-param-sub-plan"]);
                        int    consecutiveMonthsSubscribed      = 0;
                        string subMessage = null;

                        if (message.Parameters.Length == 2)
                        {
                            subMessage = message.Parameters[1];
                        }

                        if (message.Tags.ContainsKey("msg-param-should-share-streak") && message.Tags["msg-param-should-share-streak"] == "1")
                        {
                            consecutiveMonthsSubscribed = Convert.ToInt32(message.Tags["msg-param-streak-months"]);
                        }

                        var e = new TwitchSubscriptionEventArgs(user, channel, subscriptionPlan, subMessage, totalMonthsSubscribed, consecutiveMonthsSubscribed);
                        ((TwitchIrcClient)client).OnUserSubscribed(e);
                    }
                    else if (noticeType == "subgift" | noticeType == "anonsubgift")
                    {
                        int totalMonthsSubscribed = Convert.ToInt32(message.Tags["msg-param-months"]);
                        TwitchSubscriptionPlan subscriptionPlan = TwitchUtils.ConvertSubscriptionPlan(message.Tags["msg-param-sub-plan"]);
                        int        recipientUserID      = Convert.ToInt32(message.Tags["msg-param-recipient-id"]);;
                        string     recipientUserName    = message.Tags["msg-param-recipient-user-name"];
                        string     recipientDisplayName = message.Tags["msg-param-recipient-display-name"];
                        TwitchUser recipient            = new TwitchUser(client, recipientUserName, recipientDisplayName, recipientUserID);
                        string     subMessage           = null;

                        if (message.Parameters.Length == 2)
                        {
                            subMessage = message.Parameters[1];
                        }

                        if (noticeType == "anonsubgift")
                        {
                            var e = new TwitchSubscriptionEventArgs(null, channel, subscriptionPlan, subMessage, totalMonthsSubscribed, true, recipient, true);
                            ((TwitchIrcClient)client).OnUserSubscribed(e);
                        }
                        else
                        {
                            var e = new TwitchSubscriptionEventArgs(user, channel, subscriptionPlan, subMessage, totalMonthsSubscribed, true, recipient, false);
                            ((TwitchIrcClient)client).OnUserSubscribed(e);
                        }
                    }
                }
                else
                {
                    throw new TwitchProtocolException("USERNOTICE message does not have a msg-id tag.");
                }
            }
            else
            {
                throw new TwitchProtocolException("USERNOTICE message does not have a login tag.");
            }

            return(Task.CompletedTask);
        }
Esempio n. 2
0
 /// <summary>
 ///     Raises the <see cref="UserSubscribed"/> event.
 /// </summary>
 /// <param name="e">The <see cref="EventArgs"/> instance holding the event data.</param>
 internal void OnUserSubscribed(TwitchSubscriptionEventArgs e)
 {
     UserSubscribed?.Invoke(this, e);
 }