Skip to content

Instantly share code, notes, and snippets.

@shinmai
Created May 21, 2024 08:35
Show Gist options
  • Save shinmai/a8ad7842ef30f7c82b01f37ff233b86f to your computer and use it in GitHub Desktop.
Save shinmai/a8ad7842ef30f7c82b01f37ff233b86f to your computer and use it in GitHub Desktop.
BetterDiscord addon/plug-in to sanitise filenames when uploading
/**
* @name Sanitise Filenames
* @description Hide filenames!
* @version 0.0.1
* @author shi
* @authorId 142594671078539264
* @website https://shinmai.wtf/
* @source https://gist.github.com/shinmai/a8ad7842ef30f7c82b01f37ff233b86f/raw/SanitiseFilenames.plugin.js
*/
/**
* Changelog:
* 0.0.1 - initial version
*/
module.exports = meta => ({
start() {
const sanitise = (_,args)=> {
const files = args[0].uploads,
msg = args[0].parsedMessage
if(msg.content.startsWith("%")) {
msg.content = msg.content.substring(1)
for(file in files) files[file].filename=files[file].classification+"."+files[file].mimeType.split('/')[1]
}
}
BdApi.Patcher.before('sanitiseFilenames', BdApi.Webpack.getModule(BdApi.Webpack.Filters.byProps('uploadFiles')), 'uploadFiles', sanitise)
},
stop() { BdApi.Patcher.unpatchAll('sanitiseFilenames') }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment