Allow file to be uploaded. Closes #3
This commit is contained in:
parent
0d5ec60cf1
commit
0d7985df55
2 changed files with 24 additions and 4 deletions
|
@ -3,5 +3,6 @@
|
||||||
"token": "MTU1fdsYNTRb2RT.FcD2l1ig.jIuKqwertyd432RROhF5A",
|
"token": "MTU1fdsYNTRb2RT.FcD2l1ig.jIuKqwertyd432RROhF5A",
|
||||||
"prefix": "$>",
|
"prefix": "$>",
|
||||||
"codePrefix": "$>",
|
"codePrefix": "$>",
|
||||||
|
"maxFileSize": 10240,
|
||||||
"myriad": "8081"
|
"myriad": "8081"
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ class MessageInvalidListener extends Listener {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parse = this.parseMessage(message);
|
const parse = await this.parseMessage(message);
|
||||||
if (!parse) {
|
if (!parse) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -62,14 +62,22 @@ class MessageInvalidListener extends Listener {
|
||||||
return message.util.send(output);
|
return message.util.send(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
parseMessage(message) {
|
async parseMessage(message) {
|
||||||
const prefix = this.client.config.codePrefix;
|
const prefix = this.client.config.codePrefix;
|
||||||
const starts = message.content.slice(0, prefix.length).toLowerCase().startsWith(prefix.toLowerCase());
|
const starts = message.content.slice(0, prefix.length).toLowerCase().startsWith(prefix.toLowerCase());
|
||||||
if (!starts) {
|
if (!starts) {
|
||||||
return null;
|
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);
|
const match = message.content.slice(prefix.length).match(regex);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -80,7 +88,18 @@ class MessageInvalidListener extends Listener {
|
||||||
return null;
|
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 };
|
return { language, code };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue