Skip to content

Commit 3295329

Browse files
authored
Code cleanup
1 parent d188a55 commit 3295329

7 files changed

+238
-148
lines changed

RocketLeagueAssistant/CreateAutomationBase.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
#include "imgui_stdlib.h"
66

77

8+
//
9+
//
10+
//
11+
//This code will take the randomly generated automation ID and webhookURL from the RandomAlphaNumeric.cpp function and create a new automation to be used with the plugin.
12+
//
13+
//
14+
//
15+
16+
817
void RocketLeagueAssistant::CreateAutomation(std::string webhookURL, std::string automationID)
918
{
1019

@@ -17,7 +26,7 @@ void RocketLeagueAssistant::CreateAutomation(std::string webhookURL, std::string
1726
auto baseURL = cvarManager->getCvar("ha_haBaseURL");
1827
std::string baseURLString = baseURL.getStringValue();
1928

20-
//Get toekn, transform
29+
//Get token, transform
2130
CVarWrapper hatokenLCVar = cvarManager->getCvar("ha_token");
2231
if (!hatokenLCVar) { return; }
2332

@@ -32,20 +41,24 @@ void RocketLeagueAssistant::CreateAutomation(std::string webhookURL, std::string
3241
req.verb = "POST";
3342
req.url = baseURLString + "/api/config/automation/config/" + automationID;
3443

44+
//Token authorization header to create the automation via API
3545
std::map<std::string, std::string> jsonHeader{ {"Authorization", "Bearer " + tokenString}};
3646

3747
req.headers = jsonHeader;
3848

3949
std::string dataVar = "{\"id\" :";
50+
51+
//Automation YAML
4052
std::string last = R"T("alias":"RocketLeague - BakkesGenerated","description":"","trigger":[{"platform":"webhook","webhook_id":")T" + webhookURL + R"T("}],"condition":[],"action":[{"choose":[{"conditions":[{"condition":"template","value_template":"{{ trigger.json.data == 'home' }}","alias":"Blue Team (Home) Automation"}],"sequence":[]},{"conditions":[{"condition":"template","value_template":"{{ trigger.json.data == 'away' }}","alias":"Orange Team (Away) Automation"}],"sequence":[]},{"conditions":[{"condition":"template","value_template":"{{ trigger.json.data == 'mainmenu' }}","alias":"Main Menu Automation"}],"sequence":[]},{"conditions":[{"condition":"template","value_template":"{{ trigger.json.data == 'teamScored' }}","alias":"Your Team Scored Automation"}],"sequence":[]},{"conditions":[{"condition":"template","value_template":"{{ trigger.json.data == 'otherTeamScored' }}","alias":"The Other Team Scored Automation"}],"sequence":[]},{"conditions":[{"condition":"template","value_template":"{{ trigger.json.data == 'teamDemoed' }}","alias":"Your Team Demo'd the Other Team Automation"}],"sequence":[]},{"conditions":[{"condition":"template","value_template":"{{ trigger.json.data == 'gotDemoed' }}","alias":"The Other Team Demo'd Your Team Automation"}],"sequence":[]},{"conditions":[{"condition":"template","value_template":"{{ trigger.json.data == 'freeplay' }}","alias":"Freeplay Automation"}],"sequence":[]},{"conditions":[{"condition":"template","value_template":"{{ trigger.json.data == 'overtime' }}","alias":"Overtime Automation"}],"sequence":[]},{"conditions":[{"condition":"template","value_template":"{{ trigger.json.data == 'exit' }}","alias":"Game Exit Automation (ex: Return Lights to Normal)"}],"sequence":[]}]}],"mode":"single"}
4153
)T";
4254
43-
LOG("{}", last);
55+
//LOG("{}", last);
56+
//Format's request for the automation it's YAML
4457
std::string both = dataVar + " \"" + automationID + "\"," + last;
4558

4659
req.body = both;
4760

48-
LOG("{}", req.url);
61+
//LOG("{}", req.url);
4962

5063
HttpWrapper::SendCurlRequest(req, [this](int code, std::string result)
5164
{

RocketLeagueAssistant/RandomAlphaNumeric.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
#include <functional> //for std::function
1313
#include <algorithm> //for std::generate_n
1414

15+
//
16+
//
17+
//
18+
// This creates the random string for the Webhook ID and Automation ID when created using the plugin.
19+
//
20+
//
21+
//
22+
23+
24+
1525
typedef std::vector<char> char_array;
1626

1727
std::string random_string()
@@ -23,7 +33,7 @@ std::string random_string()
2333

2434
std::shuffle(str.begin(), str.end(), generator);
2535

26-
return str.substr(0, 32); // assumes 32 < number of characters in str
36+
return str.substr(0, 32);
2737
}
2838

2939
std::string random_number()
@@ -35,7 +45,7 @@ std::string random_number()
3545

3646
std::shuffle(str.begin(), str.end(), generator);
3747

38-
return str.substr(0, 13); // assumes 32 < number of characters in str
48+
return str.substr(0, 13);
3949
}
4050

4151
std::string RocketLeagueAssistant::GenWebHook() {

0 commit comments

Comments
 (0)