Fixes For Canary

This commit is contained in:
thororen1234 2025-04-08 09:09:21 -04:00
parent 760d34ddc4
commit d0a47aa602
No known key found for this signature in database
7 changed files with 45 additions and 214 deletions

View file

@ -6,7 +6,6 @@
import { Upload } from "@api/MessageEvents";
import { Settings } from "@api/Settings";
import { spoiler } from "@equicordplugins/spoilerMessages";
import { tarExtMatcher } from "@plugins/anonymiseFileNames";
import { EquicordDevs } from "@utils/constants";
import definePlugin, { ReporterTestable } from "@utils/types";
@ -36,33 +35,30 @@ export default definePlugin({
// Taken from AnonymiseFileNames
{
find: "instantBatchUpload:",
predicate: () => !Settings.plugins.AnonymiseFileNames.enabled && !Settings.plugins.SpoilerMessages,
replacement: {
match: /uploadFiles:(\i),/,
replace:
"uploadFiles:(...args)=>(args[0].uploads.forEach(f=>f.filename=$self.fixExt(f)),$1(...args)),",
},
predicate: () => !Settings.plugins.AnonymiseFileNames.enabled,
},
// Also taken from AnonymiseFileNames
{
find: 'addFilesTo:"message.attachments"',
predicate: () => !Settings.plugins.AnonymiseFileNames.enabled && !Settings.plugins.SpoilerMessages,
replacement: {
match: /(\i.uploadFiles\((\i),)/,
replace: "$2.forEach(f=>f.filename=$self.fixExt(f)),$1",
},
predicate: () => !Settings.plugins.AnonymiseFileNames.enabled,
}
],
fixExt(upload: ExtUpload) {
const file = upload.filename;
const tarMatch = tarExtMatcher.exec(file);
const extIdx = tarMatch?.index ?? file.lastIndexOf(".");
let fileName = extIdx !== -1 ? file.substring(0, extIdx) : "";
const fileName = extIdx !== -1 ? file.substring(0, extIdx) : "";
const ext = extIdx !== -1 ? file.slice(extIdx) : "";
const newExt = reverseExtensionMap[ext] || ext;
if (Settings.plugins.SpoilerMessages.enabled) {
fileName = spoiler(upload);
}
return fileName + newExt;
},