Represents the result of a parsing operation.
Example #1
0
        /// <summary>
        /// Attempts to parse the input specified by the user into the Message.
        /// </summary>
        /// <param name="input">The input from the user.</param>
        /// <returns>True on success, false on failure.</returns>
        public override ParseResult TryParse(string input)
        {
            ParseResult retval;
            string pattern = @"/names(\s+(?<channel>[#&!\+][^\x07\x2C\s]{1,199}))?";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(input);

            if (match.Success)
            {
                string channel = this.ChannelName;
                if (match.Groups["channel"].Success)
                {
                    channel = match.Groups["channel"].Value;
                }

                if (string.IsNullOrEmpty(channel))
                {
                    retval = new ParseResult(false, Strings_MessageParseResults.Names_MissingChannel);
                }
                else
                {
                    this.Parameters = new string[] { channel };
                    retval = new ParseResult(true, string.Empty);
                }
            }
            else
            {
                retval = new ParseResult(false, string.Empty);
            }

            return retval;
        }
Example #2
0
        /// <summary>
        /// Attempts to parse the input specified by the user into the Message.
        /// </summary>
        /// <param name="input">The input from the user.</param>
        /// <returns>True on success, false on failure.</returns>
        public override ParseResult TryParse(string input)
        {
            ParseResult retval;
            string pattern = @"/userhost\s+(?<nicknames>.+)";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(input);

            if (match.Success)
            {
                string[] nicknames = match.Groups["nicknames"].Value.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (nicknames.GetLength(0) > 0)
                {
                    this.Parameters = nicknames;
                    retval = new ParseResult(true, string.Empty);
                }
                else
                {
                    retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Nickname);
                }
            }
            else
            {
                retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Nickname);
            }

            return retval;
        }
Example #3
0
        /// <summary>
        /// Attempts to parse the input specified by the user into the Message.
        /// </summary>
        /// <param name="input">The input from the user.</param>
        /// <returns>True on success, false on failure.</returns>
        public override ParseResult TryParse(string input)
        {
            ParseResult retval;
            string pattern = @"/who\s+(?<mask>.+)";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(input);

            if (match.Success)
            {
                this.Parameters = match.Groups["mask"].Value.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                if (this.Parameters.Length > 0)
                {
                    retval = new ParseResult(true, string.Empty);
                }
                else
                {
                    retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Mask);
                }
            }
            else
            {
                retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Mask);
            }

            return retval;
        }
Example #4
0
        /// <summary>
        /// Attempts to parse the input specified by the user into the Message.
        /// </summary>
        /// <param name="input">The input from the user.</param>
        /// <returns>True on success, false on failure.</returns>
        public override ParseResult TryParse(string input)
        {
            ParseResult retval;
            string pattern = @"/ping\s+(?<nickname>[^\s]+)";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(input);

            if (match.Success)
            {
                this.Parameters = new string[] { match.Groups["nickname"].Value };
                retval = new ParseResult(true, string.Empty);
            }
            else
            {
                retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Nickname);
            }

            return retval;
        }
Example #5
0
        /// <summary>
        /// Attempts to parse the input specified by the user into the Message.
        /// </summary>
        /// <param name="input">The input from the user.</param>
        /// <returns>True on success, false on failure.</returns>
        public override ParseResult TryParse(string input)
        {
            ParseResult retval;
            string pattern = @"PING\s+:(?<daemon>.+)";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(input);

            if (match.Success)
            {
                this.TrailingParameter = match.Groups["daemon"].Value.RemoveCarriageReturns();
                retval = new ParseResult(true, string.Empty);
            }
            else
            {
                retval = new ParseResult(false, string.Empty);
            }

            return retval;
        }
Example #6
0
        /// <summary>
        /// Attempts to parse the input specified by the user into the Message.
        /// </summary>
        /// <param name="input">The input from the user.</param>
        /// <returns>True on success, false on failure.</returns>
        public override ParseResult TryParse(string input)
        {
            ParseResult retval;
            string pattern = @"/knock\s+(?<channel>[#&][^\x07\x2C\s]{1,199})(\s+(?<reason>.+))?";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(input);

            if (match.Success)
            {
                if (match.Groups["reason"].Success)
                {
                    this.TrailingParameter = match.Groups["reason"].Value;
                }

                this.Parameters = new string[] { match.Groups["channel"].Value };
                retval = new ParseResult(true, string.Empty);
            }
            else
            {
                retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Channel);
            }

            return retval;
        }
