-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
647 lines (575 loc) · 29.3 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
//CODE CREATED BY OWEN MAGILL
//PLEASE RESPECT THE EFFORT PUT INTO THIS CODE
//
//THE GOAL OF API++ IS TO MAKE USING API SYSTEMS EASIER
//
//COLOR NUMS
//9 BLUE
//79 RED BG WITH WHITE TEXT
//15 WHITE
#include <iostream>
#include <string>
#include <fstream>
#include <windows.h>
#include <Lmcons.h>
#include "resource.h"
using namespace std;
//declare all wariables
string newApiOp;
string mainCommand;
string fileType;
bool javascriptFile;
bool startup = true;
string repoSearchType;
string singleRepoOwner;
string singleRepoName;
string singleUrl;
string repoName;
string repoFullName;
string repoDesc;
string repoHtmlUrl;
string fileName = "newApi++File";
string filePath = "C:\\code\\api++";
string fullFilePath;
string fullFilePathConfirm;
string fileIdValue = "apiresultsapi++";
string fileTitleLink;
string fileTitleLinkCustom = "#";
string fileTitleClassName;
string fileFullNameClassName;
string fileDescClassName;
string listLinkExist;
//prefs
string prefsName;
string prefsColon;
string prefsValue;
string listFilter;
string listUrl;
string listInNameKeyword;
string apiSysType;
string discordClassName;
string infoText = "info.txt";
//info file
string infoName;
string infoEqual = "=";
string infoValue;
//program info variables
string programVersion;
string programVersionStatus;
string programGitHub;
string programWebsite;
string programDocsWebsite;
string programLangFile;
string programNullInputValue;
string programPrefFile;
//main application. responsible for main tasks
int main() {
//start API++
int prefs();
int beta();
int info();
int apiSys();
if (startup == true) {
char username[UNLEN+1];
DWORD username_len = UNLEN+1;
GetUserName(username, &username_len);
string currentUser = username;
cout << "API++ starting..." << endl;
cout << "Reading prefs file..." << endl;
//SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), <int>);
return info();
startup = false;
}
//get main input
cout << "> ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
cin >> mainCommand;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
if (mainCommand == "newapiop") {
cout << "Embed the code directly into a HTML file or put it in a JavaScript file? [H (HTML)/J (JavaScript)] ";
cin >> fileType;
if (fileType == "h" || fileType == "H") {
cout << "API++ will embed the code into a HTML file." << endl;
javascriptFile = false;
return apiSys();
}
else if (fileType == "j" || fileType == "J") {
cout << "API++ will put the code into a .js file." << endl;
javascriptFile = true;
return apiSys();
}
}
else if (mainCommand == "help") {
cout << "Need help? Visit the documentation! (";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
cout << "https://piccolowen.github.io/code/apipp/documentation/intro";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cout << ")" << endl;
}
else if (mainCommand == "exit") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 79);
cout << "EXITING..." << endl;
return 0;
}
else {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 79);
cout << "Whoops! Not a command! Hint: type 'newapiop' to create a new API system!" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
}
return main();
}
//THIS CODE WILL BE CHANGED SINCE THERE WILL BE MORE SUPPORTED APIS IN THE FUTURE
//get the type of API sys
int apiSys() {
int githubapisys();
int discordapisys();
//fetch type of embed
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "What API system will you be making? [G (GitHub)/D (Dicord)]" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> apiSysType;
if (apiSysType == "g" || apiSysType == "G") {
return githubapisys();
}
else if (apiSysType == "d" || apiSysType == "D") {
return discordapisys();
}
}
int discordapisys() {
int discordstatusapisys();
cout << "API++ only works with Discord's status API." << endl;
return discordstatusapisys();
}
int githubapisys() {
int fileSys();
cout << "For your own reference the base URL is https://api.github.com/" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "Choose whether you would like to embed a single repository or a list (found using filters). [R (single repo)/L (list of repos) ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> repoSearchType;
if (repoSearchType == "R" || repoSearchType == "r") {
cout << "Please type the owner of the repository you are trying to embed: ";
cin >> singleRepoOwner;
cout << "Please type the name of the repository you are trying to embed: ";
cin >> singleRepoName;
singleUrl = "https://api.github.com/repos/" + singleRepoOwner + "/" + singleRepoName;
cout << "This is the URL api++ will be using: " << singleUrl << endl;
cout << "Here is the repo HTML URL (the URL a user would go to view the repo.)" << endl;
repoHtmlUrl = "https://github.com/" + singleRepoOwner + "/" + singleRepoName;
cout << repoHtmlUrl << endl;
system("pause");
cout << "api++ needs to know what parts of the repo you will want to be displayed." << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "Include title? [Y/N] ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> repoName;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "Include the full name? [Y/N] ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> repoFullName;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "Include the description? [Y/N] ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> repoDesc;
return fileSys();
}
else if (repoSearchType == "l" || "L") {
cout << "There are many ways to get a list of repositories. With GitHub you have to search with a filter." << endl;
cout << "To get a full list of filters, go to https://help.github.com/en/github/searching-for-information-on-github/searching-for-repositories" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "Do you already have a search API URL? [Y/N] ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> listLinkExist;
if (listLinkExist == "y" || listLinkExist == "Y") {
cout << "Great that will make this a lot easier!" << endl;
}
else if (listLinkExist == "n" || listLinkExist == "N") {
cout << "Type the filter you want to use." << endl;
cout << "Filter by in the name [inname] \
\nFilter by in the description [indesc] \
\nFilter by in the README [inreadme] \
\nFilter by user's name [username] \
\nFilter by organization [orgname] \
\nFilter by size (MB size.) [exactsize (filter by repos with exact size) / (there are other options that are not built in to API++ yet)] \
\nFilter by number of followers [follown / (there are other options that are not built in to API++ yet)] \
\nFilter by number of forks [forksn / (there are other options that are not built in to API++ yet)] \
\nFilter by number of stars [starsn / (there are other options that are not built in to API++ yet)] \
\nFilter by date created [datec] \
\nFilter by date pushed [datep] \
\nFilter by language [lang] \
\nFilter by topic [topic] \
\nFilter by number of topics [topicsn] \
\nFilter by license keyword [license] \
\nFilter by public or private [pubpri] \
\nFilter by whether a repo is a mirror or not [mirror] \
\nFilter by whether a repo has been archived or not [arch] \
" << endl;
cin >> listFilter;
return fileSys();
}
else {
cout << "Whoops! Not one of your options! (API++ is still going to say you don't have a link) ERRORCODE=0x0" << endl;
return fileSys();
}
}
else {
cout << "Not one of your options ERRORCODE=0x0" << endl;
return apiSys();
}
}
//get file info
int fileSys() {
int singleFile();
int listFile();
ofstream file;
if (javascriptFile == true) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "What should the JavaScript file be named? (no spaces) ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> fileName;
}
else if (javascriptFile == false) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "What should the HTML file be named? (no spaces) ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> fileName;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "Where should the file be placed? (no spaces) ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> filePath;
if (javascriptFile == true) {
fullFilePath = filePath + "\\\\" + fileName + ".js";
}
else if (javascriptFile == false) {
fullFilePath = filePath + "\\\\" + fileName + ".html";
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "Is this good? [Y/N]" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cout << fullFilePath << endl;
cin >> fullFilePathConfirm;
//confirm that user is satisfied with full file path
if (fullFilePathConfirm == "Y" || fullFilePathConfirm == "y") {
if (repoSearchType == "r" || repoSearchType == "R") {
return singleFile();
}
else if (repoSearchType == "l" || repoSearchType == "L") {
return listFile();
}
}
else if (fullFilePathConfirm == "n" || fullFilePathConfirm == "N") {
return fileSys();
}
//return back to filesys if user is not satisfied
else {
cout << "Not one of your options! ERRORCODE=0" << endl;
return fileSys();
}
}
//create single repo file for github
int singleFile() {
system(("title API++ - New file: "+ fullFilePath).c_str());
ofstream file((fullFilePath).c_str());
if (javascriptFile == false) {
file << "<!DOCTYPE html>" << endl;
file << "<html>" << endl;
file << "<head>" << endl;
file << "<title>API++ auto generated file</title>" << endl;
file << "</head>" << endl;
file << "<body>" << endl;
file << "<script>" << endl;
}
file << "//JavaScript code generated by API++" << endl;
file << "//API++ by Piccolowen" << endl;
file << "window.onload = apifunc();" << endl;
file << "async function apifunc() {" << endl;
if (repoSearchType == "R" || repoSearchType == "r") {
file << "const url = '" << singleUrl << "';" << endl;
}
file << "const response = await fetch(url);" << endl;
file << "const result = await response.json();" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "For this code to work the code needs to place the results in a HTML element with a certain ID value. What should that value be? (no spaces) ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> fileIdValue;
cout << "ID value: " << fileIdValue << endl;
file << "const apiresult = document.getElementById('" << fileIdValue << "');" << endl;
file << "console.log('api++ system working...')" << endl;
file << "console.log('api++ system by Piccolowen https://github.com/Piccolowen')" << endl;
file << "console.log('api++ result:');" << endl;
file << "console.log(result);" << endl;
//repo title
if (repoName == "Y" || repoName == "y") {
file << "console.log('name result: ' + result.name)" << endl;
cout << "Should the title element have link? [C (custom link)/R (repo link)/N (no)] ";
cin >> fileTitleLink;
if (fileTitleLink == "R" || fileTitleLink == "r") {
file << "const title = document.createElement('a')" << endl;
file << "title.href = result.html_url" << endl;
}
else if (fileTitleLink == "C" || fileTitleLink == "c") {
cout << "Custom URL: ";
cin >> fileTitleLinkCustom;
file << "const title = document.createElement('a')" << endl;
file << "title.href = '" << fileTitleLinkCustom << "'" << endl;
}
else {
file << "const title = document.createElement('p')" << endl;
}
file << "title.target = '_blank'" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "What should the class value be for the title? (the class name allows styling with CSS) [no spaces] ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> fileTitleClassName;
cout << "Class name: " << fileTitleClassName << endl;
file << "title.className = '" << fileTitleClassName << "'" << endl;
file << "title.textContent = result.name" << endl;
file << "apiresult.appendChild(title)" << endl;
}
//repo fullname
if (repoFullName == "Y" || repoFullName == "y") {
file << "console.log('full name result: ' + result.full_name)" << endl;
file << "const fullname = document.createElement('p')" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "What should the class value be for the full name? (the class name allows styling with CSS) [no spaces] ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> fileFullNameClassName;
cout << "Class name: " << fileFullNameClassName << endl;
file << "fullname.className = '" << fileFullNameClassName << "'" << endl;
file << "fullname.textContent = result.full_name" << endl;
file << "apiresult.appendChild(fullname)" << endl;
}
//repo desc
if (repoDesc == "Y" || repoDesc == "y") {
file << "console.log('desc result: ' + result.description)" << endl;
file << "const desc = document.createElement('p')" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "What should the class value be for the description? (the class name allows styling with CSS) [no spaces] ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> fileDescClassName;
cout << "Class name: " << fileDescClassName << endl;
file << "desc.className = '" << fileDescClassName << "'" << endl;
file << "desc.textContent = result.description" << endl;
file << "apiresult.appendChild(desc)" << endl;
}
file << "}" << endl;
//finish html file (if applicable)
if (javascriptFile == false) {
file << "</script>" << endl;
file << "</body>" << endl;
file << "</html>" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 79);
cout << "Make sure to add an element with ID value: " << fileIdValue << "!" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
}
}
//create url for list system for github
int listFile() {
int listInNameFile();
system(("title API++ - New file: "+ fullFilePath).c_str());
if (listFilter == "inname") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "Please type the keyword you are searching for: ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> listInNameKeyword;
listUrl = "https://api.github.com/search/repositories?q=" + listInNameKeyword + "+in:name";
cout << "Here is the API URL :" << listUrl << endl;
return listInNameFile();
}
else {
cout << "Not one of your options! ERRORCODE=0x0" << endl;
}
}
//creates file for list api sys
int listInNameFile() {
system(("title API++ - New file: "+ fullFilePath).c_str());
ofstream file((fullFilePath).c_str());
if (javascriptFile == false) {
file << "<!DOCTYPE html>" << endl;
file << "<html>" << endl;
file << "<head>" << endl;
file << "<title>API++ auto generated file</title>" << endl;
file << "</head>" << endl;
file << "<body>" << endl;
file << "<script>" << endl;
}
file << "//JavaScript code generated by API++" << endl;
file << "//API++ by Piccolowen" << endl;
file << "window.onload = apifunc()" << endl;
file << "async function apifunc() {" << endl;
file << "const url = '" << listUrl << "'" << endl;
file << "const response = await fetch(url)" << endl;
file << "const result = await response.json()" << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "For this code to work the code needs to place the results in a HTML element with a certain ID value. What should that value be? (no spaces) ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> fileIdValue;
file << "const apiresult = document.getElementById('" << fileIdValue << "')" << endl;
file << "console.log('API++ system working...')" << endl;
file << "console.log('API++ system by Piccolowen https://github.com/Piccolowen')" << endl;
file << "console.log('API++ result:')" << endl;
file << "console.log(result)" << endl;
file << "const resultLength = Object.keys(result.items).length" << endl;
file << "var arrnum = 0" << endl;
file << "while (arrnum < resultLength) {" << endl;
//gather info
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "Include the title? [Y/N] ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> repoName;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "Include the full name? (ex: Piccolowen/APIpp) [Y/N] ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> repoFullName;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 47);
cout << "Include the description? [Y/N] ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cin >> repoDesc;
if (repoName == "Y" || repoName == "y") {
cout << "Do you want a URL for the title element? [C (custom URL)/R (repo URL)/N (no)] " << endl;
cin >> fileTitleLink;
if (fileTitleLink == "c" || fileTitleLink == "C") {
cout << "Please type custom URL: ";
cin >> fileTitleLinkCustom;
file << "const title = document.createElement('a')" << endl;
file << "title.href = '" << fileTitleLinkCustom << "'" << endl;
file << "title.target = '_blank'" << endl;
}
else if (fileTitleLink == "r" || fileTitleLink == "R") {
file << "const title = document.createElement('a')" << endl;
file << "title.href = result.items[arrnum].html_url" << endl;
file << "title.target = '_blank'" << endl;
}
else {
file << "const title = document.createElement('p')" << endl;
}
cout << "What should the class name for the title be? (This will allow for styling with CSS) ";
cin >> fileTitleClassName;
file << "title.className = '" << fileTitleClassName << "'" << endl;
file << "title.textContent = result.items[arrnum].name" << endl;
}
if (repoFullName == "y" || repoFullName == "Y") {
file << "const fullname = document.createElement('p')" << endl;
cout << "What should the class name for the full name be? (the full name will look like this: USERNAME/REPOSITORY) ";
cin >> fileFullNameClassName;
file << "fullname.className = '" << fileFullNameClassName << "'" << endl;
file << "fullname.textContent = result.items[arrnum].full_name" << endl;
}
if (repoDesc == "y" || repoDesc == "Y") {
file << "const desc = document.createElement('p')" << endl;
cout << "What should the class name for the description be? ";
cin >> fileDescClassName;
file << "desc.className = '" << fileDescClassName << "'" << endl;
file << "desc.textContent = result.items[arrnum].description" << endl;
}
file << "}" << endl;
file << "}" << endl;
if (javascriptFile == false) {
file << "</script>" << endl;
file << "</body>" << endl;
file << "</html>" << endl;
}
}
int discordstatusapisys() {
cout << "This API allows you to get the status of Discord." << endl;
cout << "What should the class name be for the element? (this allows for styling with CSS) ";
cin >> discordClassName;
ofstream file((fullFilePath).c_str());
file << "//Dicord's code: https://cdn.statuspage.io/se-v2.js" << endl;
file << "StatusPage='undefined'==typeof StatusPage?{}:StatusPage,StatusPage.page=function(e){if(e=e||{},!e.page)throw new Error('A pageId is required to initialize.');this.apiKey=e.apiKey||null,this.error=e.error||this.error,this.format=e.format||'json',this.pageId=e.page,this.version=e.version||'v2',this.secure=!('secure'in e)||e.secure,this.protocol=this.secure?'https':'http',this.host=e.host||'statuspage.io',this.host_with_port_and_protocol=e.test?'':this.protocol+'://'+this.pageId+'.'+this.host},StatusPage.page.prototype.serialize=function(e,t){var s=[],r={sms:'email_sms',webhook:'endpoint'};for(var o in e)if('to_sentence'!==o){var i=o;o=o in r?r[o]:o;var a=t?t+'['+o+']':o,n=e[i];s.push('object'==typeof n?this.serialize(n,a):encodeURIComponent(a)+'='+encodeURIComponent(n))}return s.join('&')},StatusPage.page.prototype.createStatusPageCORSRequest=function(e,t){var s=new XMLHttpRequest;return'withCredentials'in s?s.open(e,t,!0):'undefined'!=typeof XDomainRequest?(s=new XDomainRequest,s.open(e,t)):s=null,s},StatusPage.page.prototype.executeRequestAndCallbackWithResponse=function(e){if(!e.path)throw new Error('A path is required to make a request');var t=e.path,s=e.method||'GET',r=e.success||null,o=e.error||this.error,i=this.host_with_port_and_protocol+'/api/'+this.version+'/'+t+'.'+this.format,a=this.createStatusPageCORSRequest(s,i);if(a)if(this.apiKey&&(console.log('!!! API KEY IN USE - REMOVE BEFORE DEPLOYING TO PRODUCTION !!!'),console.log('!!! API KEY IN USE - REMOVE BEFORE DEPLOYING TO PRODUCTION !!!'),console.log('!!! API KEY IN USE - REMOVE BEFORE DEPLOYING TO PRODUCTION !!!'),a.setRequestHeader('Authorization','OAuth '+this.apiKey)),a.onload=function(){var e=JSON.parse(a.responseText);r&&r(e)},a.error=o,'POST'===s||'DELETE'===s){var n=e.data||{};a.setRequestHeader('Content-type','application/x-www-form-urlencoded'),a.send(this.serialize(n))}else a.send()},StatusPage.page.prototype.get=function(e,t){if(t=t||{},!e)throw new Error('Path is required.');if(!t.success)throw new Error('Success Callback is required.');var s=t.success||{},r=t.error||{};this.executeRequestAndCallbackWithResponse({path:e,success:s,error:r,method:'GET'})},StatusPage.page.prototype.post=function(e,t){if(t=t||{},!e)throw new Error('Path is required.');var s={};if('subscribers'===e){if(!t.subscriber)throw new Error('Subscriber is required to post.');s.subscriber=t.subscriber}else{if(!t.data)throw new Error('Data is required to post.');s=t.data}var r=t.success||{},o=t.error||{};this.executeRequestAndCallbackWithResponse({data:s,path:e,success:r,error:o,method:'POST'})},StatusPage.page.prototype['delete']=function(e,t){if(t=t||{},!e)throw new Error('Path is required.');if(!t.subscriber)throw new Error('Data is required to delete.');var s={};'subscribers'===e?s.subscriber=t.subscriber:s=t.data;var r=t.success||{},o=t.error||{};this.executeRequestAndCallbackWithResponse({data:s,path:e,success:r,error:o,method:'DELETE'})},StatusPage.page.prototype.error=function(){console.log('There was an error with your request')},StatusPage.page.prototype.summary=function(e){this.get('summary',e)},StatusPage.page.prototype.status=function(e){this.get('status',e)},StatusPage.page.prototype.components=function(e){this.get('components',e)},StatusPage.page.prototype.incidents=function(e){switch(e.filter){case'unresolved':this.get('incidents/unresolved',e);break;case'resolved':this.get('incidents/resolved',e);break;default:this.get('incidents',e)}},StatusPage.page.prototype.scheduled_maintenances=function(e){switch(e.filter){case'active':this.get('scheduled-maintenances/active',e);break;case'upcoming':this.get('scheduled-maintenances/upcoming',e);break;default:this.get('scheduled-maintenances',e)}},StatusPage.page.prototype.subscribe=function(e){if(!e||!e.subscriber)throw new Error('A subscriber object is required.');this.post('subscribers',e)},StatusPage.page.prototype.unsubscribe=function(e){if(!e||!e.subscriber)throw new Error('A subscriber object is required.');if(!e.subscriber.id)throw new Error('You must supply a subscriber.id in order to cancel a subscription.');this['delete']('subscribers',e)};" << endl;
file << "var sp = new StatusPage.page({ page: 'srhpyqt94yxb' });" << endl;
file << "sp.summary({" << endl;
file << "success: function (data) {" << endl;
file << "console.log('API++ Discord Status API system: ' + data.components[0].status);" << endl;
file << "const statussum = document.createElement('p')" << endl;
file << "statussum.className = '" << discordClassName << "'" << endl;
file << "statussum.textContent = data.components[0].status" << endl;
file << "}})" << endl;
}
//responsible for setting prefs (only runs on startup and on command)
int info() {
//read prefs
ifstream infoFile;
infoFile.open("info.txt");
if (infoFile.is_open()) {
while (infoFile >> infoName >> infoEqual >> infoValue) {
if (infoName == "VERSION") {
programVersion = infoValue;
}
else if (infoName == "VERSION_STATUS") {
programVersionStatus = infoValue;
}
else if (infoName == "GITHUB_URL") {
programGitHub = infoValue;
}
else if (infoName == "WEBSITE") {
programWebsite = infoValue;
}
else if (infoName == "DOCS_WEBSITE") {
programDocsWebsite = infoValue;
}
else if (infoName == "TEXT_SOURCE_FILE") {
programLangFile = infoValue;
}
else if (infoName == "NULL_INPUT") {
programNullInputValue = infoValue;
}
else if (infoName == "PREF_FILE") {
programPrefFile = infoValue;
}
else {
cout << "Outdated info file. ERRORCODE=0x3" << endl;
}
}
infoFile.close();
}
else {
cout << "Info file is not open. ERRORCODE=0x1" << endl;
}
if (programVersionStatus == "PRE_RELEASE") {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 79);
cout << "NOTE: THIS VERSION IS A PRE-RELEASE FOR VERSION " << programVersion << ". VISIT THE RELEASE INFO FOR MORE INFORMATION." << endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
}
system(("title API++ " + programVersion + " [" + programVersionStatus + "]").c_str());
ifstream prefs;
prefs.open((programPrefFile).c_str());
if (prefs.is_open()) {
while (infoFile >> prefsName >> prefsColon >> prefsValue) {
if (prefsColon == ":") {
if (prefsName == "theme") {
if (prefsValue == "dark") {
system("color 07");
}
else if (prefsValue == "light") {
system("color 70");
}
else {
system(("color" + prefsValue).c_str());
}
}
else {
cout << "Unknown info name. ERRORCODE=0x2" << endl;
}
}
}
prefs.close();
}
else {
cout << "Prefs file is not open or could not be found. ERRORCODE=0x4" << endl;
}
startup = false;
cout << "API++ ready..." << endl;
return main();
}
int beta() {
int main();
string fn = "C;\\code\\APIpp\\main.cpp";
if(fn.substr(fn.find_last_of(".") + 1) == "cpp") {
cout << "Yes..." << endl;
} else {
cout << "No..." << endl;
}
return main();
}