Skip to content

Commit 81152fc

Browse files
author
Nic Bradley
committed
ChatSetAttr | Improving Errors & Messages
1 parent a825a87 commit 81152fc

File tree

13 files changed

+290
-780
lines changed

13 files changed

+290
-780
lines changed

ChatSetAttr/2.0/ChatSetAttr.js

Lines changed: 79 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -67,125 +67,52 @@ var ChatSetAttr = (function (exports) {
6767
return `<${tagName}${attrs}>${childrenContent}</${tagName}>`;
6868
}
6969

70-
const COLOR_RED = {
71-
"50": "#ffebeb",
72-
"300": "#ff7474",
73-
"500": "#ff2020"};
74-
const COLOR_GREEN = {
75-
"500": "#00e626"};
76-
const COLOR_EMERALD = {
77-
"50": "#e6fff5",
78-
"300": "#4dffc7"};
79-
const COLOR_BLUE = {
80-
"50": "#e6f0ff",
81-
"100": "#b3d1ff",
82-
"300": "#4d94ff",
83-
"400": "#1a75ff",
84-
"600": "#0052b4",
85-
"800": "#002952",
86-
"900": "#001421",
70+
const buttonStyleBase = {
71+
border: "none",
72+
borderRadius: "4px",
73+
padding: "4px 8px",
74+
backgroundColor: "#e91ea2",
75+
color: "#FFFFFF",
76+
cursor: "pointer",
77+
fontWeight: "500",
8778
};
88-
const COLOR_STONE = {
89-
"50": "#fafaf9",
90-
"400": "#a8a29e",
91-
"700": "#44403c",
92-
"900": "#1c1917",
79+
const frameStyleBase = {
80+
border: "1px solid rgba(59, 130, 246, 0.3)",
81+
borderRadius: "8px",
82+
padding: "8px",
83+
backgroundColor: "rgba(59, 130, 246, 0.1)",
84+
};
85+
const frameStyleError = {
86+
border: "1px solid rgba(239, 68, 68, 0.4)",
87+
backgroundColor: "rgba(239, 68, 68, 0.1)",
88+
};
89+
const headerStyleBase = {
90+
fontSize: "1.5em",
91+
marginBottom: "0.5em",
9392
};
94-
const COLOR_WHITE = "#ffffff";
95-
const PADDING = {
96-
XS: "2px",
97-
SM: "4px",
98-
MD: "8px"};
99-
const MARGIN = {
100-
SM: "4px",
101-
MD: "8px"};
102-
const BORDER_RADIUS = {
103-
SM: "2px",
104-
MD: "4px"};
105-
const FONT_SIZE = {
106-
SM: "0.875rem",
107-
MD: "1rem",
108-
LG: "1.125rem"};
109-
const FONT_WEIGHT = {
110-
MEDIUM: "500",
111-
BOLD: "700"};
112-
const WRAPPER_STYLE = s({
113-
fontSize: FONT_SIZE.MD,
114-
});
115-
const LI_STYLE = s({
116-
fontSize: FONT_SIZE.MD,
117-
marginBottom: MARGIN.SM,
118-
});
119-
s({
120-
fontSize: FONT_SIZE.LG,
121-
fontWeight: FONT_WEIGHT.BOLD,
122-
marginBottom: MARGIN.MD,
123-
});
124-
const BUTTON_STYLE = s({
125-
padding: `${PADDING.SM} ${PADDING.MD}`,
126-
borderRadius: BORDER_RADIUS.MD,
127-
fontSize: FONT_SIZE.MD,
128-
fontWeight: FONT_WEIGHT.MEDIUM,
129-
color: COLOR_WHITE,
130-
backgroundColor: COLOR_BLUE["600"],
131-
border: "none",
132-
textDecoration: "none",
133-
});
134-
const PARAGRAPH_SPACING_STYLE = s({
135-
marginBottom: MARGIN.MD,
136-
});
13793

138-
const DELAY_WRAPPER_STYLE = s({
139-
border: `1px solid ${COLOR_STONE["400"]}`,
140-
borderRadius: BORDER_RADIUS.MD,
141-
padding: PADDING.MD,
142-
color: COLOR_STONE["900"],
143-
backgroundColor: COLOR_STONE["50"],
144-
});
145-
const DELAY_HEADER_STYLE = s({
146-
color: COLOR_STONE["700"],
147-
fontSize: FONT_SIZE.LG,
148-
fontWeight: "bold",
149-
marginBottom: PADDING.SM,
150-
});
151-
const DELAY_BODY_STYLE = s({
152-
fontSize: FONT_SIZE.SM,
153-
});
94+
const DELAY_WRAPPER_STYLE = s(frameStyleBase);
95+
const DELAY_HEADER_STYLE = s(headerStyleBase);
15496
function createDelayMessage() {
15597
return (h("div", { style: DELAY_WRAPPER_STYLE },
15698
h("div", { style: DELAY_HEADER_STYLE }, "Long Running Query"),
157-
h("div", { style: DELAY_BODY_STYLE }, "The operation is taking a long time to execute. This may be due to a large number of targets or attributes being processed. Please be patient as the operation completes.")));
99+
h("div", null, "The operation is taking a long time to execute. This may be due to a large number of targets or attributes being processed. Please be patient as the operation completes.")));
158100
}
159101

160-
// #region Chat Styles
161-
const CHAT_WRAPPER_STYLE = s({
162-
border: `1px solid ${COLOR_EMERALD["300"]}`,
163-
borderRadius: BORDER_RADIUS.MD,
164-
padding: PADDING.MD,
165-
backgroundColor: COLOR_EMERALD["50"],
166-
});
167-
const CHAT_HEADER_STYLE = s({
168-
fontSize: FONT_SIZE.LG,
169-
fontWeight: "bold",
170-
marginBottom: PADDING.SM,
171-
});
102+
const CHAT_WRAPPER_STYLE = s(frameStyleBase);
103+
const CHAT_HEADER_STYLE = s(headerStyleBase);
172104
const CHAT_BODY_STYLE = s({
173-
fontSize: FONT_SIZE.SM,
105+
fontSize: "14px",
106+
lineHeight: "1.4",
174107
});
175-
// #region Error Styles
176108
const ERROR_WRAPPER_STYLE = s({
177-
border: `1px solid ${COLOR_RED["300"]}`,
178-
borderRadius: BORDER_RADIUS.MD,
179-
padding: PADDING.MD,
180-
backgroundColor: COLOR_RED["50"],
181-
});
182-
const ERROR_HEADER_STYLE = s({
183-
color: COLOR_RED["500"],
184-
fontWeight: "bold",
185-
fontSize: FONT_SIZE.LG,
109+
...frameStyleBase,
110+
...frameStyleError,
186111
});
112+
const ERROR_HEADER_STYLE = s(headerStyleBase);
187113
const ERROR_BODY_STYLE = s({
188-
fontSize: FONT_SIZE.SM,
114+
fontSize: "14px",
115+
lineHeight: "1.4",
189116
});
190117
// #region Generic Message Creation Function
191118
function createMessage(header, messages, styles) {
@@ -210,26 +137,12 @@ var ChatSetAttr = (function (exports) {
210137
});
211138
}
212139

213-
const NOTIFY_WRAPPER_STYLE = s({
214-
border: `1px solid ${COLOR_BLUE["300"]}`,
215-
borderRadius: BORDER_RADIUS.MD,
216-
padding: PADDING.MD,
217-
color: COLOR_BLUE["800"],
218-
backgroundColor: COLOR_BLUE["100"],
219-
});
220-
const NOTIFY_HEADER_STYLE = s({
221-
color: COLOR_BLUE["900"],
222-
fontSize: FONT_SIZE.LG,
223-
fontWeight: "bold",
224-
marginBottom: PADDING.SM,
225-
});
226-
const NOTIFY_BODY_STYLE = s({
227-
fontSize: FONT_SIZE.MD,
228-
});
140+
const NOTIFY_WRAPPER_STYLE = s(frameStyleBase);
141+
const NOTIFY_HEADER_STYLE = s(headerStyleBase);
229142
function createNotifyMessage(title, content) {
230143
return (h("div", { style: NOTIFY_WRAPPER_STYLE },
231144
h("div", { style: NOTIFY_HEADER_STYLE }, title),
232-
h("div", { style: NOTIFY_BODY_STYLE }, content)));
145+
h("div", null, content)));
233146
}
234147

