Example #1
0
        public static bool TryParseOffer(Discord.IUser user, Discord.IUser target, string input, out TradeOffer offer)
        {
            offer = null;

            input = input.Trim();
            var reader = new StringReader(input);

            // item,amount item,amount item

            bool requested = false;
            bool remainder = false;

            if (!reader.CanRead())
            {
                return(false); // throw new Exception("Expected a string to read but returned null");
            }
            var offered  = new Dictionary <string, int>();
            var requests = new Dictionary <string, int>();

            while (reader.CanRead())
            {
                string arg;
                int    amount = 1;

                if (!reader.GetRemaining().Contains(' '))
                {
                    arg       = reader.GetRemaining();
                    remainder = true;
                }
                else
                {
                    arg = reader.ReadUntil(' ');
                }

                if (arg == Separator)
                {
                    if (requested)
                    {
                        return(false); // throw new Exception("Offer separator has already been specified");
                    }
                    requested = true;
                    continue;
                }

                if (arg.Contains(','))
                {
                    if (arg.Count(x => x == ',') > 1)
                    {
                        return(false); // throw new Exception("Expected a single comma separator");
                    }
                    int.TryParse(arg[arg.IndexOf(',')..], out amount);