2019-11-12 13:53:58 +00:00
|
|
|
module.exports = Self => {
|
2022-02-22 06:30:26 +00:00
|
|
|
require('../methods/chat/getServiceAuth')(Self);
|
2020-01-20 06:33:24 +00:00
|
|
|
require('../methods/chat/send')(Self);
|
|
|
|
require('../methods/chat/sendCheckingPresence')(Self);
|
2021-02-01 08:29:47 +00:00
|
|
|
require('../methods/chat/notifyIssues')(Self);
|
2022-06-02 12:55:39 +00:00
|
|
|
require('../methods/chat/sendQueued')(Self);
|
2022-11-25 07:36:29 +00:00
|
|
|
|
|
|
|
Self.observe('before save', async function(ctx) {
|
|
|
|
if (!ctx.isNewInstance) return;
|
|
|
|
|
|
|
|
let {message} = ctx.instance;
|
|
|
|
if (!message) return;
|
|
|
|
|
2022-11-25 11:26:58 +00:00
|
|
|
const parts = message.match(/(?<=\[)[a-zA-Z0-9_\-+!@#$%^&*()={};':"\\|,.<>/?\s]*(?=])/g);
|
2022-11-25 11:12:48 +00:00
|
|
|
if (!parts) return;
|
|
|
|
|
2022-11-25 07:36:29 +00:00
|
|
|
const replacedParts = parts.map(part => {
|
2022-11-25 11:26:58 +00:00
|
|
|
return part.replace(/[!$%^&*()={};':"\\,.<>/?]/g, '');
|
2022-11-25 07:36:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
for (const [index, part] of parts.entries())
|
|
|
|
message = message.replace(part, replacedParts[index]);
|
|
|
|
|
|
|
|
ctx.instance.message = message;
|
|
|
|
});
|
2019-11-12 13:53:58 +00:00
|
|
|
};
|