Example #1
0
        public static bool TryParse(string s, out CommandString result)
        {
            result = null;
            if (string.IsNullOrWhiteSpace(s) || s[0] != '/')
            {
                return(false);
            }

            string[] words = s.Split(WS_CHARS, StringSplitOptions.RemoveEmptyEntries);

            var cmdRegex = new Regex(@"/(?<cmd>\w+)(@(?<name>\w+))?");
            var match    = cmdRegex.Match(words.First());

            if (!match.Success)
            {
                return(false);
            }

            string cmd      = match.Groups["cmd"].Captures[0].Value;
            string username = match.Groups["name"].Captures.Count > 0 ? match.Groups["name"].Captures[0].Value : null;

            string[] parameters = words.Skip(1).ToArray();

            result = new CommandString(cmd, username, parameters);
            return(true);
        }
        public string Execute(CommandString cmd, MessageEventArgs args)
        {
            var word = cmd.Parameters.FirstOrDefault();

            if (string.IsNullOrWhiteSpace(word))
            {
                return(null);
            }

            if (!Regex.IsMatch(word, @"[а-яА-Я]+"))
            {
                return(null);
            }

            bool newWord = Dict.Learn(word);

            return(newWord ? $"Принято слово \"{word}\"" : $"Поднял рейтинг слову \"{word}\"");
        }
Example #3
0
        public string Execute(CommandString cmd, MessageEventArgs args)
        {
            var word = cmd.Parameters.FirstOrDefault();

            if (string.IsNullOrWhiteSpace(word))
            {
                return(null);
            }

            if (!Regex.IsMatch(word, @"[а-яА-Я]+"))
            {
                return(null);
            }
            if (Dict.Unlearn(word))
            {
                return($"Удалил слово \"{word}\"");
            }
            else
            {
                return($"Не нашел слово \"{word}\"");
            }
        }