예제 #1
0
        /// <summary>
        ///     Used to confirm if a user wants to submit their playtest request, or make further changes.
        /// </summary>
        /// <returns></returns>
        private async Task ConfirmRequest()
        {
            while (true)
            {
                var isValid = false;
                var index   = -1;
                await Display(
                    "Type the ID of the field you want to edit or type `Submit` to submit your playtest request.");

                _userMessage = await _interactive.NextMessageAsync(_context);

                if (_userMessage == null ||
                    _userMessage.Content.Equals("exit", StringComparison.OrdinalIgnoreCase))
                {
                    await CancelRequest();

                    return;
                }

                if (_userMessage.Content.Equals("submit", StringComparison.OrdinalIgnoreCase))
                {
                    if (_testRequest.Preferredserver != "No preference" && !_testRequest.Game.Equals(
                            DatabaseUtil.GetTestServer(_testRequest.Preferredserver).Game,
                            StringComparison.OrdinalIgnoreCase))
                    {
                        index   = 11;
                        isValid = true;
                    }
                    else
                    {
                        break;
                    }
                }

                if (!isValid)
                {
                    isValid = int.TryParse(_userMessage.Content, out index);
                }

                if (isValid && index >= 0 && index <= _arrayValues.Length)
                {
                    var valid = false;
                    await Display(_wizardText[index]);

                    while (!valid)
                    {
                        _userMessage = await _interactive.NextMessageAsync(_context);

                        valid = await ParseTestInformation(_arrayValues[index], _userMessage.Content);

                        if (_userMessage == null ||
                            _userMessage.Content.Equals("exit", StringComparison.OrdinalIgnoreCase))
                        {
                            await CancelRequest();

                            return;
                        }
                    }
                }
            }

            //Avoid rate limiting
            await Task.Delay(1000);

            //Attempt to store request in the DB
            if (DatabaseUtil.AddPlaytestRequests(_testRequest))
            {
                await _instructionsMessage.ModifyAsync(x =>
                                                       x.Content =
                                                       $"Request Submitted! If you have any feedback or suggestions of the scheduling process, please send {_dataService.AlertUser} a message!");

                await _embedMessage.ModifyAsync(x => x.Embed = RebuildEmbed().WithColor(240, 240, 240).Build());

                //Give them the quick request if they want to re-test.
                try
                {
                    //Try DM
                    await _context.User.SendMessageAsync(
                        $"Here is a quick request for your test to quickly submit again if something happens with this test.```>Request {_testRequest}```");
                }
                catch
                {
                    //Just reply instead
                    await _context.Channel.SendMessageAsync(
                        $"Here is a quick request for your test to quickly submit again if something happens with this test.```>Request {_testRequest}```");
                }

                var schedule = await _playtestService.GetUpcomingEvents(true, false);

                var creators = "";
                foreach (var c in _testRequest.CreatorsDiscord)
                {
                    creators += _dataService.GetSocketGuildUser(c).Mention + " ";
                }

                //Set as alert user just in case.
                var testingAdminMention = _dataService.AlertUser.Mention;
                var mentionChannel      = _dataService.AdminBotsChannel;

                if (_testRequest.Game.Equals("csgo", StringComparison.OrdinalIgnoreCase))
                {
                    testingAdminMention = _dataService.CSGOPlaytestAdmin.Mention;
                    mentionChannel      = _dataService.CSGOTestingChannel;
                }
                else if (_testRequest.Game.Equals("tf2", StringComparison.OrdinalIgnoreCase))
                {
                    testingAdminMention = _dataService.TF2PlaytestAdmin.Mention;
                    mentionChannel      = _dataService.TF2TestingChannel;
                }

                await _dataService.AdminBotsChannel.SendMessageAsync(
                    $"{testingAdminMention} a new playtest request for `{_testRequest.MapName}` has been submitted by {creators.Trim()}!",
                    embed : schedule.Build());

                //Users to mention.
                string mentions = null;
                _testRequest.CreatorsDiscord.ForEach(x => mentions += $"{_dataService.GetSocketGuildUser(x).Mention} ");

                var embed = await _workshop.HandleWorkshopEmbeds(_context.Message,
                                                                 $"[Map Images]({_testRequest.ImgurAlbum}) | [Playtesting Information](https://www.tophattwaffle.com/playtesting)",
                                                                 _testRequest.TestType, GeneralUtil.GetWorkshopIdFromFqdn(_testRequest.WorkshopURL));

                if (embed != null)
                {
                    await mentionChannel.SendMessageAsync($"{mentions} has submitted a playtest request!",
                                                          embed : embed.Build());
                }
                else
                {
                }

                await _log.LogMessage($"{_context.User} has requested a playtest!\n{_testRequest}", color : LOG_COLOR);
            }
            else
            {
                //Failed adding to the database. Give them a quick request to attempt resubmission later.
                await _instructionsMessage.ModifyAsync(x =>
                                                       x.Content = "An error occured creating the playtest request!");

                await _embedMessage.ModifyAsync(x => x.Embed = RebuildEmbed().WithColor(25, 25, 25).Build());

                //Give them the quick request if they want to re-test.
                try
                {
                    //Try DM
                    await _context.User.SendMessageAsync(
                        $"Here is a quick request for your test to quickly submit again later.```>Request {_testRequest}```");
                }
                catch
                {
                    //Just reply instead
                    await _context.Channel.SendMessageAsync(
                        $"Here is a quick request for your test to quickly submit again later.```>Request {_testRequest}```");
                }
            }
        }