Exemplo n.º 1
0
        internal void Process(ReceivedCommandEventArgs args)
        {
            var argsGiven     = ArgNames.ToList();
            var processedArgs = new Dictionary <string, string>();

            if (argsGiven.Count == 0)
            {
                _callback(args.ArgString, new ReadOnlyDictionary <string, string>(processedArgs), args.Connection, args.Respond);
                return;
            }

            foreach (var valuePair in args.Args.Where(kvp => !string.IsNullOrEmpty(kvp.Key)))
            {
                if (argsGiven.Contains(valuePair.Key))
                {
                    argsGiven.Remove(valuePair.Key);
                    processedArgs.Add(valuePair.Key, valuePair.Value);
                }
                else
                {
                    args.Respond("Command has invalid arguments");
                    return;
                }
            }

            foreach (var valuePair in args.Args.Where(kvp => string.IsNullOrEmpty(kvp.Key)))
            {
                if (argsGiven.Count > 0)
                {
                    var key = argsGiven[0];
                    argsGiven.RemoveAt(0);
                    processedArgs.Add(key, valuePair.Value);
                }
                else
                {
                    args.Respond("Command has invalid arguments");
                    return;
                }
            }

            _callback(args.ArgString, new ReadOnlyDictionary <string, string>(processedArgs), args.Connection, args.Respond);
        }
Exemplo n.º 2
0
 private void OnReceivedCommand(ReceivedCommandEventArgs args)
 {
     ReceivedCommand?.Invoke(this, args);
 }