Example #7
0
        /// <summary>
        /// Parse a voice command into the message.
        /// </summary>
        /// <param name="payload">The raw voice command.</param>
        /// <returns>A <see cref="ParseResult"/> that contains the result of the operation.</returns>
        private ParseResult ParseVoiceCommand(string payload)
        {
            ParseResult retval;
            string pattern = @"/voice\s+(?<mask>.+)";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(payload);

            if (match.Success)
            {
                if (string.IsNullOrEmpty(this.ChannelName))
                {
                    retval = new ParseResult(false, Strings_MessageParseResults.Voice_InvalidContext);
                }
                else
                {
                    this.Parameters = new string[] { this.ChannelName, "+v", match.Groups["mask"].Value };
                    retval = new ParseResult(true, string.Empty);
                }
            }
            else
            {
                retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Nickname);
            }

            return retval;
        }
Example #8
0
        /// <summary>
        /// Parse a deop/dehop/hop/op command into the message.
        /// </summary>
        /// <param name="payload">The raw deop/dehop/hop/op command.</param>
        /// <returns>A <see cref="ParseResult"/> that contains the result of the operation.</returns>
        private ParseResult ParseOpCommand(string payload)
        {
            ParseResult retval;
            string pattern = @"/(?<command>deop|dehop|hop|op)\s+((?<channel>[#&!\+][^\x07\x2C\s]{1,199})\s+)?(?<nickname>.+)";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(payload);

            if (match.Success)
            {
                string modifier = match.Groups["command"].Value.StartsWith("de") ? "-" : "+";
                string mode = match.Groups["command"].Value.EndsWith("hop") ? "h" : "o";
                string channel = this.ChannelName;

                if (match.Groups["channel"].Success)
                {
                    channel = match.Groups["channel"].Value;
                }

                this.Parameters = new string[] { channel, modifier + mode, match.Groups["nickname"].Value };
                retval = new ParseResult(true, string.Empty);
            }
            else
            {
                retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Nickname);
            }

            return retval;
        }
Example #9
0
        /// <summary>
        /// Parse a mode command into the message.
        /// </summary>
        /// <param name="payload">The raw mode command.</param>
        /// <returns>A <see cref="ParseResult"/> that contains the result of the operation.</returns>
        private ParseResult ParseModeCommand(string payload)
        {
            ParseResult retval;
            string pattern = @"/mode(\s+(?<target>[^\s]+))?(\s+(?<modestr>[^\s]+))?(\s+(?<args>.+))?";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(payload);

            if (match.Success)
            {
                List<string> parameters = new List<string>();

                if (match.Groups["target"].Success)
                {
                    parameters.Add(match.Groups["target"].Value);

                    if (match.Groups["modestr"].Success)
                    {
                        parameters.Add(match.Groups["modestr"].Value);

                        if (match.Groups["args"].Success)
                        {
                            parameters.AddRange(match.Groups["args"].Value.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries));
                        }
                    }
                }

                this.Parameters = parameters.ToArray();
                retval = new ParseResult(true, string.Empty);
            }
            else
            {
                retval = new ParseResult(false, string.Empty);
            }

            return retval;
        }
Example #10
0
        /// <summary>
        /// Parse an except/unexcept command into the message.
        /// </summary>
        /// <param name="payload">The raw except/unexcept command.</param>
        /// <returns>A <see cref="ParseResult"/> that contains the result of the operation.</returns>
        private ParseResult ParseExceptCommand(string payload)
        {
            ParseResult retval;
            string pattern = @"/(?<command>except|unexcept)(\s+(?<mask>.+))?";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(payload);

            if (match.Success)
            {
                if (string.IsNullOrEmpty(this.ChannelName))
                {
                    string resultMessage = match.Groups["command"].Value.Equals("except", StringComparison.OrdinalIgnoreCase) ?
                                                        Strings_MessageParseResults.Except_InvalidContext :
                                                        Strings_MessageParseResults.Unexcept_InvalidContext;
                    retval = new ParseResult(false, resultMessage);
                }
                else
                {
                    // If we have a mask then we need to except it, otherwise
                    // the user is requesting a list of exceptions on the channel
                    // that the message has been instantiated on
                    if (match.Groups["mask"].Success)
                    {
                        if (match.Groups["command"].Value.Equals("except", StringComparison.OrdinalIgnoreCase))
                        {
                            this.Parameters = new string[] { this.ChannelName, "+e", match.Groups["mask"].Value };
                        }
                        else
                        {
                            this.Parameters = new string[] { this.ChannelName, "-e", match.Groups["mask"].Value };
                        }

                        retval = new ParseResult(true, string.Empty);
                    }
                    else
                    {
                        if (match.Groups["command"].Value.Equals("except", StringComparison.OrdinalIgnoreCase))
                        {
                            this.Parameters = new string[] { this.ChannelName, "+e" };
                            retval = new ParseResult(true, string.Empty);
                        }
                        else
                        {
                            retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Nickname);
                        }
                    }
                }
            }
            else
            {
                retval = new ParseResult(false, string.Empty);
            }

            return retval;
        }
Example #11
0
        /// <summary>
        /// Parse a ban command into the message.
        /// </summary>
        /// <param name="payload">The raw ban command.</param>
        /// <returns>A <see cref="ParseResult"/> that contains the result of the operation.</returns>
        private ParseResult ParseBanCommand(string payload)
        {
            ParseResult retval;
            string pattern = @"/(?<command>ban|unban)(\s+(?<mask>.+))?";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(payload);

            if (match.Success)
            {
                if (string.IsNullOrEmpty(this.ChannelName))
                {
                    retval = new ParseResult(false, match.Groups["command"].Value.Equals("ban", StringComparison.OrdinalIgnoreCase) ? Strings_MessageParseResults.Ban_InvalidContext : Strings_MessageParseResults.Unban_InvalidContext);
                }
                else
                {
                    // If we have a mask then we need to ban or unban it, otherwise
                    // the user is requesting a list of bans on the channel
                    // that the message has been instantiated on
                    if (match.Groups["mask"].Success)
                    {
                        if (match.Groups["command"].Value.Equals("ban", StringComparison.OrdinalIgnoreCase))
                        {
                            this.Parameters = new string[] { this.ChannelName, "+b", match.Groups["mask"].Value };
                        }
                        else
                        {
                            this.Parameters = new string[] { this.ChannelName, "-b", match.Groups["mask"].Value };
                        }

                        retval = new ParseResult(true, string.Empty);
                    }
                    else
                    {
                        // The lack of a mask is only valid if we are using /ban
                        if (match.Groups["command"].Value.Equals("ban", StringComparison.OrdinalIgnoreCase))
                        {
                            this.Parameters = new string[] { this.ChannelName, "+b" };
                            retval = new ParseResult(true, string.Empty);
                        }
                        else
                        {
                            retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Nickname);
                        }
                    }
                }
            }
            else
            {
                retval = new ParseResult(false, string.Empty);
            }

            return retval;
        }
Example #12
0
        /// <summary>
        /// Parses <paramref name="command"/> and returns a <see cref="ParseResult"/> object to indicate the result of the operation
        /// </summary>
        /// <param name="command">The command issued by the user to parse</param>
        /// <returns><see cref="ParseResult"/></returns>
        public ParseResult Parse(string command)
        {
            ParseResult retval;

            string server = null;
            int port = 6667;
            string portString = null;
            string password = null;

            Regex regex = new Regex(@"/(server|connect)(\s+)(?<server>[a-zA-Z\.0-9\-]+)(((\s+)(?<port>[0-9]+))?((\s+)(?<password>.*))?)?", RegexOptions.IgnoreCase);
            MatchCollection matches = regex.Matches(command);

            if (matches.Count > 0)
            {
                server = matches[0].Groups["server"].Value;
                portString = matches[0].Groups["port"].Value;
                password = matches[0].Groups["password"].Value.RemoveCarriageReturns();
            }

            if (string.IsNullOrEmpty(server))
            {
                retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Server);
            }
            else if ((!string.IsNullOrEmpty(portString)) && (!int.TryParse(portString, out port)))
            {
                retval = new ParseResult(false, Strings_MessageParseResults.Server_InvalidPort);
            }
            else
            {
                this.server = server;
                this.port = port;

                if (!string.IsNullOrEmpty(password))
                {
                    this.password = password;
                }

                retval = new ParseResult(true, string.Empty);
            }

            return retval;
        }