235148
function getPlayerName(playerID) {
@@ -261,7 +174,7 @@ var ChatSetAttr = (function (exports) {
261174
<p>Thank you for installing ChatSetAttr.</p>
262175
<p>To get started, use the command <code>!setattr-config</code> to configure the script to your needs.</p>
263176
<p>For detailed documentation and examples, please use the <code>!setattr-help</code> command or click the button below:</p>
264-
<p><a href="!setattrs-help" style="${BUTTON_STYLE}">Create Journal Handout</a></p>`;
177+
<p><a href="!setattrs-help" style="${s(buttonStyleBase)}">Create Journal Handout</a></p>`;
265178
sendNotification("Welcome to ChatSetAttr!", welcomeMessage, false);
266179
}
267180

@@ -612,46 +525,28 @@ var ChatSetAttr = (function (exports) {
612525
return Math.max(Math.min(currentValue, maxValue), 0);
613526
}
614527

615-
const CONFIG_WRAPPER_STYLE = s({
616-
border: `1px solid ${COLOR_BLUE["300"]}`,
617-
borderRadius: BORDER_RADIUS.MD,
618-
padding: PADDING.MD,
619-
backgroundColor: COLOR_BLUE["50"],
620-
});
621-
const CONFIG_HEADER_STYLE = s({
622-
color: COLOR_BLUE["400"],
623-
fontSize: FONT_SIZE.LG,
624-
fontWeight: "bold",
625-
marginBottom: PADDING.SM,
626-
});
627-
const CONFIG_BODY_STYLE = s({
628-
fontSize: FONT_SIZE.SM,
629-
});
528+
const CONFIG_WRAPPER_STYLE = s(frameStyleBase);
529+
const CONFIG_HEADER_STYLE = s(headerStyleBase);
630530
const CONFIG_TABLE_STYLE = s({
631531
width: "100%",
632532
border: "none",
633533
borderCollapse: "separate",
634534
borderSpacing: "0 4px",
635535
});
636536
const CONFIG_ROW_STYLE = s({
637-
marginBottom: PADDING.XS,
537+
marginBottom: "4px",
638538
});
639-
const CONFIG_BUTTON_SHARED = {
640-
color: COLOR_WHITE,
641-
border: "none",
642-
borderRadius: BORDER_RADIUS.SM,
643-
fontSize: FONT_SIZE.SM,
644-
padding: `${PADDING.XS} ${PADDING.SM}`,
645-
textAlign: "center",
646-
width: "100%",
647-
};
648539
const CONFIG_BUTTON_STYLE_ON = s({
649-
backgroundColor: COLOR_GREEN["500"],
650-
...CONFIG_BUTTON_SHARED,
540+
...buttonStyleBase,
541+
backgroundColor: "#16A34A",
542+
color: "#FFFFFF",
543+
fontWeight: "500",
651544
});
652545
const CONFIG_BUTTON_STYLE_OFF = s({
653-
backgroundColor: COLOR_RED["300"],
654-
...CONFIG_BUTTON_SHARED,
546+
...buttonStyleBase,
547+
backgroundColor: "#DC2626",
548+
color: "#FFFFFF",
549+
fontWeight: "500",
655550
});
656551
const CONFIG_CLEAR_FIX_STYLE = s({
657552
clear: "both",
@@ -665,7 +560,7 @@ var ChatSetAttr = (function (exports) {
665560
const relevantEntries = configEntries.filter(([key]) => key !== "version" && key !== "globalconfigCache" && key !== "flags");
666561
return (h("div", { style: CONFIG_WRAPPER_STYLE },
667562
h("div", { style: CONFIG_HEADER_STYLE }, "ChatSetAttr Configuration"),
668-
h("div", { style: CONFIG_BODY_STYLE },
563+
h("div", null,
669564
h("table", { style: CONFIG_TABLE_STYLE }, relevantEntries.map(([key, value]) => (h("tr", { style: CONFIG_ROW_STYLE },
670565
h("td", null,
671566
h("strong", null,
@@ -1906,6 +1801,7 @@ var ChatSetAttr = (function (exports) {
19061801
if (isSetting) {
19071802
const value = results[target][name] ?? "";
19081803
try {
1804+
console.log("Setting attribute", actualName, "on target", target, "to", value, "with type", type);
19091805
await libSmartAttributes.setAttribute(target, actualName, value, type, setOptions);
19101806
}
19111807
catch (error) {
@@ -1945,15 +1841,28 @@ var ChatSetAttr = (function (exports) {
19451841
const { operation, targeting, options, changes, references, feedback, } = parseMessage(msg.content);
19461842
// Start Timer
19471843
startTimer("chatsetattr", 8000, () => sendDelayMessage(options.silent));
1844+
// Check Config and Permissions
1845+
const config = getConfig();
1846+
const isGM = playerIsGM(msg.playerid);
1847+
if (options.evaluate && !isGM && !config.playersCanEvaluate) {
1848+
return errorOut("You do not have permission to use the evaluate option.", msg.playerid, errors);
1849+
}
1850+
if (targeting.includes("party") && !isGM && !config.playersCanTargetParty) {
1851+
return errorOut("You do not have permission to target the party.", msg.playerid, errors);
1852+
}
1853+
if ((operation === "modattr" || operation === "modbattr") && !isGM && !config.playersCanModify) {
1854+
return errorOut("You do not have permission to modify attributes.", msg.playerid, errors);
1855+
}
19481856
// Preprocess
19491857
const { targets, errors: targetErrors } = generateTargets(msg, targeting);
19501858
errors.push(...targetErrors);
1859+
if (targets.length === 0) {
1860+
return errorOut("No valid targets found.", msg.playerid, errors);
1861+
}
19511862
const request = generateRequest(references, changes);
19521863
const command = handlers[operation];
19531864
if (!command) {
1954-
errors.push(`No handler found for operation: ${operation}`);
1955-
sendErrors(msg.playerid, "Errors", errors);
1956-
return;
1865+
return errorOut(`Invalid operation: ${operation}`, msg.playerid, errors);
19571866
}
19581867
// Execute
19591868
for (const target of targets) {
@@ -1982,6 +1891,11 @@ var ChatSetAttr = (function (exports) {
19821891
const feedbackTitle = feedback?.header ?? delSetTitle;
19831892
sendMessages(msg.playerid, feedbackTitle, messages, feedback?.from);
19841893
}
1894+
function errorOut(errorText, playerid, errors) {
1895+
errors.push("No valid targets found.");
1896+
sendErrors(playerid, "Errors", errors);
1897+
clearTimer("chatsetattr");
1898+
}
19851899
function generateRequest(references, changes) {
19861900
const referenceSet = new Set(references);
19871901
for (const change of changes) {
@@ -2037,6 +1951,14 @@ var ChatSetAttr = (function (exports) {
20371951
});
20381952
}
20391953

1954+
const LI_STYLE = s({
1955+
marginBottom: "4px",
1956+
});
1957+
const WRAPPER_STYLE = s(frameStyleBase);
1958+
const PARAGRAPH_SPACING_STYLE = s({
1959+
marginTop: "8px",
1960+
marginBottom: "8px",
1961+
});
20401962
const v2_0 = {
20411963
appliesTo: "<=1.10",
20421964
version: "2.0",

0 commit comments

Comments
 (0)