Skip to content

Commit

Permalink
Minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorAU committed Nov 18, 2020
1 parent ebb783a commit ddf2308
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 51 deletions.
8 changes: 0 additions & 8 deletions addon/external/_config.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/*──────────────────────────────────────────────────────┐
│ Author: Connor │
│ Steam: https://steamcommunity.com/id/_connor │
│ Github: https://github.com/ConnorAU │
│ │
│ Please do not modify or remove this comment block │
└──────────────────────────────────────────────────────*/

// Developer info: https://github.com/ConnorAU/SQFDiscordEmbedBuilder/blob/master/README.md

class CfgDiscordEmbedWebhooks {
Expand Down
10 changes: 1 addition & 9 deletions addon/pbo/config.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/*──────────────────────────────────────────────────────┐
│ Author: Connor │
│ Steam: https://steamcommunity.com/id/_connor │
│ Github: https://github.com/ConnorAU │
│ │
│ Please do not modify or remove this comment block │
└──────────────────────────────────────────────────────*/

// You don't need to worry about this stuff
#include "\@DiscordEmbedBuilder\external\_config.cpp"
class CfgPatches {
Expand All @@ -31,4 +23,4 @@ class CfgFunctions {
class send {};
};
};
};
};
55 changes: 33 additions & 22 deletions addon/pbo/fn_buildCfg.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ params [["_template","",[""]],["_textParameters",[],[[]]]];
private _cfgDir = configFile >> "CfgDiscordEmbedBuilder" >> _template;
if (isNull _cfgDir) exitwith {false};

