// Fill out your copyright notice in the Description page of Project Settings. #include "MBPFL.h" #include "Http.h" #include "Interfaces/IHttpRequest.h" #include "JsonObjectConverter.h" #define BUG_REPORT_WEBHOOK_URL "https://discordapp.com/api/webhooks/759470661789286481/-5BbYkdJtvxYyt1ZpN1zlkfG_jm2YXR1RYGTZpthlvdbxEUNQrk7RXrRVmt0A3UwALgC" #define MYGAME_VERSION "v1.0-pre-alpha" #define LOG(str, ...) UE_LOG(LogTemp, Warning, TEXT(str), __VA_ARGS__) void UMBPFL::SubmitBugReport(const EBugReportCategory Category, const EBugReportPriority Priority, const FBugReportUserData& AuthorData, FString& ReportID, bool bIncludeSpecs) { // Just some quick checks to prevent spamming if (AuthorData.Author == "" || AuthorData.MapName == "" || AuthorData.Message == "") { return; } if (FHttpModule* http = &FHttpModule::Get()) { TSharedRef request = http->CreateRequest(); request->SetVerb("POST"); request->SetHeader("Content-Type", "application/json"); request->SetURL(BUG_REPORT_WEBHOOK_URL); ReportID = FGuid::NewGuid().ToString(); // Create the embed for the report FDiscordMessageEmbed embed; embed.title = GetEnumValueAsString("EBugReportCategory", Category); embed.author.icon_url = ""; embed.author.name = AuthorData.Author; embed.description = AuthorData.Message; embed.color = embed.GetColor(Priority); embed.fields.Add({ "Priority", GetEnumValueAsString("EBugReportPriority", Priority) }); embed.fields.Add({ "Location", AuthorData.Location.ToString(), true }); embed.fields.Add({ "Map", AuthorData.MapName, true }); embed.footer.text = FString::Printf(TEXT("MYGame %s | %s"), *FString(MYGAME_VERSION), *ReportID); FDiscordMessage data; data.username = "Bug Reporter"; data.embeds.Add(embed); // Don't show "private" information unless the player wants to if (bIncludeSpecs) { // Create another embed for the users pc specs FDiscordMessageEmbed embed2; embed2.title = FString::Printf(TEXT("%s PC Specs"), *AuthorData.Author); embed2.color = embed.GetColor(Priority); embed2.fields.Add({ "Resolution", GetGameResolution(), true }); embed2.fields.Add({ "RAM", FString::Printf(TEXT("%dGB"), GetTotalRAM()), true }); embed2.fields.Add({ "CPU", GetCPUBrandName(), true }); embed2.fields.Add({ "GPU", GetGPUBrandName(), true }); embed2.fields.Add({ "GPU Driver", GetGPUDriverInfo(), true }); data.embeds.Add(embed2); } FString OutputString; FJsonObjectConverter::UStructToJsonObjectString(data, OutputString); OutputString = OutputString.Replace(TEXT("binline"), TEXT("inline")); request->SetContentAsString(OutputString); request->ProcessRequest(); } }