-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassmarkbot.c
More file actions
2517 lines (2304 loc) · 147 KB
/
passmarkbot.c
File metadata and controls
2517 lines (2304 loc) · 147 KB
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
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <concord/discord.h>
#include <concord/log.h>
// Struct to hold CPU info read from passmark.txt
typedef struct
{
char cpuname[256];
char cores[256];
char single[256];
char multi[256];
char tdp[256];
char socket[256];
char type[256];
} CPUSpecs;
typedef struct
{
char gpuname[256];
char threedperf[256];
char twodperf[256];
char tdp[256];
char vram[256];
char type[256];
} GPUSpecs;
// Break the query into tokens and search for each token in the struct & return 1 if all tokens are found (based off of https://www.geeksforgeeks.org/cpp/string-tokenization-in-c/)
int tokenise_query_and_search(const char *fullcpuname, const char *query)
{
char initialquery[256];
strcpy(initialquery, query);
char delimiter[] = " ";
char *token;
token = strtok(initialquery, delimiter);
while (token != NULL)
{
if (strcasestr(fullcpuname, token) == NULL)
{
return 0;
}
token = strtok(NULL, delimiter);
}
return 1;
}
void print_usage(void)
{
printf("\n\n[ Decentcarp's Passmark Discord Bot ]\n\n"
"Usage:\n"
"!passmark <CPUNAME> (e.g. !passmark i7-8700K) - Displays single thread perf, multi thread perf, TDP (if applicable).\n"
"To compare multiple CPUs, use the format: !passmark <CPU1> | <CPU2 (optional)> | <CPU3 (optional)> | <CPU4 (optional)> | <CPU5 (optional)> (e.g. !passmark i7-8700K | Ryzen 5 3600).\n"
"!gpassmark <GPUNAME> (e.g. !gpassmark 7900 XT) - Displays 3D performance, VRAM, TDP (if applicable).\n"
"To compare multiple GPUs, use the format: !gpassmark <GPU1> | <GPU2 (optional)> | <GPU3 (optional)> | <GPU4 (optional)> | <GPU5 (optional)> (e.g. !gpassmark 7900 XT | RTX 3080).\n"
"!passmark and !gpassmark can be shortened to !pm and !gpm respectively.\n\n"
"\nPress Enter to start the bot.\n");
}
// Log when the bot connects to Discord
void on_ready(struct discord *client, const struct discord_ready *event)
{
log_info("Decentcarp's Passmark Discord Bot connected to Discord as %s#%s!",
event->user->username, event->user->discriminator);
}
void passmark(struct discord *client, const struct discord_message *event)
{
// Array to hold up to 5 CPU queries, query_count tracks how many were provided
char query[5][256] = {{0}};
int query_count = 0;
// Whitespace trimmer & separate message content into multiple query using | as separator
if (event->content && event->content[0] != '\0')
{
char temp_input[500] = {0};
strncpy(temp_input, event->content, sizeof(temp_input) - 1);
// Count pipes to determine number of query (pipes + 1), capped at 5
int pipe_count = 0;
for (int j = 0; temp_input[j] != '\0'; j++)
{
if (temp_input[j] == '|')
pipe_count++;
}
query_count = (pipe_count + 1 > 5) ? 5 : pipe_count + 1;
// Split by pipes and trim each query
char *current = temp_input;
for (int i = 0; i < query_count; i++)
{
char *pipe = strchr(current, '|');
if (pipe != NULL)
{
*pipe = '\0';
strncpy(query[i], current, sizeof(query[i]) - 1);
current = pipe + 1;
}
else
{
strncpy(query[i], current, sizeof(query[i]) - 1);
}
// Trim whitespace
char *start = query[i];
while (*start == ' ' || *start == '\t')
start++;
if (start != query[i])
memmove(query[i], start, strlen(start) + 1);
size_t len = strlen(query[i]);
while (len > 0 && (query[i][len - 1] == ' ' || query[i][len - 1] == '\t' ||
query[i][len - 1] == '\n' || query[i][len - 1] == '\r'))
{
query[i][--len] = '\0';
}
}
}
log_info("Got: %s, %s, %s, %s, %s, as input.", query[0], query[1], query[2], query[3], query[4]);
// Return error if query/message content is empty
if (!*query[0])
{
struct discord_embed_field fields[] = {
{
.name = "I need something to search for.",
.value = "Usage: !passmark <cpu (approximate or exact)> | <cpu 2 (optional)> | <cpu 3 (optional)> | <cpu 4 (optional)> | <cpu 5 (optional)>.",
},
};
struct discord_embed embeds[] = {
{
.title = ":P",
.color = 0x3498DB,
.timestamp = discord_timestamp(client),
.footer =
&(struct discord_embed_footer){
.text = "PassmarkBot made with ❤️ by r5900 (decentcarp).",
},
.fields =
&(struct discord_embed_fields){
.size = sizeof(fields) / sizeof *fields,
.array = fields,
},
},
};
struct discord_create_message params = {
.embeds =
&(struct discord_embeds){
.size = sizeof(embeds) / sizeof *embeds,
.array = embeds,
},
};
discord_create_message(client, event->channel_id, ¶ms, NULL);
return;
}
// Opens passmark.txt
FILE *file;
file = fopen("passmark.txt", "r");
// Returns error if passmark.txt cannot be found or opened
if (file == NULL)
{
log_info("I couldn't find the specified database file :C");
return;
}
// Init struct & read values from passmark.txt into CPUSpecs struct array, capped at 7000 entries and 7 string values per array entry (it HAS to be 7 values)
static CPUSpecs cpuspecs[7000];
int readvalues = 0;
int numberofcpus = 0;
while ((readvalues = fscanf(file,
"%255[^,],%255[^,],%255[^,],%255[^,],%255[^,],%255[^,],%255[^\r\n]%*[\r\n]",
cpuspecs[numberofcpus].cpuname,
cpuspecs[numberofcpus].cores,
cpuspecs[numberofcpus].multi,
cpuspecs[numberofcpus].single,
cpuspecs[numberofcpus].tdp,
cpuspecs[numberofcpus].socket,
cpuspecs[numberofcpus].type)) == 7)
{
if (numberofcpus >= 7000)
break;
numberofcpus++;
}
// Returns error if passmark.txt is not formatted correctly
if (readvalues != EOF)
{
log_info("The database file is not formatted correctly :C\n");
return;
}
// Close passmark.txt as we're done using it
fclose(file);
if (event->author->bot)
return;
// Read through through CPUSpecs struct array and search for a matching CPU using tokenise_query_and_search, with query as the input
int i;
for (i = 0; i < numberofcpus; i++)
{
if (tokenise_query_and_search(cpuspecs[i].cpuname, query[0]))
{
// If query 2 is empty, skip searching query 2 to 5 and display the results for query 1
if (!*query[1])
{
char name[256] = "";
sprintf(name, "**%s**", cpuspecs[i].cpuname);
char performance[256] = "";
// Check if TDP is 0, and if so, don't parse it into the performance string
if (cpuspecs[i].tdp[0] == '\0' || strcmp(cpuspecs[i].tdp, "0") == 0)
{
sprintf(performance, "**Single:** %s | **Multi:** %s", cpuspecs[i].single, cpuspecs[i].multi);
}
else
{
sprintf(performance, "**Single:** %s | **Multi:** %s | **TDP:** %sW", cpuspecs[i].single, cpuspecs[i].multi, cpuspecs[i].tdp);
}
// Send an embed containing name (CPU name) and performance (single thread performance, multi thread performance and TDP if not 0)
struct discord_embed_field fields[] = {
{
.name = name,
.value = performance,
},
};
struct discord_embed embeds[] = {
{
.color = 0x3498DB,
.timestamp = discord_timestamp(client),
.fields =
&(struct discord_embed_fields){
.size = sizeof(fields) / sizeof *fields,
.array = fields,
},
},
};
struct discord_create_message params = {
.embeds =
&(struct discord_embeds){
.size = sizeof(embeds) / sizeof *embeds,
.array = embeds,
},
};
discord_create_message(client, event->channel_id, ¶ms, NULL);
}
// If query 3 is empty, skip searching query 3 to 5 and display the results for query 1 and 2 (if query 2 is not empty)
else if (!*query[2] && !*query[3] && !*query[4])
{
int i2;
// Read through through CPUSpecs struct array yet again and search for the second CPU using tokenise_query_and_search, with query2 as the input
for (i2 = 0; i2 < numberofcpus; i2++)
{
if (tokenise_query_and_search(cpuspecs[i2].cpuname, query[1]))
{
// Save first CPU's name and performance into cpu1name and cpu1performance
char cpu1name[256] = "";
sprintf(cpu1name, "**%s**", cpuspecs[i].cpuname);
char cpu1performance[256] = "";
// For percentage difference
int cpusingle1 = atoi(cpuspecs[i].single);
int cpusingle2 = atoi(cpuspecs[i2].single);
int cpumulti1 = atoi(cpuspecs[i].multi);
int cpumulti2 = atoi(cpuspecs[i2].multi);
int sdiff = (cpusingle1 - cpusingle2) * 100 / cpusingle2;
int mdiff = (cpumulti1 - cpumulti2) * 100 / cpumulti2;
// Check if TDP is 0, and if so, don't parse it into the performance string (for first CPU)
if (cpuspecs[i].tdp[0] == '\0' || strcmp(cpuspecs[i].tdp, "0") == 0)
{
if (cpusingle1 > cpusingle2)
{
if (cpumulti1 > cpumulti2)
{
sprintf(cpu1performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)*", cpuspecs[i].single, sdiff, cpuspecs[i].multi, mdiff);
}
else
{
sprintf(cpu1performance, "**Single:** %s *(+%d%%)* | **Multi:** %s", cpuspecs[i].single, sdiff, cpuspecs[i].multi);
}
}
else
{
if (cpumulti1 > cpumulti2)
{
sprintf(cpu1performance, "**Single:** %s | **Multi:** %s *(+%d%%)*", cpuspecs[i].single, cpuspecs[i].multi, mdiff);
}
else
{
sprintf(cpu1performance, "**Single:** %s | **Multi:** %s", cpuspecs[i].single, cpuspecs[i].multi);
}
}
}
else
{
if (cpusingle1 > cpusingle2)
{
if (cpumulti1 > cpumulti2)
{
sprintf(cpu1performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i].single, sdiff, cpuspecs[i].multi, mdiff, cpuspecs[i].tdp);
}
else
{
sprintf(cpu1performance, "**Single:** %s *(+%d%%)* | **Multi:** %s | **TDP:** %sW", cpuspecs[i].single, sdiff, cpuspecs[i].multi, cpuspecs[i].tdp);
}
}
else
{
if (cpumulti1 > cpumulti2)
{
sprintf(cpu1performance, "**Single:** %s | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i].single, cpuspecs[i].multi, mdiff, cpuspecs[i].tdp);
}
else
{
sprintf(cpu1performance, "**Single:** %s | **Multi:** %s | **TDP:** %sW", cpuspecs[i].single, cpuspecs[i].multi, cpuspecs[i].tdp);
}
}
}
// Same drill, save second CPU's name and performance into cpu2name and cpu2performance
char cpu2name[256] = "";
sprintf(cpu2name, "**%s**", cpuspecs[i2].cpuname);
char cpu2performance[256] = "";
// for percentage difference
int cpusingle1b = atoi(cpuspecs[i].single);
int cpusingle2b = atoi(cpuspecs[i2].single);
int cpumulti1b = atoi(cpuspecs[i].multi);
int cpumulti2b = atoi(cpuspecs[i2].multi);
int sdiffb = (cpusingle2b - cpusingle1b) * 100 / cpusingle1b;
int mdiffb = (cpumulti2b - cpumulti1b) * 100 / cpumulti1b;
// Check if TDP is 0, and if so, don't parse it into the performance string (for second CPU)
if (cpuspecs[i2].tdp[0] == '\0' || strcmp(cpuspecs[i2].tdp, "0") == 0)
{
if (cpusingle2b > cpusingle1b)
{
if (cpumulti2b > cpumulti1b)
{
sprintf(cpu2performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)*", cpuspecs[i2].single, sdiffb, cpuspecs[i2].multi, mdiffb);
}
else
{
sprintf(cpu2performance, "**Single:** %s *(+%d%%)* | **Multi:** %s", cpuspecs[i2].single, sdiffb, cpuspecs[i2].multi);
}
}
else
{
if (cpumulti2b > cpumulti1b)
{
sprintf(cpu2performance, "**Single:** %s | **Multi:** %s *(+%d%%)*", cpuspecs[i2].single, cpuspecs[i2].multi, mdiffb);
}
else
{
sprintf(cpu2performance, "**Single:** %s | **Multi:** %s", cpuspecs[i2].single, cpuspecs[i2].multi);
}
}
}
else
{
if (cpusingle2b > cpusingle1b)
{
if (cpumulti2b > cpumulti1b)
{
sprintf(cpu2performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i2].single, sdiffb, cpuspecs[i2].multi, mdiffb, cpuspecs[i2].tdp);
}
else
{
sprintf(cpu2performance, "**Single:** %s *(+%d%%)* | **Multi:** %s | **TDP:** %sW", cpuspecs[i2].single, sdiffb, cpuspecs[i2].multi, cpuspecs[i2].tdp);
}
}
else
{
if (cpumulti2b > cpumulti1b)
{
sprintf(cpu2performance, "**Single:** %s | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i2].single, cpuspecs[i2].multi, mdiffb, cpuspecs[i2].tdp);
}
else
{
sprintf(cpu2performance, "**Single:** %s | **Multi:** %s | **TDP:** %sW", cpuspecs[i2].single, cpuspecs[i2].multi, cpuspecs[i2].tdp);
}
}
}
// Send an embed containing the two CPU's name and performance, with the first CPUs name and performance being on the first two lines, and the second CPU's name and performance being on the last two lines
struct discord_embed_field fields[] = {
{
.name = cpu1name,
.value = cpu1performance,
},
{
.name = cpu2name,
.value = cpu2performance,
},
};
struct discord_embed embeds[] = {
{
.color = 0x3498DB,
.timestamp = discord_timestamp(client),
.fields =
&(struct discord_embed_fields){
.size = sizeof(fields) / sizeof *fields,
.array = fields,
},
},
};
struct discord_create_message params = {
.embeds =
&(struct discord_embeds){
.size = sizeof(embeds) / sizeof *embeds,
.array = embeds,
},
};
discord_create_message(client, event->channel_id, ¶ms, NULL);
break;
}
}
}
// If query 4 is empty, skip searching query 4 to 5 and display the results for query 1, 2 and 3 (if query 2 and 3 aren't empty)
else if (!*query[3] && !*query[4])
{
int i2;
// Read through through CPUSpecs struct array yet again and search for the second CPU using tokenise_query_and_search, with query2 as the input
for (i2 = 0; i2 < numberofcpus; i2++)
{
if (tokenise_query_and_search(cpuspecs[i2].cpuname, query[1]))
{
int i3;
for (i3 = 0; i3 < numberofcpus; i3++)
{
if (tokenise_query_and_search(cpuspecs[i3].cpuname, query[2]))
{
// Save first CPU's name and performance into cpu1name and cpu1performance
char cpu1name[256] = "";
sprintf(cpu1name, "**%s**", cpuspecs[i].cpuname);
char cpu1performance[256] = "";
// For percentage difference
int cpusingle1 = atoi(cpuspecs[i].single);
int cpusingle2 = atoi(cpuspecs[i2].single);
int cpumulti1 = atoi(cpuspecs[i].multi);
int cpumulti2 = atoi(cpuspecs[i2].multi);
int sdiff = (cpusingle2 - cpusingle1) * 100 / cpusingle2;
int mdiff = (cpumulti2 - cpumulti1) * 100 / cpumulti2;
// Check if TDP is 0, and if so, don't parse it into the performance string (for first CPU)
if (cpuspecs[i].tdp[0] == '\0' || strcmp(cpuspecs[i].tdp, "0") == 0)
{
if (cpusingle1 > cpusingle2)
{
if (cpumulti1 > cpumulti2)
{
sprintf(cpu1performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)*", cpuspecs[i].single, sdiff, cpuspecs[i].multi, mdiff);
}
else
{
sprintf(cpu1performance, "**Single:** %s *(+%d%%)* | **Multi:** %s", cpuspecs[i].single, sdiff, cpuspecs[i].multi);
}
}
else
{
if (cpumulti1 > cpumulti2)
{
sprintf(cpu1performance, "**Single:** %s | **Multi:** %s *(+%d%%)*", cpuspecs[i].single, cpuspecs[i].multi, mdiff);
}
else
{
sprintf(cpu1performance, "**Single:** %s | **Multi:** %s", cpuspecs[i].single, cpuspecs[i].multi);
}
}
}
else
{
if (cpusingle1 > cpusingle2)
{
if (cpumulti1 > cpumulti2)
{
sprintf(cpu1performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i].single, sdiff, cpuspecs[i].multi, mdiff, cpuspecs[i].tdp);
}
else
{
sprintf(cpu1performance, "**Single:** %s *(+%d%%)* | **Multi:** %s | **TDP:** %sW", cpuspecs[i].single, sdiff, cpuspecs[i].multi, cpuspecs[i].tdp);
}
}
else
{
if (cpumulti1 > cpumulti2)
{
sprintf(cpu1performance, "**Single:** %s | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i].single, cpuspecs[i].multi, mdiff, cpuspecs[i].tdp);
}
else
{
sprintf(cpu1performance, "**Single:** %s | **Multi:** %s | **TDP:** %sW", cpuspecs[i].single, cpuspecs[i].multi, cpuspecs[i].tdp);
}
}
}
// Same drill, save second CPU's name and performance into cpu2name and cpu2performance
char cpu2name[256] = "";
sprintf(cpu2name, "**%s**", cpuspecs[i2].cpuname);
char cpu2performance[256] = "";
// for percentage difference
int cpusingle1b = atoi(cpuspecs[i].single);
int cpusingle2b = atoi(cpuspecs[i2].single);
int cpumulti1b = atoi(cpuspecs[i].multi);
int cpumulti2b = atoi(cpuspecs[i2].multi);
int sdiffb = (cpusingle2b - cpusingle1b) * 100 / cpusingle1b;
int mdiffb = (cpumulti2b - cpumulti1b) * 100 / cpumulti1b;
// Check if TDP is 0, and if so, don't parse it into the performance string (for second CPU)
if (cpuspecs[i2].tdp[0] == '\0' || strcmp(cpuspecs[i2].tdp, "0") == 0)
{
if (cpusingle2b > cpusingle1b)
{
if (cpumulti2b > cpumulti1b)
{
sprintf(cpu2performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)*", cpuspecs[i2].single, sdiffb, cpuspecs[i2].multi, mdiffb);
}
else
{
sprintf(cpu2performance, "**Single:** %s *(+%d%%)* | **Multi:** %s", cpuspecs[i2].single, sdiffb, cpuspecs[i2].multi);
}
}
else
{
if (cpumulti2b > cpumulti1b)
{
sprintf(cpu2performance, "**Single:** %s | **Multi:** %s *(+%d%%)*", cpuspecs[i2].single, cpuspecs[i2].multi, mdiffb);
}
else
{
sprintf(cpu2performance, "**Single:** %s | **Multi:** %s", cpuspecs[i2].single, cpuspecs[i2].multi);
}
}
}
else
{
if (cpusingle2b > cpusingle1b)
{
if (cpumulti2b > cpumulti1b)
{
sprintf(cpu2performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i2].single, sdiffb, cpuspecs[i2].multi, mdiffb, cpuspecs[i2].tdp);
}
else
{
sprintf(cpu2performance, "**Single:** %s *(+%d%%)* | **Multi:** %s | **TDP:** %sW", cpuspecs[i2].single, sdiffb, cpuspecs[i2].multi, cpuspecs[i2].tdp);
}
}
else
{
if (cpumulti2b > cpumulti1b)
{
sprintf(cpu2performance, "**Single:** %s | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i2].single, cpuspecs[i2].multi, mdiffb, cpuspecs[i2].tdp);
}
else
{
sprintf(cpu2performance, "**Single:** %s | **Multi:** %s | **TDP:** %sW", cpuspecs[i2].single, cpuspecs[i2].multi, cpuspecs[i2].tdp);
}
}
}
// Save third CPU's name and performance
char cpu3name[256] = "";
sprintf(cpu3name, "**%s**", cpuspecs[i3].cpuname);
char cpu3performance[256] = "";
// for percentage difference
int cpusingle1c = atoi(cpuspecs[i].single);
int cpusingle3 = atoi(cpuspecs[i3].single);
int cpumulti1c = atoi(cpuspecs[i].multi);
int cpumulti3 = atoi(cpuspecs[i3].multi);
int sdiffc = (cpusingle3 - cpusingle1c) * 100 / cpusingle1c;
int mdiffc = (cpumulti3 - cpumulti1c) * 100 / cpumulti1c;
// Check if TDP is 0, and if so, don't parse it into the performance string (for third CPU)
if (cpuspecs[i3].tdp[0] == '\0' || strcmp(cpuspecs[i3].tdp, "0") == 0)
{
if (cpusingle1c < cpusingle3)
{
if (cpumulti1c < cpumulti3)
{
sprintf(cpu3performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)*", cpuspecs[i3].single, sdiffc, cpuspecs[i3].multi, mdiffc);
}
else
{
sprintf(cpu3performance, "**Single:** %s *(+%d%%)* | **Multi:** %s", cpuspecs[i3].single, sdiffc, cpuspecs[i3].multi);
}
}
else
{
if (cpumulti1c < cpumulti3)
{
sprintf(cpu3performance, "**Single:** %s | **Multi:** %s *(+%d%%)*", cpuspecs[i3].single, cpuspecs[i3].multi, mdiffc);
}
else
{
sprintf(cpu3performance, "**Single:** %s | **Multi:** %s", cpuspecs[i3].single, cpuspecs[i3].multi);
}
}
}
else
{
if (cpusingle1c < cpusingle3)
{
if (cpumulti1c < cpumulti3)
{
sprintf(cpu3performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i3].single, sdiffc, cpuspecs[i3].multi, mdiffc, cpuspecs[i3].tdp);
}
else
{
sprintf(cpu3performance, "**Single:** %s *(+%d%%)* | **Multi:** %s | **TDP:** %sW", cpuspecs[i3].single, sdiffc, cpuspecs[i3].multi, cpuspecs[i3].tdp);
}
}
else
{
if (cpumulti1c < cpumulti3)
{
sprintf(cpu3performance, "**Single:** %s | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i3].single, cpuspecs[i3].multi, mdiffc, cpuspecs[i3].tdp);
}
else
{
sprintf(cpu3performance, "**Single:** %s | **Multi:** %s | **TDP:** %sW", cpuspecs[i3].single, cpuspecs[i3].multi, cpuspecs[i3].tdp);
}
}
}
// Send an embed containing the three CPU's name and performance, with the first CPUs name and performance being on the first two lines, and the second CPU's name and performance being on the last two lines
struct discord_embed_field fields[] = {
{
.name = cpu1name,
.value = cpu1performance,
},
{
.name = cpu2name,
.value = cpu2performance,
},
{
.name = cpu3name,
.value = cpu3performance,
},
};
struct discord_embed embeds[] = {
{
.color = 0x3498DB,
.timestamp = discord_timestamp(client),
.footer =
&(struct discord_embed_footer){
.text = "Percentages calculated using the first CPU as a baseline.",
},
.fields =
&(struct discord_embed_fields){
.size = sizeof(fields) / sizeof *fields,
.array = fields,
},
},
};
struct discord_create_message params = {
.embeds =
&(struct discord_embeds){
.size = sizeof(embeds) / sizeof *embeds,
.array = embeds,
},
};
discord_create_message(client, event->channel_id, ¶ms, NULL);
break;
}
}
break;
}
}
break;
}
// If query 5 is empty, skip searching query 5 and display the results for query 1, 2, 3 and 4 (if query 2, 3 and 4 aren't empty)
else if (!*query[4])
{
int i2;
// Read through through CPUSpecs struct array yet again and search for the second CPU using tokenise_query_and_search, with query2 as the input
for (i2 = 0; i2 < numberofcpus; i2++)
{
if (tokenise_query_and_search(cpuspecs[i2].cpuname, query[1]))
{
int i3;
for (i3 = 0; i3 < numberofcpus; i3++)
{
if (tokenise_query_and_search(cpuspecs[i3].cpuname, query[2]))
{
int i4;
for (i4 = 0; i4 < numberofcpus; i4++)
{
if (tokenise_query_and_search(cpuspecs[i4].cpuname, query[3]))
{
// Save first CPU's name and performance into cpu1name and cpu1performance
char cpu1name[256] = "";
sprintf(cpu1name, "**%s**", cpuspecs[i].cpuname);
char cpu1performance[256] = "";
// For percentage difference
int cpusingle1 = atoi(cpuspecs[i].single);
int cpusingle2 = atoi(cpuspecs[i2].single);
int cpumulti1 = atoi(cpuspecs[i].multi);
int cpumulti2 = atoi(cpuspecs[i2].multi);
int sdiff = (cpusingle1 - cpusingle2) * 100 / cpusingle2;
int mdiff = (cpumulti1 - cpumulti2) * 100 / cpumulti2;
// Check if TDP is 0, and if so, don't parse it into the performance string (for first CPU)
if (cpuspecs[i].tdp[0] == '\0' || strcmp(cpuspecs[i].tdp, "0") == 0)
{
if (cpusingle1 > cpusingle2)
{
if (cpumulti1 > cpumulti2)
{
sprintf(cpu1performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)*", cpuspecs[i].single, sdiff, cpuspecs[i].multi, mdiff);
}
else
{
sprintf(cpu1performance, "**Single:** %s *(+%d%%)* | **Multi:** %s", cpuspecs[i].single, sdiff, cpuspecs[i].multi);
}
}
else
{
if (cpumulti1 > cpumulti2)
{
sprintf(cpu1performance, "**Single:** %s | **Multi:** %s *(+%d%%)*", cpuspecs[i].single, cpuspecs[i].multi, mdiff);
}
else
{
sprintf(cpu1performance, "**Single:** %s | **Multi:** %s", cpuspecs[i].single, cpuspecs[i].multi);
}
}
}
else
{
if (cpusingle1 > cpusingle2)
{
if (cpumulti1 > cpumulti2)
{
sprintf(cpu1performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i].single, sdiff, cpuspecs[i].multi, mdiff, cpuspecs[i].tdp);
}
else
{
sprintf(cpu1performance, "**Single:** %s *(+%d%%)* | **Multi:** %s | **TDP:** %sW", cpuspecs[i].single, sdiff, cpuspecs[i].multi, cpuspecs[i].tdp);
}
}
else
{
if (cpumulti1 > cpumulti2)
{
sprintf(cpu1performance, "**Single:** %s | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i].single, cpuspecs[i].multi, mdiff, cpuspecs[i].tdp);
}
else
{
sprintf(cpu1performance, "**Single:** %s | **Multi:** %s | **TDP:** %sW", cpuspecs[i].single, cpuspecs[i].multi, cpuspecs[i].tdp);
}
}
}
// Same drill, save second CPU's name and performance into cpu2name and cpu2performance
char cpu2name[256] = "";
sprintf(cpu2name, "**%s**", cpuspecs[i2].cpuname);
char cpu2performance[256] = "";
// for percentage difference
int cpusingle1b = atoi(cpuspecs[i].single);
int cpusingle2b = atoi(cpuspecs[i2].single);
int cpumulti1b = atoi(cpuspecs[i].multi);
int cpumulti2b = atoi(cpuspecs[i2].multi);
int sdiffb = (cpusingle2b - cpusingle1b) * 100 / cpusingle1b;
int mdiffb = (cpumulti2b - cpumulti1b) * 100 / cpumulti1b;
// Check if TDP is 0, and if so, don't parse it into the performance string (for second CPU)
if (cpuspecs[i2].tdp[0] == '\0' || strcmp(cpuspecs[i2].tdp, "0") == 0)
{
if (cpusingle2b > cpusingle1b)
{
if (cpumulti2b > cpumulti1b)
{
sprintf(cpu2performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)*", cpuspecs[i2].single, sdiffb, cpuspecs[i2].multi, mdiffb);
}
else
{
sprintf(cpu2performance, "**Single:** %s *(+%d%%)* | **Multi:** %s", cpuspecs[i2].single, sdiffb, cpuspecs[i2].multi);
}
}
else
{
if (cpumulti2b > cpumulti1b)
{
sprintf(cpu2performance, "**Single:** %s | **Multi:** %s *(+%d%%)*", cpuspecs[i2].single, cpuspecs[i2].multi, mdiffb);
}
else
{
sprintf(cpu2performance, "**Single:** %s | **Multi:** %s", cpuspecs[i2].single, cpuspecs[i2].multi);
}
}
}
else
{
if (cpusingle2b > cpusingle1b)
{
if (cpumulti2b > cpumulti1b)
{
sprintf(cpu2performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i2].single, sdiffb, cpuspecs[i2].multi, mdiffb, cpuspecs[i2].tdp);
}
else
{
sprintf(cpu2performance, "**Single:** %s *(+%d%%)* | **Multi:** %s | **TDP:** %sW", cpuspecs[i2].single, sdiffb, cpuspecs[i2].multi, cpuspecs[i2].tdp);
}
}
else
{
if (cpumulti2b > cpumulti1b)
{
sprintf(cpu2performance, "**Single:** %s | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i2].single, cpuspecs[i2].multi, mdiffb, cpuspecs[i2].tdp);
}
else
{
sprintf(cpu2performance, "**Single:** %s | **Multi:** %s | **TDP:** %sW", cpuspecs[i2].single, cpuspecs[i2].multi, cpuspecs[i2].tdp);
}
}
}
// Save third CPU's name and performance
char cpu3name[256] = "";
sprintf(cpu3name, "**%s**", cpuspecs[i3].cpuname);
char cpu3performance[256] = "";
// for percentage difference
int cpusingle1c = atoi(cpuspecs[i].single);
int cpusingle3 = atoi(cpuspecs[i3].single);
int cpumulti1c = atoi(cpuspecs[i].multi);
int cpumulti3 = atoi(cpuspecs[i3].multi);
int sdiffc = (cpusingle3 - cpusingle1c) * 100 / cpusingle1c;
int mdiffc = (cpumulti3 - cpumulti1c) * 100 / cpumulti1c;
// Check if TDP is 0, and if so, don't parse it into the performance string (for third CPU)
if (cpuspecs[i3].tdp[0] == '\0' || strcmp(cpuspecs[i3].tdp, "0") == 0)
{
if (cpusingle1c < cpusingle3)
{
if (cpumulti1c < cpumulti3)
{
sprintf(cpu3performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)*", cpuspecs[i3].single, sdiffc, cpuspecs[i3].multi, mdiffc);
}
else
{
sprintf(cpu3performance, "**Single:** %s *(+%d%%)* | **Multi:** %s", cpuspecs[i3].single, sdiffc, cpuspecs[i3].multi);
}
}
else
{
if (cpumulti1c < cpumulti3)
{
sprintf(cpu3performance, "**Single:** %s | **Multi:** %s *(+%d%%)*", cpuspecs[i3].single, cpuspecs[i3].multi, mdiffc);
}
else
{
sprintf(cpu3performance, "**Single:** %s | **Multi:** %s", cpuspecs[i3].single, cpuspecs[i3].multi);
}
}
}
else
{
if (cpusingle1c < cpusingle3)
{
if (cpumulti1c < cpumulti3)
{
sprintf(cpu3performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i3].single, sdiffc, cpuspecs[i3].multi, mdiffc, cpuspecs[i3].tdp);
}
else
{
sprintf(cpu3performance, "**Single:** %s *(+%d%%)* | **Multi:** %s | **TDP:** %sW", cpuspecs[i3].single, sdiffc, cpuspecs[i3].multi, cpuspecs[i3].tdp);
}
}
else
{
if (cpumulti1c < cpumulti3)
{
sprintf(cpu3performance, "**Single:** %s | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i3].single, cpuspecs[i3].multi, mdiffc, cpuspecs[i3].tdp);
}
else
{
sprintf(cpu3performance, "**Single:** %s | **Multi:** %s | **TDP:** %sW", cpuspecs[i3].single, cpuspecs[i3].multi, cpuspecs[i3].tdp);
}
}
}
// Save fourth CPU's name and performance
char cpu4name[256] = "";
sprintf(cpu4name, "**%s**", cpuspecs[i4].cpuname);
char cpu4performance[256] = "";
// for percentage difference
int cpusingle1d = atoi(cpuspecs[i].single);
int cpusingle4 = atoi(cpuspecs[i4].single);
int cpumulti1d = atoi(cpuspecs[i].multi);
int cpumulti4 = atoi(cpuspecs[i4].multi);
int sdiffd = (cpusingle4 - cpusingle1d) * 100 / cpusingle1d;
int mdiffd = (cpumulti4 - cpumulti1d) * 100 / cpumulti1d;
// Check if TDP is 0, and if so, don't parse it into the performance string (for third CPU)
if (cpuspecs[i4].tdp[0] == '\0' || strcmp(cpuspecs[i4].tdp, "0") == 0)
{
if (cpusingle1d < cpusingle4)
{
if (cpumulti1d < cpumulti4)
{
sprintf(cpu4performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)*", cpuspecs[i4].single, sdiffd, cpuspecs[i4].multi, mdiffd);
}
else
{
sprintf(cpu4performance, "**Single:** %s *(+%d%%)* | **Multi:** %s", cpuspecs[i4].single, sdiffd, cpuspecs[i4].multi);
}
}
else
{
if (cpumulti1d < cpumulti4)
{
sprintf(cpu4performance, "**Single:** %s | **Multi:** %s *(+%d%%)*", cpuspecs[i4].single, cpuspecs[i4].multi, mdiffd);
}
else
{
sprintf(cpu4performance, "**Single:** %s | **Multi:** %s", cpuspecs[i4].single, cpuspecs[i4].multi);
}
}
}
else
{
if (cpusingle1d < cpusingle4)
{
if (cpumulti1d < cpumulti4)
{
sprintf(cpu4performance, "**Single:** %s *(+%d%%)* | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i4].single, sdiffd, cpuspecs[i4].multi, mdiffd, cpuspecs[i4].tdp);
}
else
{
sprintf(cpu4performance, "**Single:** %s *(+%d%%)* | **Multi:** %s | **TDP:** %sW", cpuspecs[i4].single, sdiffd, cpuspecs[i4].multi, cpuspecs[i4].tdp);
}
}
else
{
if (cpumulti1d < cpumulti4)
{
sprintf(cpu4performance, "**Single:** %s | **Multi:** %s *(+%d%%)* | **TDP:** %sW", cpuspecs[i4].single, cpuspecs[i4].multi, mdiffd, cpuspecs[i4].tdp);
}
else
{
sprintf(cpu4performance, "**Single:** %s | **Multi:** %s | **TDP:** %sW", cpuspecs[i4].single, cpuspecs[i4].multi, cpuspecs[i4].tdp);
}
}
}
// Send an embed containing the two CPU's name and performance, with the first CPUs name and performance being on the first two lines, and the second CPU's name and performance being on the last two lines
struct discord_embed_field fields[] = {
{
.name = cpu1name,
.value = cpu1performance,
},
{
.name = cpu2name,