コード例 #1
0
        private async Task SetStateAsync(TradeState state, string prepend = "")
        {
            if (State != state)
            {
                LastState = State;
                State     = state;
            }

            var content = new StringBuilder();

            if (!string.IsNullOrWhiteSpace(prepend))
            {
                content.AppendLine(prepend);
            }

            switch (state)
            {
            case TradeState.Menu:
                content.Append(WriteTradeMenu());
                break;

            case TradeState.Inventory:
                if (!CurrentId.HasValue)
                {
                    throw new Exception("Cannot read the inventory of an empty primary ID");
                }

                content.Append(WriteInventory(GetAccount(CurrentId.Value)));
                break;

            case TradeState.Success:
                content.AppendLine("> ✅ **Success!**\n> The trade has successfully gone through.");
                content.Append(WriteTradeResult());
                Host.AddToVar(Stats.TimesTraded);
                Participant.AddToVar(Stats.TimesTraded);
                break;
            }

            await UpdateMessageAsync(content.ToString());
        }