Require images to be jpg or png in image type

This commit is contained in:
Daniel Odendahl Jr
2018-11-10 15:45:32 +00:00
parent d909e38ed2
commit 73b9c56981
2 changed files with 3 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "98.1.0",
"version": "98.1.1",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+2
View File
@@ -1,4 +1,5 @@
const { ArgumentType } = require('discord.js-commando');
const fileTypeRe = /\.(jpe?g|png)$/i;
module.exports = class ImageArgumentType extends ArgumentType {
constructor(client) {
@@ -10,6 +11,7 @@ module.exports = class ImageArgumentType extends ArgumentType {
if (attachment) {
if (!attachment.height || !attachment.width) return false;
if (attachment.size > 8e+6) return 'Please provide an image under 8 MB.';
if (!fileTypeRe.test(attachment.name)) return 'Please only send PNG or JPG format images.';
return true;
}
return this.client.registry.types.get('user').validate(value, msg, arg);