mirror of
https://github.com/yawaflua/PL_JusticeBot.git
synced 2025-12-08 19:39:27 +02:00
add auto gived avance
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
|
||||
<PackageReference Include="spworlds" Version="1.0.5" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
|
||||
@@ -3,7 +3,9 @@ using Discord.Interactions;
|
||||
using Discord.WebSocket;
|
||||
using DiscordApp.Database;
|
||||
using DiscordApp.Database.Tables;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
|
||||
using Microsoft.OpenApi.Any;
|
||||
using System.Net;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace DiscordApp.Discord.Commands
|
||||
{
|
||||
@@ -82,17 +84,95 @@ namespace DiscordApp.Discord.Commands
|
||||
int allCount = 0;
|
||||
var allReports = Startup.appDbContext.Reports.ToArray();
|
||||
var allEmployee = new Dictionary<string, int>();
|
||||
string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijk0NTMxNzgzMjI5MDMzNjc5OCIsInRva2VuVmVyc2lvbiI6MCwiaXAiOiIxODUuMTA0LjExMi4xODAiLCJpYXQiOjE2OTkxOTA5MzMsImV4cCI6MTcwMTc4MjkzM30.Z9ykVYIIsN0bF0BlNV6sgwdiRu-GNx-olmKRxl6OJHk";
|
||||
var cookieContainer = new CookieContainer();
|
||||
var handler = new HttpClientHandler() { CookieContainer = cookieContainer };
|
||||
HttpClient client = new(handler);
|
||||
client.BaseAddress = new Uri("https://spworlds.ru/api/");
|
||||
|
||||
cookieContainer.Add(client.BaseAddress, new Cookie("jeff", token));
|
||||
string ok = @"{
|
||||
""id"": ""945317832290336798"",
|
||||
""isAdmin"": false,
|
||||
""minecraftUUID"": ""775f00d30da34275967d58cb50838b9f"",
|
||||
""accounts"": [
|
||||
{
|
||||
""id"": ""095ee127-578b-479e-90af-21b679546e09"",
|
||||
""serverId"": ""spb"",
|
||||
""roles"": [],
|
||||
""isBanned"": false,
|
||||
""banReason"": null,
|
||||
""server"": {
|
||||
""id"": ""spb"",
|
||||
""name"": ""СПб"",
|
||||
""icon"": 1,
|
||||
""hasSite"": true,
|
||||
""economy"": {
|
||||
""campaignPrice"": 32,
|
||||
""pinPrice"": 0,
|
||||
""adPrice"": 32
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
""id"": ""96a89c09-63a1-44e9-9e10-abbf9f78483c"",
|
||||
""serverId"": ""pl"",
|
||||
""roles"": [
|
||||
""mapmaker""
|
||||
],
|
||||
""isBanned"": false,
|
||||
""banReason"": null,
|
||||
""server"": {
|
||||
""id"": ""pl"",
|
||||
""name"": ""PoopLand"",
|
||||
""icon"": 4,
|
||||
""hasSite"": true,
|
||||
""economy"": {
|
||||
""campaignPrice"": 32,
|
||||
""pinPrice"": 0,
|
||||
""adPrice"": 32
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
""bedrockUsername"": ""YaFlay"",
|
||||
""username"": ""YaFlay"",
|
||||
""hasTOTP"": false
|
||||
}";
|
||||
var content = new StringContent(ok) ;
|
||||
await client.PostAsync("auth/refresh_token", content);
|
||||
|
||||
|
||||
foreach (var report in allReports)
|
||||
{
|
||||
allEmployee[report.Employee] += (int)report.type;
|
||||
if (allEmployee.TryGetValue(report.Employee, out _))
|
||||
{
|
||||
allEmployee[report.Employee] += (int)report.type;
|
||||
}
|
||||
else
|
||||
{
|
||||
allEmployee.Add(report.Employee, (int)report.type);
|
||||
}
|
||||
|
||||
}
|
||||
foreach (var employee in allEmployee)
|
||||
{
|
||||
await Startup.sp.CreateTransaction(employee.Key, employee.Value, "АвтоЗарплата Юстиций");
|
||||
allCount += employee.Value;
|
||||
try
|
||||
{
|
||||
var request = await client.GetAsync($"pl/accounts/{employee.Key}");
|
||||
Console.WriteLine(request.Content.ReadAsStringAsync().Result);
|
||||
JsonNode response = await request.Content.ReadFromJsonAsync<JsonNode>();
|
||||
|
||||
await Startup.sp.CreateTransaction(response["cardsOwned"][0]["number"].ToString(), employee.Value, $"zp {employee.Key}");
|
||||
await Console.Out.WriteLineAsync($"{employee.Key}, {employee.Value}");
|
||||
allCount += employee.Value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error: {ex.Message}, {employee.Key}");
|
||||
}
|
||||
}
|
||||
await FollowupAsync($"Готово! Раздал {allCount} АР", ephemeral: true);
|
||||
await FollowupAsync($"Готово! Раздал {allCount} АР ||{allEmployee.ToArray()}||", ephemeral: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user