示例#1
0
        public TriviaGame(IBotStrings strings, DiscordSocketClient client, GamesConfig config,
                          IDataCache cache, ICurrencyService cs, IGuild guild, ITextChannel channel,
                          TriviaOptions options, string quitCommand)
        {
            _cache        = cache;
            _questionPool = new TriviaQuestionPool(_cache);
            _strings      = strings;
            _client       = client;
            _config       = config;
            _cs           = cs;
            _options      = options;
            _quitCommand  = quitCommand;

            Guild   = guild;
            Channel = channel;
        }
示例#2
0
        public TriviaGame(NadekoStrings strings, DiscordSocketClient client, IBotConfigProvider bc,
                          IDataCache cache, ICurrencyService cs, IGuild guild, ITextChannel channel,
                          TriviaOptions options)
        {
            _log          = LogManager.GetCurrentClassLogger();
            _cache        = cache;
            _questionPool = new TriviaQuestionPool(_cache);
            _strings      = strings;
            _client       = client;
            _bc           = bc;
            _cs           = cs;
            _options      = options;

            Guild   = guild;
            Channel = channel;
        }
示例#3
0
        public async Task <TriviaApiResult> GetTrivia(TriviaOptions options, TriviaDifficulty levels)
        {
            _categoryId = (int)options;
            _difficulty = levels.ToString().ToLower();
            string endpoint = $@"{_baseUrl}/api.php?amount=1&category={_categoryId}&difficulty={_difficulty}&type=multiple";

            using (HttpResponseMessage response = await _apiClient.GetAsync(endpoint))
            {
                if (response.IsSuccessStatusCode)
                {
                    Task <TriviaApiResult> triviaModel = response.Content.ReadAsAsync <TriviaApiResult>();
                    //var trivia = triviaModel.Result.Results.FirstOrDefault();

                    //if (trivia != null)
                    //{
                    //    //insert the correct answer in the random spot
                    //    Random rnd = new Random();
                    //    int idx = rnd.Next(0, 3);

                    //    var lst = trivia.Incorrect_Answers.Select(x => x).ToList();
                    //    lst.Insert(idx, trivia.Correct_Answer);

                    //    //add options A-D
                    //    var r = lst.Select((value, index) => $"{(char)(65+index)}. {value}");

                    //    //insert indentation
                    //    string result = r.Select(i => i).Aggregate((i, j) => i + "\r\n   " + j);
                    //    result = $"{trivia.Question}\r\n   {result}";

                    //    //remove quotations and apostrophes
                    //    return result.Replace("&#039;","'").Replace("&quot;","'");


                    //}

                    return(triviaModel.Result);
                }


                return(null);
            }
        }