Adapt max image file size to server boost tier, fixes #165
This commit is contained in:
parent
c8d8973d7b
commit
ab3ae7b9c6
1 changed files with 32 additions and 17 deletions
|
@ -113,7 +113,21 @@ export default async (client, cluster, worker, ipc, message) => {
|
|||
} else if (typeof result === "object" && result.embed) {
|
||||
await client.createMessage(message.channel.id, Object.assign(result, reference));
|
||||
} else if (typeof result === "object" && result.file) {
|
||||
if (result.file.length > 8388119 && process.env.TEMPDIR !== "") {
|
||||
let fileSize = 8388119;
|
||||
if (message.channel.guild) {
|
||||
switch (message.channel.guild.premiumTier) {
|
||||
case 2:
|
||||
fileSize = 52428308;
|
||||
break;
|
||||
case 3:
|
||||
fileSize = 104856616;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (result.file.length > fileSize) {
|
||||
if (process.env.TEMPDIR !== "") {
|
||||
const filename = `${Math.random().toString(36).substring(2, 15)}.${result.name.split(".")[1]}`;
|
||||
await promises.writeFile(`${process.env.TEMPDIR}/${filename}`, result.file);
|
||||
const imageURL = `${process.env.TMP_DOMAIN == "" ? "https://tmp.projectlounge.pw" : process.env.TMP_DOMAIN}/${filename}`;
|
||||
|
@ -130,6 +144,7 @@ export default async (client, cluster, worker, ipc, message) => {
|
|||
},
|
||||
}
|
||||
}, reference));
|
||||
}
|
||||
} else {
|
||||
await client.createMessage(message.channel.id, Object.assign({
|
||||
content: result.text ? result.text : undefined
|
||||
|
|
Loading…
Reference in a new issue