Fixes sending of rewards to bot

This commit is contained in:
benbierens 2024-02-19 15:57:28 +01:00
parent 42d3c5cd2c
commit 23b7bbd548
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
1 changed files with 8 additions and 4 deletions

View File

@ -2,6 +2,7 @@
using DiscordRewards;
using Logging;
using Newtonsoft.Json;
using System.Net.Http.Json;
namespace TestNetRewarder
{
@ -26,7 +27,9 @@ namespace TestNetRewarder
public async Task<bool> SendRewards(GiveRewardsCommand command)
{
if (command == null || command.Rewards == null || !command.Rewards.Any()) return false;
return await HttpPost(JsonConvert.SerializeObject(command)) == "OK";
var result = await HttpPostJson(command);
log.Log("Reward response: " + result);
return result == "OK";
}
private async Task<string> HttpGet()
@ -44,12 +47,13 @@ namespace TestNetRewarder
}
}
private async Task<string> HttpPost(string content)
private async Task<string> HttpPostJson<T>(T body)
{
try
{
var client = new HttpClient();
var response = await client.PostAsync(GetUrl(), new StringContent(content));
using var client = new HttpClient();
using var content = JsonContent.Create(body);
using var response = await client.PostAsync(GetUrl(), content);
return await response.Content.ReadAsStringAsync();
}
catch (Exception ex)