Update SendLargeMessages.plugin.js
This commit is contained in:
parent
24357425af
commit
8e20b11660
|
@ -2,7 +2,7 @@
|
||||||
* @name SendLargeMessages
|
* @name SendLargeMessages
|
||||||
* @author DevilBro
|
* @author DevilBro
|
||||||
* @authorId 278543574059057154
|
* @authorId 278543574059057154
|
||||||
* @version 1.6.6
|
* @version 1.6.7
|
||||||
* @description Allows you to enter larger Messages, which will automatically split into several smaller Messages
|
* @description Allows you to enter larger Messages, which will automatically split into several smaller Messages
|
||||||
* @invite Jx3TjNS
|
* @invite Jx3TjNS
|
||||||
* @donate https://www.paypal.me/MircoWittrien
|
* @donate https://www.paypal.me/MircoWittrien
|
||||||
|
@ -17,12 +17,12 @@ module.exports = (_ => {
|
||||||
"info": {
|
"info": {
|
||||||
"name": "SendLargeMessages",
|
"name": "SendLargeMessages",
|
||||||
"author": "DevilBro",
|
"author": "DevilBro",
|
||||||
"version": "1.6.6",
|
"version": "1.6.7",
|
||||||
"description": "Allows you to enter larger Messages, which will automatically split into several smaller Messages"
|
"description": "Allows you to enter larger Messages, which will automatically split into several smaller Messages"
|
||||||
},
|
},
|
||||||
"changeLog": {
|
"changeLog": {
|
||||||
"improved": {
|
"improved": {
|
||||||
"New Line instead of Spaces": "Added an option to check for newlines instead of spaces to split messages"
|
"Nitro Max Message Length": "Now uses 4000 as Max Limit when the user has the permissions to"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -66,14 +66,13 @@ module.exports = (_ => {
|
||||||
}
|
}
|
||||||
} : (([Plugin, BDFDB]) => {
|
} : (([Plugin, BDFDB]) => {
|
||||||
const messageDelay = 1000; //changing at own risk, might result in bans or mutes
|
const messageDelay = 1000; //changing at own risk, might result in bans or mutes
|
||||||
|
let maxMessageLength = 2000;
|
||||||
let settings = {};
|
|
||||||
|
|
||||||
return class SendLargeMessages extends Plugin {
|
return class SendLargeMessages extends Plugin {
|
||||||
onLoad () {
|
onLoad () {
|
||||||
this.defaults = {
|
this.defaults = {
|
||||||
settings: {
|
general: {
|
||||||
byNewlines: {value: false, description: "Try to split messages on newlines instead of spaces", note: "This will stop sentences from being cut, but might result in more messages being sent"},
|
byNewlines: {value: false, description: "Try to split Messages on Newlines instead of Spaces", note: "This will stop Sentences from being cut, but might result in more Messages being sent"},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -89,44 +88,46 @@ module.exports = (_ => {
|
||||||
}
|
}
|
||||||
|
|
||||||
onStart () {
|
onStart () {
|
||||||
this.forceUpdateAll();
|
maxMessageLength = BDFDB.LibraryModules.NitroUtils.canUseIncreasedMessageLength() && BDFDB.DiscordUtils.getExperiment("premiumContentLengthAvailable") ? BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH_PREMIUM : BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH;
|
||||||
|
|
||||||
|
BDFDB.PatchUtils.forceAllUpdates(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
onStop () {
|
onStop () {
|
||||||
this.forceUpdateAll();
|
BDFDB.PatchUtils.forceAllUpdates(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
getSettingsPanel (collapseStates = {}) {
|
getSettingsPanel (collapseStates = {}) {
|
||||||
let settingsPanel, settingsItems = [];
|
let settingsPanel;
|
||||||
|
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, {
|
||||||
|
collapseStates: collapseStates,
|
||||||
|
children: _ => {
|
||||||
|
let settingsItems = [];
|
||||||
|
|
||||||
for (let key in settings) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
for (let key in this.defaults.general) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||||
type: "Switch",
|
type: "Switch",
|
||||||
plugin: this,
|
plugin: this,
|
||||||
keys: ["settings", key],
|
keys: ["general", key],
|
||||||
label: this.defaults.settings[key].description,
|
label: this.defaults.general[key].description,
|
||||||
note: this.defaults.settings[key].note,
|
note: this.defaults.general[key].note,
|
||||||
value: settings[key]
|
value: this.settings.general[key]
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems);
|
return settingsItems;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSettingsClosed (e) {
|
onSettingsClosed (e) {
|
||||||
if (this.SettingsUpdated) {
|
if (this.SettingsUpdated) {
|
||||||
delete this.SettingsUpdated;
|
delete this.SettingsUpdated;
|
||||||
this.forceUpdateAll();
|
BDFDB.PatchUtils.forceAllUpdates(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forceUpdateAll () {
|
|
||||||
settings = BDFDB.DataUtils.get(this, "settings");
|
|
||||||
|
|
||||||
BDFDB.PatchUtils.forceAllUpdates(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
processChannelTextAreaForm (e) {
|
processChannelTextAreaForm (e) {
|
||||||
if (!BDFDB.PatchUtils.isPatched(this, e.instance, "handleSendMessage")) BDFDB.PatchUtils.patch(this, e.instance, "handleSendMessage", {instead: e2 => {
|
if (!BDFDB.PatchUtils.isPatched(this, e.instance, "handleSendMessage")) BDFDB.PatchUtils.patch(this, e.instance, "handleSendMessage", {instead: e2 => {
|
||||||
if (e2.methodArguments[0].length > BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH) {
|
if (e2.methodArguments[0].length > maxMessageLength) {
|
||||||
e2.stopOriginalMethodCall();
|
e2.stopOriginalMethodCall();
|
||||||
let messages = this.formatText(e2.methodArguments[0]);
|
let messages = this.formatText(e2.methodArguments[0]);
|
||||||
messages.filter(n => n).forEach((message, i) => {
|
messages.filter(n => n).forEach((message, i) => {
|
||||||
|
@ -149,12 +150,12 @@ module.exports = (_ => {
|
||||||
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: "SlateCharacterCount"});
|
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: "SlateCharacterCount"});
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
let text = BDFDB.LibraryModules.SlateSelectionUtils.serialize(children[index].props.document, "raw");
|
let text = BDFDB.LibraryModules.SlateSelectionUtils.serialize(children[index].props.document, "raw");
|
||||||
if (text.length > BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH) children[index] = BDFDB.ReactUtils.createElement("div", {
|
if (text.length > maxMessageLength) children[index] = BDFDB.ReactUtils.createElement("div", {
|
||||||
className: BDFDB.disCNS.textareacharcounter + BDFDB.disCN.textareacharcountererror,
|
className: BDFDB.disCNS.textareacharcounter + BDFDB.disCN.textareacharcountererror,
|
||||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||||
text: Math.ceil(text.length / BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH * (39/40)) + " " + BDFDB.LanguageUtils.LanguageStrings.MESSAGES,
|
text: Math.ceil(text.length / maxMessageLength * (39/40)) + " " + BDFDB.LanguageUtils.LanguageStrings.MESSAGES,
|
||||||
children: BDFDB.ReactUtils.createElement("span", {
|
children: BDFDB.ReactUtils.createElement("span", {
|
||||||
children: BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH - text.length
|
children: maxMessageLength - text.length
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -163,19 +164,19 @@ module.exports = (_ => {
|
||||||
}
|
}
|
||||||
|
|
||||||
processChannelEditorContainer (e) {
|
processChannelEditorContainer (e) {
|
||||||
if (e.instance.props.type && e.instance.props.type == BDFDB.DiscordConstants.TextareaTypes.NORMAL) e.instance.props.shouldUploadLongMessages = false;
|
if (e.instance.props.type == BDFDB.DiscordConstants.TextareaTypes.NORMAL) e.instance.props.shouldUploadLongMessages = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
formatText (text) {
|
formatText (text) {
|
||||||
const separator = settings.byNewlines ? "\n" : " ";
|
const separator = !this.settings.general.byNewlines ? "\n" : " ";
|
||||||
|
|
||||||
text = text.replace(/\t/g, " ");
|
text = text.replace(/\t/g, " ");
|
||||||
let longWords = text.match(new RegExp(`[^${separator.replace("\n", "\\n")}]{${BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH * (19/20)},}`, "gm"));
|
let longWords = text.match(new RegExp(`[^${separator.replace("\n", "\\n")}]{${maxMessageLength * (19/20)},}`, "gm"));
|
||||||
if (longWords) for (let longWord of longWords) {
|
if (longWords) for (let longWord of longWords) {
|
||||||
let count1 = 0;
|
let count1 = 0;
|
||||||
let shortWords = [];
|
let shortWords = [];
|
||||||
longWord.split("").forEach(c => {
|
longWord.split("").forEach(c => {
|
||||||
if (shortWords[count1] && (shortWords[count1].length >= BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH * (19/20) || (c == "\n" && shortWords[count1].length >= BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH * (19/20) - 100))) count1++;
|
if (shortWords[count1] && (shortWords[count1].length >= maxMessageLength * (19/20) || (c == "\n" && shortWords[count1].length >= maxMessageLength * (19/20) - 100))) count1++;
|
||||||
shortWords[count1] = shortWords[count1] ? shortWords[count1] + c : c;
|
shortWords[count1] = shortWords[count1] ? shortWords[count1] + c : c;
|
||||||
});
|
});
|
||||||
text = text.replace(longWord, shortWords.join(separator));
|
text = text.replace(longWord, shortWords.join(separator));
|
||||||
|
@ -183,7 +184,7 @@ module.exports = (_ => {
|
||||||
let messages = [];
|
let messages = [];
|
||||||
let count2 = 0;
|
let count2 = 0;
|
||||||
text.split(separator).forEach((word) => {
|
text.split(separator).forEach((word) => {
|
||||||
if (messages[count2] && (messages[count2] + "" + word).length > BDFDB.DiscordConstants.MAX_MESSAGE_LENGTH * (39/40)) count2++;
|
if (messages[count2] && (messages[count2] + "" + word).length > maxMessageLength * (39/40)) count2++;
|
||||||
messages[count2] = messages[count2] ? messages[count2] + separator + word : word;
|
messages[count2] = messages[count2] ? messages[count2] + separator + word : word;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue