<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace RMUD
{
	public class ParserCommandHandler : IClientCommandHandler
	{
		internal CommandParser Parser;

		public ParserCommandHandler()
		{
			Parser = new CommandParser();

			//Iterate over all types, find ICommandFactories, Create commands
			foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
			{
				if (type.IsSubclassOf(typeof(CommandFactory)))
				{
					var instance = Activator.CreateInstance(type) as CommandFactory;
					instance.Create(Parser);
				}
			}
		}

        public void HandleCommand(Client Client, String Command)
        {
            if (String.IsNullOrEmpty(Command)) return;

            if (Command[0] == '@')
            {
                #region Handle debug command

                var tokens = Command.Split(' ');
                if (tokens.Length == 0) return;

                if (tokens[0].ToUpper() == "@MATCH")
                {
                    var startTime = DateTime.Now;
                    var matches = Parser.ParseCommand(Command.Substring(7), Client.Player);
                    var endTime = DateTime.Now;
                    Client.Send(String.Format("Matched {0} in {1:n0} milliseconds. {2} unique matches.\r\n",
                        matches.Command.Processor.GetType().Name,
                        (endTime - startTime).TotalMilliseconds,
                        matches.Matches.Count));
                    foreach (var match in matches.Matches)
                    {
                        var builder = new StringBuilder();

                        foreach (var arg in match.Arguments)
                        {
                            builder.Append("[");
                            builder.Append(arg.Key);
                            builder.Append(" : ");
                            builder.Append(arg.Value.ToString());
                            builder.Append("] ");
                        }

                        builder.Append("\r\n");

                        Client.Send(builder.ToString());<commit_msg>Fix bug where @match threw exception when nothing was matched.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace RMUD
{
	public class ParserCommandHandler : IClientCommandHandler
	{
		internal CommandParser Parser;

		public ParserCommandHandler()
		{
			Parser = new CommandParser();

			//Iterate over all types, find ICommandFactories, Create commands
			foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
			{
				if (type.IsSubclassOf(typeof(CommandFactory)))
				{
					var instance = Activator.CreateInstance(type) as CommandFactory;
					instance.Create(Parser);
				}
			}
		}

        public void HandleCommand(Client Client, String Command)
        {
            if (String.IsNullOrEmpty(Command)) return;

            if (Command[0] == '@')
            {
                #region Handle debug command

                var tokens = Command.Split(' ');
                if (tokens.Length == 0) return;

                if (tokens[0].ToUpper() == "@MATCH")
                {
                    var startTime = DateTime.Now;
                    var matches = Parser.ParseCommand(Command.Substring(7), Client.Player);
                    var endTime = DateTime.Now;

                    if (matches == null)
                    {
                        Client.Send(String.Format("Matched nothing in {0:n0} milliseconds.\r\n",
                            (endTime - startTime).TotalMilliseconds));
                    }
                    else
                    {
                        Client.Send(String.Format("Matched {0} in {1:n0} milliseconds. {2} unique matches.\r\n",
                            matches.Command.Processor.GetType().Name,
                            (endTime - startTime).TotalMilliseconds,
                            matches.Matches.Count));
                        foreach (var match in matches.Matches)
                        {
                            var builder = new StringBuilder();

                            foreach (var arg in match.Arguments)
                            {
                                builder.Append("[");
                                builder.Append(arg.Key);
                                builder.Append(" : ");
                                builder.Append(arg.Value.ToString());
                                builder.Append("] ");
                            }

                            builder.Append("\r\n");

                            Client.Send(builder.ToString());
                        }
{'fraction_non_alphanumeric': 0.09860347016504444, 'fraction_numerical': 0.003808717731696995, 'mean_word_length': 1.3682364729458918, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5872158', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1070, 'n_words': 245}