Skip to content

Commit e64a5e5

Browse files
committed
Update paginator to delete message when pressing the trash button, check avatar file sizes before uploading now
1 parent 9e8bf6f commit e64a5e5

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

src/commands/prefixed/info/avatar.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Command, CommandClient, Structures } from 'detritus-client';
2-
import { Permissions } from 'detritus-client/lib/constants';
2+
import { Permissions, MAX_ATTACHMENT_SIZE } from 'detritus-client/lib/constants';
33

44
import { CommandTypes, PresenceStatusColors } from '../../../constants';
55
import { DefaultParameters, Parameters, createUserEmbed, editOrReply } from '../../../utils';
@@ -66,6 +66,10 @@ export default class AvatarCommand extends BaseCommand {
6666
filename: avatarUrl.split('/').pop()!,
6767
value: await context.rest.get(user.avatarUrlFormat(null, {size: 512})),
6868
};
69+
const maxAttachmentSize = (context.guild) ? context.guild.maxAttachmentSize : MAX_ATTACHMENT_SIZE;
70+
if (maxAttachmentSize <= file.value.length) {
71+
file = undefined;
72+
}
6973
} catch(error) {
7074

7175
}

src/stores/guildlogging.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ClientEvents,
77
MessageFlags,
88
UserFlags as DiscordUserFlags,
9+
MAX_ATTACHMENT_SIZE,
910
} from 'detritus-client/lib/constants';
1011
import { Embed, Markup, Snowflake, intToHex, intToRGB } from 'detritus-client/lib/utils';
1112
import { Endpoints as DiscordEndpoints, RequestTypes } from 'detritus-client-rest';
@@ -341,7 +342,7 @@ class GuildLoggingStore extends Store<string, GuildLogStorage> {
341342
const promises: Array<Promise<any>> = [];
342343
for (let [loggerType, queue] of queues) {
343344
// add embed length checks since the max character amount of 6000 is spread through all 10 embeds
344-
const unfilteredPayloads = queue.splice(0, 10).map((event) => createLogPayload(event));
345+
const unfilteredPayloads = queue.splice(0, 10).map((event) => createLogPayload(event, shard));
345346
const payloads: Array<RequestTypes.ExecuteWebhook> = [];
346347
while (unfilteredPayloads.length) {
347348
const embeds: Array<Embed> = [];
@@ -782,6 +783,7 @@ export default new GuildLoggingStore();
782783

783784
export function createLogPayload(
784785
event: GuildLoggingEventItem,
786+
shard: ShardClient,
785787
): {
786788
embed: Embed,
787789
files: Array<{filename: string, value: any}>,
@@ -1801,13 +1803,19 @@ export function createLogPayload(
18011803
embed.setColor(EmbedColors.LOG_UPDATE);
18021804

18031805
if (avatars) {
1804-
if (avatars.current) {
1805-
embed.setAuthor(undefined, `attachment://${avatars.current.filename}`);
1806-
files.push(avatars.current);
1807-
}
1808-
if (avatars.old) {
1809-
embed.setThumbnail(`attachment://${avatars.old.filename}`);
1810-
files.push(avatars.old);
1806+
const guild = shard.guilds.get(guildId);
1807+
const maxFileSize = (guild) ? guild.maxAttachmentSize : MAX_ATTACHMENT_SIZE;
1808+
1809+
const total = ((avatars.current) ? avatars.current.value.length : 0) + ((avatars.old) ? avatars.old.value.length : 0);
1810+
if (total && total < maxFileSize) {
1811+
if (avatars.current) {
1812+
embed.setAuthor(undefined, `attachment://${avatars.current.filename}`);
1813+
files.push(avatars.current);
1814+
}
1815+
if (avatars.old) {
1816+
embed.setThumbnail(`attachment://${avatars.old.filename}`);
1817+
files.push(avatars.old);
1818+
}
18111819
}
18121820
}
18131821

src/utils/paginator.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,14 @@ export class Paginator {
467467
}; break;
468468
case PageButtonNames.STOP: {
469469
await this.onStop(null, true, context, true);
470-
if (context instanceof Command.Context && !context.message.deleted && context.message.canDelete) {
471-
try {
472-
await context.message.delete();
473-
} catch(error) {
474-
470+
if (this.context instanceof Command.Context) {
471+
const message = this.context.message;
472+
if (!message.deleted && message.canDelete) {
473+
try {
474+
await message.delete();
475+
} catch(error) {
476+
477+
}
475478
}
476479
}
477480
}; break;

0 commit comments

Comments
 (0)