From dd711dd7c3513e7ba3b0e5bc3d04a16d78e99a33 Mon Sep 17 00:00:00 2001 From: Mih4n <50325226+Mih4n@users.noreply.github.com> Date: Mon, 16 Oct 2023 19:17:13 +0300 Subject: [PATCH] sloved errors --- ...CoreApp,Version=v6.0.AssemblyAttributes.cs | 4 +++ src/obj/Debug/net6.0/spworlds.AssemblyInfo.cs | 25 +++++++++++++++++++ .../net6.0/spworlds.AssemblyInfoInputs.cache | 1 + ....GeneratedMSBuildEditorConfig.editorconfig | 11 ++++++++ .../Debug/net6.0/spworlds.GlobalUsings.g.cs | 8 ++++++ src/spworlds.cs | 18 ++----------- 6 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 src/obj/Debug/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs create mode 100644 src/obj/Debug/net6.0/spworlds.AssemblyInfo.cs create mode 100644 src/obj/Debug/net6.0/spworlds.AssemblyInfoInputs.cache create mode 100644 src/obj/Debug/net6.0/spworlds.GeneratedMSBuildEditorConfig.editorconfig create mode 100644 src/obj/Debug/net6.0/spworlds.GlobalUsings.g.cs diff --git a/src/obj/Debug/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs b/src/obj/Debug/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs new file mode 100644 index 0000000..ed92695 --- /dev/null +++ b/src/obj/Debug/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] diff --git a/src/obj/Debug/net6.0/spworlds.AssemblyInfo.cs b/src/obj/Debug/net6.0/spworlds.AssemblyInfo.cs new file mode 100644 index 0000000..c77ec52 --- /dev/null +++ b/src/obj/Debug/net6.0/spworlds.AssemblyInfo.cs @@ -0,0 +1,25 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using System.Reflection; + +[assembly: System.Reflection.AssemblyCompanyAttribute("Mih4n")] +[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] +[assembly: System.Reflection.AssemblyDescriptionAttribute("данная библиотека предназначена для работы с сайтом spworlds. Ознакомиться с доку" + + "ментацией можно в гитхабе проекта")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.1.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.1")] +[assembly: System.Reflection.AssemblyProductAttribute("spworlds")] +[assembly: System.Reflection.AssemblyTitleAttribute("spworlds")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.0.1.0")] +[assembly: System.Reflection.AssemblyMetadataAttribute("RepositoryUrl", "https://github.com/Mih4n/spworlds")] + +// Создано классом WriteCodeFragment MSBuild. + diff --git a/src/obj/Debug/net6.0/spworlds.AssemblyInfoInputs.cache b/src/obj/Debug/net6.0/spworlds.AssemblyInfoInputs.cache new file mode 100644 index 0000000..78e8d16 --- /dev/null +++ b/src/obj/Debug/net6.0/spworlds.AssemblyInfoInputs.cache @@ -0,0 +1 @@ +3b79596e0f193799e87c2d642144700f8551bcf8 diff --git a/src/obj/Debug/net6.0/spworlds.GeneratedMSBuildEditorConfig.editorconfig b/src/obj/Debug/net6.0/spworlds.GeneratedMSBuildEditorConfig.editorconfig new file mode 100644 index 0000000..57fd3f3 --- /dev/null +++ b/src/obj/Debug/net6.0/spworlds.GeneratedMSBuildEditorConfig.editorconfig @@ -0,0 +1,11 @@ +is_global = true +build_property.TargetFramework = net6.0 +build_property.TargetPlatformMinVersion = +build_property.UsingMicrosoftNETSdkWeb = +build_property.ProjectTypeGuids = +build_property.InvariantGlobalization = +build_property.PlatformNeutralAssembly = +build_property.EnforceExtendedAnalyzerRules = +build_property._SupportedPlatformList = Linux,macOS,Windows +build_property.RootNamespace = spworlds +build_property.ProjectDir = c:\Users\losev\OneDrive\Рабочий стол\spworlds\spworlds-csharp-library\src\ diff --git a/src/obj/Debug/net6.0/spworlds.GlobalUsings.g.cs b/src/obj/Debug/net6.0/spworlds.GlobalUsings.g.cs new file mode 100644 index 0000000..8578f3d --- /dev/null +++ b/src/obj/Debug/net6.0/spworlds.GlobalUsings.g.cs @@ -0,0 +1,8 @@ +// +global using global::System; +global using global::System.Collections.Generic; +global using global::System.IO; +global using global::System.Linq; +global using global::System.Net.Http; +global using global::System.Threading; +global using global::System.Threading.Tasks; diff --git a/src/spworlds.cs b/src/spworlds.cs index 26a92f8..e988b70 100644 --- a/src/spworlds.cs +++ b/src/spworlds.cs @@ -23,27 +23,14 @@ public class SPWorlds client.BaseAddress = new Uri("https://spworlds.ru/api/public/"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Base64BearerToken); } - - // Полностью бесполезная функция, вебхук, возвращающийся от сайта по факту невозможно валидировать. private async Task ValidateWebHook(string webHook, string bodyHash) { - // Если я правильно все понял, то вот - // Конвертим из string в bytes body_hash byte[] body = Encoding.UTF8.GetBytes(bodyHash); - // потом конвертим вебхук byte[] webhook = Encoding.UTF8.GetBytes(webHook); - // создаем объект с токеном(тоже encoded в bytes) для сопостовления var key = new HMACSHA256(Encoding.UTF8.GetBytes(token)); - // Переводим в Base64 string webhook64 = Convert.ToBase64String(key.ComputeHash(webhook)); return webhook64.Equals(body); - /** - * Тот же код, но на Python: - hmacData = hmac.new(token.encode('utf - 8'), webhook.encode('utf - 8'), sha256).digest() - base64Data = b64encode(hmacData) - return hmac.compare_digest(base64Data, bodyHash.encode('utf-8')) - **/ } private async Task SendRequest(string endpoint, Boolean getResult = true, Dictionary? body = null) @@ -93,9 +80,8 @@ public class SPWorlds public async Task GetUser(string discordId) { - var userResponse = JsonObject.Parse(await SendRequest($"users/{discordId}")); - var userName = userResponse["username"]; - User user = new() { Name = userName} + string userName = (string)JsonObject.Parse(await SendRequest($"users/{discordId}"))["username"]; + User user = new(userName); return (User)user; }