private _emptyString = { [EMPTY_STRING,_this] select (_this != ""); };
private _emptyString = { [_this,EMPTY_STRING] select (_this == ""); };
private _formatString = {
params [["_str","",[""]],["_replaceEmpty",true,[true]]];
private _str = format([_str]+_textParameters);
Expand All @@ -41,41 +41,52 @@ private _avatar = getText(_cfgDir >> "avatar");
private _tts = getNumber(_cfgDir >> "tts") isEqualTo 1;
private _embeds = "true" configClasses (_cfgDir >> "embeds");

private ["_title","_description","_url","_color","_timestamp","_thumbnail","_image","_timestamp","_authorName","_authorURL","_authorImage","_author","_footerText","_footerImage","_footer","_fields"];
{
_title = getText(_x >> "title") call _formatString;
_description = getText(_x >> "description") call _formatString;
_url = getText(_x >> "url") call _emptyString;
_color = getText(_x >> "color") call _formatString;
_timestamp = getNumber(_x >> "timestamp");
_thumbnail = getText(_x >> "thumbnail") call _emptyString;
_image = getText(_x >> "image") call _emptyString;
_embeds = _embeds apply {
private _title = getText(_x >> "title") call _formatString;
private _description = getText(_x >> "description") call _formatString;
private _url = getText(_x >> "url") call _emptyString;
private _color = getText(_x >> "color") call _formatString;
private _timestamp = getNumber(_x >> "timestamp");
private _thumbnail = getText(_x >> "thumbnail") call _emptyString;
private _image = getText(_x >> "image") call _emptyString;

// tobool
_timestamp = _timestamp isEqualTo 1;
private _timestamp = _timestamp isEqualTo 1;

// Author things
_authorName = getText(_x >> "Author" >> "name") call _formatString;
_authorURL = getText(_x >> "Author" >> "url") call _emptyString;
_authorImage = getText(_x >> "Author" >> "image") call _emptyString;
_author = [[],[_authorName,_authorURL,_authorImage]] select (_authorName != EMPTY_STRING);
private _authorName = getText(_x >> "Author" >> "name") call _formatString;
private _author = if (_authorName == EMPTY_STRING) then {[]} else {
[
_authorName,
getText(_x >> "Author" >> "url") call _emptyString,
getText(_x >> "Author" >> "image") call _emptyString
]
};

// Footer things
_footerText = getText(_x >> "Footer" >> "text") call _formatString;
_footerImage = getText(_x >> "Footer" >> "image") call _emptyString;
_footer = [[],[_footerText,_footerImage]] select (_footerText != EMPTY_STRING);
private _footerText = getText(_x >> "Footer" >> "text") call _formatString;
private _footer = if (_footerText == EMPTY_STRING) then {[]} else {
[
_footerText,
getText(_x >> "Footer" >> "image") call _emptyString
]
};

// Field things
_fields = getArray(_x >> "fields") apply {
private _fields = getArray(_x >> "fields") apply {
_x params [
["_fieldName","",[""]],
["_fieldContent","",[""]],
["_fieldInline",0,[0]]
];
[_fieldName call _formatString,_fieldContent call _formatString,_fieldInline isEqualTo 1];
[
_fieldName call _formatString,
_fieldContent call _formatString,
_fieldInline isEqualTo 1
]
};

_embeds set [_forEachIndex,[_title,_description,_url,_color,_timestamp,_thumbnail,_image,_author,_footer,_fields]];
} foreach _embeds;
[_title,_description,_url,_color,_timestamp,_thumbnail,_image,_author,_footer,_fields]
};

[_webhookurl,_message,_username,_avatar,_tts,_embeds] call DiscordEmbedBuilder_fnc_send;
36 changes: 24 additions & 12 deletions addon/pbo/fn_buildSqf.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Example 2:

if !(uiNamespace getVariable ["DiscordEmbedBuilder_LoadSuccess",false]) exitwith {false};

private _emptyString = { [EMPTY_STRING,_this] select (_this != ""); };
private _emptyString = { [_this,EMPTY_STRING] select (_this == ""); };

params [
["_webhookName","",[""]],
Expand All @@ -103,7 +103,7 @@ params [
];

private _webhookurl = getText(configFile >> "CfgDiscordEmbedWebhooks" >> _webhookName);
{
_embeds = _embeds apply {
_x params [
["_title","",[""]],
["_description","",[""]],
Expand Down Expand Up @@ -132,18 +132,26 @@ private _webhookurl = getText(configFile >> "CfgDiscordEmbedWebhooks" >> _webhoo
["_authorImage","",[""]]
];
_authorName = _authorName call _emptyString;
_authorURL = _authorURL call _emptyString;
_authorImage = _authorImage call _emptyString;
_author = [[],[_authorName,_authorURL,_authorImage]] select (_authorName != EMPTY_STRING);
_author = if (_authorName == EMPTY_STRING) then {[]} else {
[
_authorName,
_authorURL call _emptyString,
_authorImage call _emptyString
]
};

// Footer things
_footer params [
["_footerName","",[""]],
["_footerText","",[""]],
["_footerImage","",[""]]
];
_footerName = _footerName call _emptyString;
_footerImage = _footerImage call _emptyString;
_footer = [[],[_footerName,_footerImage]] select (_footerName != EMPTY_STRING);
_footerText = _footerText call _emptyString;
_footer = if (_footerText == EMPTY_STRING) then {[]} else {
[
_footerText,
_footerImage call _emptyString
]
};

// Field things
_fields = _fields apply {
Expand All @@ -152,10 +160,14 @@ private _webhookurl = getText(configFile >> "CfgDiscordEmbedWebhooks" >> _webhoo
["_fieldContent","",[""]],
["_fieldInline",false,[true]]
];
[_fieldName call _emptyString,_fieldContent call _emptyString,_fieldInline];
[
_fieldName call _emptyString,
_fieldContent call _emptyString,
_fieldInline
]
};

_embeds set [_forEachIndex,[_title,_description,_url,_color,_timestamp,_thumbnail,_image,_author,_footer,_fields]];
} foreach _embeds;
[_title,_description,_url,_color,_timestamp,_thumbnail,_image,_author,_footer,_fields]
};

[_webhookurl,_message,_username,_avatar,_tts,_embeds] call DiscordEmbedBuilder_fnc_send;

0 comments on commit ddf2308

Please sign in to comment.