Merge pull request #2482 from ekwoka/split-large-limit
✨ Allows limiting the total messages sent
This commit is contained in:
commit
eac4748ffd
|
@ -67,6 +67,7 @@ module.exports = (_ => {
|
||||||
},
|
},
|
||||||
amounts: {
|
amounts: {
|
||||||
splitCounter: {value: 0, description: "Messages will be split after roughly X Characters"},
|
splitCounter: {value: 0, description: "Messages will be split after roughly X Characters"},
|
||||||
|
maxPages: { value: 0, description: 'Maximum number of split pages', note: "(0 for unlimited) Pages beyond this count will be discarded" }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -131,6 +132,22 @@ module.exports = (_ => {
|
||||||
value: this.settings.amounts.splitCounter < 1000 || this.settings.amounts.splitCounter > maxMessageLength ? maxMessageLength : this.settings.amounts.splitCounter
|
value: this.settings.amounts.splitCounter < 1000 || this.settings.amounts.splitCounter > maxMessageLength ? maxMessageLength : this.settings.amounts.splitCounter
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
settingsItems.push(
|
||||||
|
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||||
|
type: 'TextInput',
|
||||||
|
childProps: {
|
||||||
|
type: 'number'
|
||||||
|
},
|
||||||
|
plugin: this,
|
||||||
|
keys: ['amounts', 'maxPages'],
|
||||||
|
label: this.defaults.amounts.maxPages.description,
|
||||||
|
note: this.defaults.amounts.maxPages.note,
|
||||||
|
min: 0,
|
||||||
|
max: 20,
|
||||||
|
value: this.settings.amounts.splitCounter
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
return settingsItems;
|
return settingsItems;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -189,6 +206,7 @@ module.exports = (_ => {
|
||||||
formatText (text) {
|
formatText (text) {
|
||||||
const separator = !this.settings.general.byNewlines ? "\n" : " ";
|
const separator = !this.settings.general.byNewlines ? "\n" : " ";
|
||||||
const splitMessageLength = this.settings.amounts.splitCounter < 1000 || this.settings.amounts.splitCounter > maxMessageLength ? maxMessageLength : this.settings.amounts.splitCounter;
|
const splitMessageLength = this.settings.amounts.splitCounter < 1000 || this.settings.amounts.splitCounter > maxMessageLength ? maxMessageLength : this.settings.amounts.splitCounter;
|
||||||
|
const maxPages = this.settings.amounts.maxPages || Infinity;
|
||||||
|
|
||||||
text = text.replace(/\t/g, " ");
|
text = text.replace(/\t/g, " ");
|
||||||
let longWords = text.match(new RegExp(`[^${separator.replace("\n", "\\n")}]{${splitMessageLength * (19/20)},}`, "gm"));
|
let longWords = text.match(new RegExp(`[^${separator.replace("\n", "\\n")}]{${splitMessageLength * (19/20)},}`, "gm"));
|
||||||
|
@ -231,7 +249,7 @@ module.exports = (_ => {
|
||||||
messages[j] = messages[j] + insertCodeLine;
|
messages[j] = messages[j] + insertCodeLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return messages;
|
return messages.slice(0, maxPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
setLabelsByLanguage () {
|
setLabelsByLanguage () {
|
||||||
|
|
Loading…
Reference in New Issue