Regarding Stripping the whisper, this version will have nothing in that preceding area, which is probably as close as you can get to stripping it:
on("chat:message", function(msg) {
var cmdName = "!bw";
var msgWhisper = msg.content.slice(cmdName.length);
if(msg.type == "api" && msg.content.indexOf(cmdName) !== -1) {
if(_.has(msg,'inlinerolls')){
msgWhisper = _.chain(msg.inlinerolls)
.reduce(function(m,v,k){
m['$[['+k+']]']=v.results.total || 0;
return m;
},{})
.reduce(function(m,v,k){
return m.replace(k,v);
},msgWhisper)
.value();
}
sendChat('', "/w gm "+msgWhisper);
};
});
As for message order, that's an unfortunate side effect of mixing chat and API chat. Since all messages are processed asynchronously, ordering is not guaranteed. Usually, you won't see this as your chat messages will get processed synchronously (but might be interleaved with other peoples chat messages depending on when they sent them, latency between connections, etc.). However, when you have an API message, it must go through additional processing beyond the chat system, and thus takes longer. Effectively an API command is a chat message that then triggers a chat message:
CHAT MESSAGE 1
CHAT MESSAGE 2
API COMMAND 1
CHAT MESSAGE 3
CHAT MESSAGE 4
[API ISSUED CHAT MESSAGE 1]
It's not avoidable, though you could conceivably replace all your regular chat messages with API chat messages and get the ordering right. Here's a version of the above that just sends a message to chat using
!say :
on("chat:message", function(msg) {
var cmdName = "!say";
var msgSay = msg.content.slice(cmdName.length);
if(msg.type == "api" && msg.content.indexOf(cmdName) !== -1) {
if(_.has(msg,'inlinerolls')){
msgSay = _.chain(msg.inlinerolls)
.reduce(function(m,v,k){
m['$[['+k+']]']=v.results.total || 0;
return m;
},{})
.reduce(function(m,v,k){
return m.replace(k,v);
},msgSay)
.value();
}
sendChat(msg.who, msgSay);
};
});
You could try it with this:
/em @{character_name}'s (@{weapon1name})
!bw @{spacer} Target: AC:[[@{target|armorclass}]] TCH: [[@{target|touchac}]] FF: [[@{target|flatac}]]
!say @{weapon1critmin}-20 @{weapon1critmult}x @{weapon1range}ft @{weapon1ammunition} shots left
!say Opt:
!say @{weapon1fullattackmacro}
!say -------------------------------------------
!say @{weapon1damage}
You could even replace that /em with this !emas script I wrote a while back to try this:
https://gist.github.com/shdwjk/42f34ecfd167ec56c9f7