Beispiel #1
0
        internal static Task HandleTargetedMessage(IrcClient client, IrcMessage message)
        {
            IrcTargetedMessage targetedMessage = new IrcTargetedMessage(client, message);

            if (targetedMessage.IsChannelMessage)
            {
                var channel = (IrcChannel)targetedMessage.Target;
                var e       = new IrcChannelMessageEventArgs(targetedMessage);

                if (targetedMessage.Type == IrcTargetedMessage.MessageType.Privmsg)
                {
                    client.OnChannelMessageReceived(e);
                    channel.OnMessageReceived(e);
                }
                else if (targetedMessage.Type == IrcTargetedMessage.MessageType.Notice)
                {
                    client.OnChannelNoticeReceived(e);
                    channel.OnNoticeReceived(e);
                }
            }
            else
            {
                var e = new IrcUserMessageEventArgs(targetedMessage);

                if (targetedMessage.Type == IrcTargetedMessage.MessageType.Privmsg)
                {
                    client.OnUserMessageReceived(e);
                }
                else if (targetedMessage.Type == IrcTargetedMessage.MessageType.Notice)
                {
                    client.OnUserNoticeReceived(e);
                }
            }

            return(Task.CompletedTask);
        }
Beispiel #2
0
 public IrcUser(IrcClient client, string nickName) : this(client, nickName, null, null)
 {
 }
Beispiel #3
0
 public IrcUser(IrcClient client, string nickName, string ident) : this(client, nickName, ident, null)
 {
 }
Beispiel #4
0
 /// <summary>
 ///     Initializes a new instance of <see cref="IrcUser"/>
 /// </summary>
 /// <param name="hostMask">The parsed hostmask of the user</param>
 public IrcUser(IrcClient client, IrcHostMask hostMask) : this(client, hostMask.NickName, hostMask.Ident, hostMask.Host)
 {
 }
Beispiel #5
0
 public TwitchUser(IrcClient client, string userName, Dictionary <string, string> tags) : base(client, userName)
 {
     Init(tags);
 }
Beispiel #6
0
 public TwitchUser(IrcClient client, string userName, string displayName, int userID) : base(client, userName)
 {
     DisplayName = displayName;
     ID          = userID;
 }
Beispiel #7
0
 public TwitchUser(IrcClient client, IrcHostMask hostMask, Dictionary <string, string> tags) : base(client, hostMask)
 {
     Init(tags);
 }
Beispiel #8
0
 internal TwitchChannel(IrcClient client, string name) : base(client, name)
 {
 }
Beispiel #9
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);
        }
Beispiel #10
0
 /// <summary>
 ///     Initializes a new instance of <see cref="IrcChannel"/>.
 /// </summary>
 /// <param name="client">A reference to the <see cref="IrcClient"/> instance.</param>
 /// <param name="name">The name of the channel-</param>
 public IrcChannel(IrcClient client, string name)
 {
     Client = client;
     Name   = name;
 }
Beispiel #11
0
        /// <summary>
        ///     Initializes a new instance of <see cref="IrcTargetedMessage"/>.
        /// </summary>
        /// <param name="message"></param>
        public IrcTargetedMessage(IrcClient client, IrcMessage message)
        {
            if (message.Prefix == null)
            {
                throw new ArgumentException("Message contains no prefix.");
            }

            if (message.Parameters.Length < 2)
            {
                throw new ArgumentException("The message needs to have 2 parameters to specify the target and the message.");
            }

            if (message.Command == "PRIVMSG")
            {
                Type = MessageType.Privmsg;
            }
            else if (message.Command == "NOTICE")
            {
                Type = MessageType.Notice;
            }
            else
            {
                Type = MessageType.Unknown;
            }

            IrcHostMask hostMask = IrcHostMask.Parse(message.Prefix);

            if (hostMask != null)
            {
                if (client is TwitchIrcClient)
                {
                    Source = new TwitchUser(client, hostMask, message.Tags);
                }
                else
                {
                    Source = new IrcUser(client, hostMask);
                }
            }
            else
            {
                Source = new IrcServer(message.Prefix);
            }

            if (message.Parameters[0].StartsWith("#"))
            {
                string channelName = message.Parameters[0].Substring(1);

                if (client.Channels.ContainsKey(channelName))
                {
                    Target = client.Channels[channelName];
                }
                else
                {
                    Debug.WriteLine("[IrcTargetedMessage] Could not find the targeted channel in the client's channels list.");
                }

                IsChannelMessage = true;
            }
            else
            {
                Target = client.User;
            }

            Tags    = message.Tags;
            Message = message.Parameters[1];
            Client  = client;
        }