Skip to content

Commit 649be85

Browse files
committed
Add notification when script takes a long time to finish
1 parent 3255bb9 commit 649be85

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

ChatSetAttr/1.5/ChatSetAttr.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ var chatSetAttr = chatSetAttr || (function () {
613613
sendChatMessage(output);
614614
},
615615
sendDeleteFeedback = function (whisper, feedback) {
616-
const output = whisper + '<div style="border:1px solid black;background-color:' +
616+
let output = whisper + '<div style="border:1px solid black;background-color:' +
617617
'#FFFFFF;padding:3px;"><h3>Deleting attributes</h3><p>';
618618
output += Object.entries(feedback)
619619
.filter(([charid, arr]) => arr.length)

ChatSetAttr/1.6/ChatSetAttr.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ var chatSetAttr = chatSetAttr || (function () {
151151
return msg.content;
152152
}
153153
},
154+
notifyAboutDelay = function (whisper) {
155+
const chatFunction = () => sendChatMessage(whisper + 'Your command is taking a ' +
156+
'long time to execute. Please be patient, the process will finish eventually.');
157+
return setTimeout(chatFunction, 8000);
158+
},
154159
getCIKey = function (obj, name) {
155160
const nameLower = name.toLowerCase();
156161
let result = false;
@@ -198,7 +203,8 @@ var chatSetAttr = chatSetAttr || (function () {
198203
// Setting attributes happens in a delayed recursive way to prevent the sandbox
199204
// from overheating.
200205
delayedGetAndSetAttributes = function (whisper, list, setting, errors, rData, opts) {
201-
const cList = [].concat(list),
206+
const timeNotification = notifyAboutDelay(whisper),
207+
cList = [].concat(list),
202208
feedback = [],
203209
dWork = function (charid) {
204210
const attrs = getCharAttributes(charid, setting, errors, rData, opts);
@@ -207,6 +213,7 @@ var chatSetAttr = chatSetAttr || (function () {
207213
setTimeout(dWork, 50, cList.shift());
208214
}
209215
else {
216+
clearTimeout(timeNotification);
210217
if (!opts.mute) handleErrors(whisper, errors);
211218
if (!opts.silent) sendFeedback(whisper, feedback, opts);
212219
}
@@ -431,7 +438,8 @@ var chatSetAttr = chatSetAttr || (function () {
431438
},
432439
// Deleting attributes
433440
delayedDeleteAttributes = function (whisper, list, setting, errors, rData, opts) {
434-
const cList = [].concat(list),
441+
const timeNotification = notifyAboutDelay(whisper),
442+
cList = [].concat(list),
435443
feedback = {},
436444
dWork = function (charid) {
437445
const attrs = getCharAttributes(charid, setting, errors, rData, opts);
@@ -441,6 +449,7 @@ var chatSetAttr = chatSetAttr || (function () {
441449
setTimeout(dWork, 50, cList.shift());
442450
}
443451
else {
452+
clearTimeout(timeNotification);
444453
if (!opts.silent) sendDeleteFeedback(whisper, feedback, opts);
445454
}
446455
}
@@ -625,7 +634,7 @@ var chatSetAttr = chatSetAttr || (function () {
625634
sendChatMessage(output, opts['fb-from']);
626635
},
627636
sendDeleteFeedback = function (whisper, feedback, opts) {
628-
const output = (opts['fb-public'] ? '' : whisper) +
637+
let output = (opts['fb-public'] ? '' : whisper) +
629638
'<div style="border:1px solid black;background-color:#FFFFFF;padding:3px;">' +
630639
'<h3>' + (('fb-header' in opts) ? opts['fb-header'] : 'Deleting attributes') + '</h3><p>';
631640
output += Object.entries(feedback)

ChatSetAttr/ChatSetAttr.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ var chatSetAttr = chatSetAttr || (function () {
151151
return msg.content;
152152
}
153153
},
154+
notifyAboutDelay = function (whisper) {
155+
const chatFunction = () => sendChatMessage(whisper + 'Your command is taking a ' +
156+
'long time to execute. Please be patient, the process will finish eventually.');
157+
return setTimeout(chatFunction, 8000);
158+
},
154159
getCIKey = function (obj, name) {
155160
const nameLower = name.toLowerCase();
156161
let result = false;
@@ -198,7 +203,8 @@ var chatSetAttr = chatSetAttr || (function () {
198203
// Setting attributes happens in a delayed recursive way to prevent the sandbox
199204
// from overheating.
200205
delayedGetAndSetAttributes = function (whisper, list, setting, errors, rData, opts) {
201-
const cList = [].concat(list),
206+
const timeNotification = notifyAboutDelay(whisper),
207+
cList = [].concat(list),
202208
feedback = [],
203209
dWork = function (charid) {
204210
const attrs = getCharAttributes(charid, setting, errors, rData, opts);
@@ -207,6 +213,7 @@ var chatSetAttr = chatSetAttr || (function () {
207213
setTimeout(dWork, 50, cList.shift());
208214
}
209215
else {
216+
clearTimeout(timeNotification);
210217
if (!opts.mute) handleErrors(whisper, errors);
211218
if (!opts.silent) sendFeedback(whisper, feedback, opts);
212219
}
@@ -431,7 +438,8 @@ var chatSetAttr = chatSetAttr || (function () {
431438
},
432439
// Deleting attributes
433440
delayedDeleteAttributes = function (whisper, list, setting, errors, rData, opts) {
434-
const cList = [].concat(list),
441+
const timeNotification = notifyAboutDelay(whisper),
442+
cList = [].concat(list),
435443
feedback = {},
436444
dWork = function (charid) {
437445
const attrs = getCharAttributes(charid, setting, errors, rData, opts);
@@ -441,6 +449,7 @@ var chatSetAttr = chatSetAttr || (function () {
441449
setTimeout(dWork, 50, cList.shift());
442450
}
443451
else {
452+
clearTimeout(timeNotification);
444453
if (!opts.silent) sendDeleteFeedback(whisper, feedback, opts);
445454
}
446455
}
@@ -625,7 +634,7 @@ var chatSetAttr = chatSetAttr || (function () {
625634
sendChatMessage(output, opts['fb-from']);
626635
},
627636
sendDeleteFeedback = function (whisper, feedback, opts) {
628-
const output = (opts['fb-public'] ? '' : whisper) +
637+
let output = (opts['fb-public'] ? '' : whisper) +
629638
'<div style="border:1px solid black;background-color:#FFFFFF;padding:3px;">' +
630639
'<h3>' + (('fb-header' in opts) ? opts['fb-header'] : 'Deleting attributes') + '</h3><p>';
631640
output += Object.entries(feedback)

0 commit comments

Comments
 (0)