Make the sendMessage patch actually work
This commit is contained in:
parent
bc4aab4d4a
commit
d4f803ce2e
13
index.js
13
index.js
@ -17,7 +17,7 @@ const { Plugin } = require("powercord/entities");
|
|||||||
const { inject, uninject } = require("powercord/injector");
|
const { inject, uninject } = require("powercord/injector");
|
||||||
const { messages, getModule } = require("powercord/webpack");
|
const { messages, getModule } = require("powercord/webpack");
|
||||||
|
|
||||||
const indents = [, " ", "\t"];
|
// const indents = [, " ", "\t"];
|
||||||
|
|
||||||
const sendMessageInjectionId = "unindentSendMessage";
|
const sendMessageInjectionId = "unindentSendMessage";
|
||||||
const codeblockInjectionId = "unindentCodeblocks";
|
const codeblockInjectionId = "unindentCodeblocks";
|
||||||
@ -30,7 +30,12 @@ module.exports = class Unindent extends Plugin {
|
|||||||
"sendMessage",
|
"sendMessage",
|
||||||
args => {
|
args => {
|
||||||
const msg = args[1];
|
const msg = args[1];
|
||||||
msg.content = msg.content.replace(/```(.|\n)*?```/g, m => this.unindent(m, 1));
|
msg.content = msg.content.replace(/```(.|\n)*?```/g, m => {
|
||||||
|
const lines = m.split("\n");
|
||||||
|
let suffix = "";
|
||||||
|
if (lines[lines.length - 1] === "```") suffix = lines.pop();
|
||||||
|
return `${lines[0]}\n${this.unindent(lines.slice(1).join("\n"))}\n${suffix}`;
|
||||||
|
});
|
||||||
return args;
|
return args;
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
@ -43,14 +48,14 @@ module.exports = class Unindent extends Plugin {
|
|||||||
parser.defaultRules.codeBlock,
|
parser.defaultRules.codeBlock,
|
||||||
"react",
|
"react",
|
||||||
args => {
|
args => {
|
||||||
args[0].content = this.unindent(args[0].content, 0);
|
args[0].content = this.unindent(args[0].content);
|
||||||
return args;
|
return args;
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
unindent(str, firstLineIdx) {
|
unindent(str) {
|
||||||
const minIndent = str.match(/^ *(?=\S)/gm)?.reduce((prev, curr) => Math.min(prev, curr.length), Infinity) ?? 0;
|
const minIndent = str.match(/^ *(?=\S)/gm)?.reduce((prev, curr) => Math.min(prev, curr.length), Infinity) ?? 0;
|
||||||
return str.replace(new RegExp(`^ {${minIndent}}`, "gm"), "");
|
return str.replace(new RegExp(`^ {${minIndent}}`, "gm"), "");
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user