Exemple #1
0
        private async Task UpdateSingleAsync(NumberToUpdate type, string num, string displayName)
        {
            if (!Utils.VerifyNumber(num))
            {
                _client.SendMessageAt(displayName, "Specified number is invalid");
                return;
            }

            _winLossAllowed &= num != "-1";

            if (await SendRecordApiCallAsync(type, num))
            {
                _client.SendMessageAt(displayName, "Updated successfully");
                _winLossTimer = new Timer(ResetWinLossAllowed, null, TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(-1));
            }
            else
            {
                _client.SendMessageAt(displayName, "Not updated, something went wrong. You know who to bug.");
                _winLossAllowed = true;
            }
        }
Exemple #2
0
        private async Task <bool> SendRecordApiCallAsync(NumberToUpdate type, string num)
        {
            var url = _config["WinLossApiBaseUrl"];

            switch (type)
            {
            case NumberToUpdate.Wins:
                url += "wins/";
                break;

            case NumberToUpdate.Losses:
                url += "losses/";
                break;

            case NumberToUpdate.Draws:
                url += "draws/";
                break;

            case NumberToUpdate.Clear:
                url += "clear";
                break;
            }

            if (type != NumberToUpdate.Clear)
            {
                url += num;
            }

            Utils.LogToConsole($"Sending record API call to {url}");

            var request = new HttpRequestMessage(HttpMethod.Put, url);

            request.Headers.Authorization = new AuthenticationHeaderValue(_config["FitzyApiKey"]);

            var response = await _httpClient.SendAsync(request);

            // timer ensures there won't be multiple calls made at once, this log line is okay
            Utils.LogToConsole($"Previous API call succeeded: {response.IsSuccessStatusCode}");
            return(response.IsSuccessStatusCode);
        }