Example #13
0
        /// <summary>
        /// Attempts to parse the input specified by the user into the Message.
        /// </summary>
        /// <param name="input">The input from the user.</param>
        /// <returns>True on success, false on failure.</returns>
        public override ParseResult TryParse(string input)
        {
            ParseResult retval;
            string pattern = @"/kick\s(?<nickname>[^\s]+)+?(\s(?<reason>.+))?";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(input);

            if (match.Success)
            {
                this.Parameters = new string[] { this.ChannelName, match.Groups["nickname"].Value };

                if (match.Groups["reason"].Success)
                {
                    this.TrailingParameter = match.Groups["reason"].Value;
                }

                retval = new ParseResult(true, string.Empty);
            }
            else
            {
                retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Nickname);
            }

            return retval;
        }
Example #14
0
        /// <summary>
        /// Parse a private message.
        /// </summary>
        /// <param name="payload">The raw message.</param>
        /// <returns>A <see cref="ParseResult"/> that contains the result of the operation.</returns>
        private ParseResult ParsePrivateMessage(string payload)
        {
            ParseResult retval;
            string pattern = @"/msg\s+(?<nickname>[^\s]+)\s+(?<message>.+)";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(payload);

            if (match.Success)
            {
                this.Parameters = new string[] { match.Groups["nickname"].Value };
                this.TrailingParameter = match.Groups["message"].Value;
                retval = new ParseResult(true, string.Empty);
            }
            else
            {
                retval = new ParseResult(false, Strings_MessageParseResults.MissingParameters);
            }

            return retval;
        }
Example #15
0
        /// <summary>
        /// Parse an action message.
        /// </summary>
        /// <param name="payload">The raw message.</param>
        /// <returns>A <see cref="ParseResult"/> that contains the result of the operation.</returns>
        private ParseResult ParseActionMessage(string payload)
        {
            ParseResult retval;
            string pattern = @"/me\s+(?<action>.+)";
            Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            Match match = regex.Match(payload);

            if (string.IsNullOrEmpty(this.ChannelName))
            {
                retval = new ParseResult(false, Strings_MessageParseResults.Me_InvalidContext);
            }
            else
            {
                if (match.Success)
                {
                    this.Parameters = new string[] { this.ChannelName };
                    this.TrailingParameter = string.Format("{0}ACTION {1}{0}", (char)1, match.Groups["action"].Value);
                    retval = new ParseResult(true, string.Empty);
                }
                else
                {
                    retval = new ParseResult(false, Strings_MessageParseResults.MissingParameter_Action);
                }
            }

            return retval;
        }
Example #16
0
        /// <summary>
        /// Attempts to parse the input specified by the user into the Message.
        /// </summary>
        /// <param name="input">The input from the user.</param>
        /// <returns>True on success, false on failure.</returns>
        public override ParseResult TryParse(string input)
        {
            ParseResult retval;
            if (string.IsNullOrEmpty(this.ChannelName))
            {
                retval = new ParseResult(false, Strings_MessageParseResults.Topic_MissingChannel);
            }
            else
            {
                string pattern = @"/topic(\s+(?<topic>.+))?";
                Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
                Match match = regex.Match(input);

                if (match.Success)
                {
                    this.Parameters = new string[] { this.ChannelName };

                    if (match.Groups["topic"].Success)
                    {
                        this.TrailingParameter = match.Groups["topic"].Value;
                    }

                    retval = new ParseResult(true, string.Empty);
                }
                else
                {
                    retval = new ParseResult(false, string.Empty);
                }
            }

            return retval;
        }