-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-add the file scanner for ROM files
- Loading branch information
1 parent
e1f707b
commit d400619
Showing
2 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const {generalErrorHandler} = require('../errorHandlers'); | ||
|
||
const romExtensions = ['sfc', 'smc', 'rom', 'nes', 'z64', 'n64', 'gb', 'gbc', 'gba']; | ||
|
||
const isRomFile = (filename) => { | ||
const parts = filename.split('.'); | ||
for (const part of parts) { | ||
// Rom extension is present in filename | ||
if (romExtensions.indexOf(part) !== -1) { return true; } | ||
} | ||
// Doesn't look like a ROM file | ||
return false; | ||
}; | ||
|
||
module.exports = (client, message) => { | ||
try{ | ||
return message.attachments.each((attachment) => { | ||
// Disallow direct posting of ROM files | ||
if (isRomFile(attachment.name)) { | ||
message.channel.send(`${message.author}: Do not post links to ROMs or other copyrighted content.`); | ||
return message.delete(); | ||
} | ||
}); | ||
} catch (error) { | ||
message.channel.send('Something went wrong while trying to analyze your file. It has been deleted ' + | ||
'for safety purposes.'); | ||
message.delete(); | ||
generalErrorHandler(error); | ||
} | ||
}; |