Allow file to be uploaded. Closes #3

This commit is contained in:
Manuel 2021-05-12 11:26:24 +02:00
parent 0d5ec60cf1
commit 0d7985df55
Signed by: Manuel
GPG key ID: 4085037435E1F07A
2 changed files with 24 additions and 4 deletions

View file

@ -3,5 +3,6 @@
"token": "MTU1fdsYNTRb2RT.FcD2l1ig.jIuKqwertyd432RROhF5A",
"prefix": "$>",
"codePrefix": "$>",
"maxFileSize": 10240,
"myriad": "8081"
}

View file

@ -16,7 +16,7 @@ class MessageInvalidListener extends Listener {
return null;
}
const parse = this.parseMessage(message);
const parse = await this.parseMessage(message);
if (!parse) {
return null;
}
@ -62,14 +62,22 @@ class MessageInvalidListener extends Listener {
return message.util.send(output);
}
parseMessage(message) {
async parseMessage(message) {
const prefix = this.client.config.codePrefix;
const starts = message.content.slice(0, prefix.length).toLowerCase().startsWith(prefix.toLowerCase());
if (!starts) {
return null;
}
const regex = /^\s*(`{1,3})(.+?)[ \n]([^]+)\1\s*$/;
let file = null;
let regex = "";
if (file = message.attachments.first()) {
regex = /^\s*(`{1})(.+)(`{1})\s*$/;
} else {
regex = /^\s*(`{1,3})(.+?)[ \n]([^]+)\1\s*$/;
}
const match = message.content.slice(prefix.length).match(regex);
if (!match) {
return null;
@ -80,7 +88,18 @@ class MessageInvalidListener extends Listener {
return null;
}
const code = match[3].trim();
let code = "";
if (file) {
if (file.size > this.client.config.maxFileSize) {
return null;
}
code = await fetch(file.url)
.then(res => res.text());
} else {
code = match[3].trim();
}
return { language, code };
}
}