Skip to content

Commit 720be50

Browse files
committed
Made ChatSetAttr 1.8 inline parsing more explicit
1 parent 70bed10 commit 720be50

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

ChatSetAttr/1.8/ChatSetAttr.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ChatSetAttr version 1.8
2-
// Last Updated: 2018-07-13
2+
// Last Updated: 2018-07-15
33
// A script to create, modify, or delete character attributes from the chat area or macros.
44
// If you don't like my choices for --replace, you can edit the replacers variable at your own peril to change them.
55

@@ -696,12 +696,12 @@ var chatSetAttr = chatSetAttr || (function () {
696696
}
697697
},
698698
handleInlineCommand = (msg) => {
699-
const matches = msg.content.match(/!(?:set|mod|modb)attr\b[^{]*?(?:\s*--(?:[^{-]+?-?)*?{{[^}[\]]+\$\[\[(?:\d+)\]\][^}]*?}})+/g);
699+
const command = msg.content.match(/!(set|mod|modb)attr .*?!!!/);
700700

701-
(matches || []).forEach(str => {
702-
const mode = str.match(/^!(set|mod|modb)attr/),
703-
newMsgContent = str.replace(/(--(?:[^{-]+?-?)*?){{[^}[\]]+\$\[\[(\d+)\]\][^}]*?}}/g, (_, pre, number) => {
704-
return `${pre}$[[${number}]]`;
701+
if (command) {
702+
const mode = command[1],
703+
newMsgContent = command[0].slice(0, -3).replace(/{{[^}[\]]+\$\[\[(\d+)\]\].*?}}/g, (_, number) => {
704+
return `$[[${number}]]`;
705705
});
706706
const newMsg = {
707707
content: newMsgContent,
@@ -711,9 +711,9 @@ var chatSetAttr = chatSetAttr || (function () {
711711
processInlinerolls(newMsg),
712712
msg.playerid,
713713
msg.selected,
714-
mode[1]
714+
mode
715715
);
716-
});
716+
}
717717
},
718718
// Main function, called after chat message input
719719
handleInput = function (msg) {

ChatSetAttr/ChatSetAttr.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ChatSetAttr version 1.8
2-
// Last Updated: 2018-07-13
2+
// Last Updated: 2018-07-15
33
// A script to create, modify, or delete character attributes from the chat area or macros.
44
// If you don't like my choices for --replace, you can edit the replacers variable at your own peril to change them.
55

@@ -696,12 +696,12 @@ var chatSetAttr = chatSetAttr || (function () {
696696
}
697697
},
698698
handleInlineCommand = (msg) => {
699-
const matches = msg.content.match(/!(?:set|mod|modb)attr\b[^{]*?(?:\s*--(?:[^{-]+?-?)*?{{[^}[\]]+\$\[\[(?:\d+)\]\][^}]*?}})+/g);
699+
const command = msg.content.match(/!(set|mod|modb)attr .*?!!!/);
700700

701-
(matches || []).forEach(str => {
702-
const mode = str.match(/^!(set|mod|modb)attr/),
703-
newMsgContent = str.replace(/(--(?:[^{-]+?-?)*?){{[^}[\]]+\$\[\[(\d+)\]\][^}]*?}}/g, (_, pre, number) => {
704-
return `${pre}$[[${number}]]`;
701+
if (command) {
702+
const mode = command[1],
703+
newMsgContent = command[0].slice(0, -3).replace(/{{[^}[\]]+\$\[\[(\d+)\]\].*?}}/g, (_, number) => {
704+
return `$[[${number}]]`;
705705
});
706706
const newMsg = {
707707
content: newMsgContent,
@@ -711,9 +711,9 @@ var chatSetAttr = chatSetAttr || (function () {
711711
processInlinerolls(newMsg),
712712
msg.playerid,
713713
msg.selected,
714-
mode[1]
714+
mode
715715
);
716-
});
716+
}
717717
},
718718
// Main function, called after chat message input
719719
handleInput = function (msg) {

ChatSetAttr/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ One of the following options must be specified; they determine which characters
1414

1515
## Inline commands
1616

17-
It is possible to use some ChatSetAttr commands in the middle of a roll template, with some limitations. To do so, write the ChatSetAttr command between the properties of a roll template. If one of the attribute values is a whole roll template property, the first inline roll within that property will be used instead. It is easiest to illustrate how this works in an example:
17+
It is possible to use some ChatSetAttr commands in the middle of a roll template, with some limitations. To do so, write the ChatSetAttr command between the properties of a roll template, and end it "!!!". If one of the attribute values is a whole roll template property, the first inline roll within that property will be used instead. It is easiest to illustrate how this works in an example:
1818

1919
```null
20-
&{template:default} {{name=Cthulhu}} !modattr --silent --charid @{target|character_id} --sanity|-{{Sanity damage=[[2d10+2]]}} --corruption|{{Corruption=Corruption increases by [[1]]}} {{description=Text}}
20+
&{template:default} {{name=Cthulhu}} !modattr --silent --charid @{target|character_id} --sanity|-{{Sanity damage=[[2d10+2]]}} --corruption|{{Corruption=Corruption increases by [[1]]}}!!! {{description=Text}}
2121
```
2222

23-
This will decrease sanity by 2d10+2 and increase corruption by 1 for the character selected with the --charid @{target|character\_id} command. In order for the parsing to work correctly, all attributes specified by roll templates must come at at the end of the command (but they are not required to be at the end of the chat message).
23+
This will decrease sanity by 2d10+2 and increase corruption by 1 for the character selected with the --charid @{target|character\_id} command. **It is crucial** that the ChatSetAttr part of the command is ended by three exclamation marks like in the message above – this is how the script know when to stop interpreting the roll template as part of the ChatSetAttr command.
2424

2525
## Additional options
2626

0 commit comments

Comments
 (0)