Skip to content

Commit

Permalink
chore: remove locallyStored as option entirely
Browse files Browse the repository at this point in the history
all sounds are always locally stored, as discord added TTL to their URLs months ago. We already set the option to always be true, but now we can enforce it and remove the outdated fallback behavior
  • Loading branch information
maybeanerd committed Jun 16, 2024
1 parent 2306144 commit c5143a9
Showing 1 changed file with 13 additions and 34 deletions.
47 changes: 13 additions & 34 deletions src/commands/joinsound/management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ async function setSound(
userId: string,
guildId: string,
soundUrl: string | undefined,
locallyStored: boolean,
): Promise<JoinsoundStoreError | null> {
const user = await getUser(userId, guildId);
if (!locallyStored) {
user.sound = soundUrl;
await removeLocallyStoredJoinsoundOfTarget({ userId, guildId });
} else if (soundUrl) {
if (soundUrl) {
user.sound = 'local';
const error = await storeJoinsoundOfTarget({ userId, guildId }, soundUrl);
if (error) {
Expand All @@ -65,20 +61,16 @@ async function setSound(
}

export async function removeSound(userId: string, guildId: string) {
return setSound(userId, guildId, undefined, true);
return setSound(userId, guildId, undefined);
}

async function setDefaultSound(
userId: string,
soundUrl: string | undefined,
locallyStored: boolean,
): Promise<JoinsoundStoreError | null> {
const user = await getGlobalUser(userId);

if (!locallyStored) {
user.sound = soundUrl;
await removeLocallyStoredJoinsoundOfTarget({ userId, default: true });
} else if (soundUrl) {
if (soundUrl) {
user.sound = 'local';
const error = await storeJoinsoundOfTarget(
{ userId, default: true },
Expand All @@ -98,20 +90,16 @@ async function setDefaultSound(
}

export async function removeDefaultSound(userId: string) {
return setDefaultSound(userId, undefined, true);
return setDefaultSound(userId, undefined);
}

async function setDefaultGuildJoinsound(
guildId: string,
soundUrl: string | undefined,
locallyStored: boolean,
): Promise<JoinsoundStoreError | null> {
const guild = await getConfiguration(guildId);

if (!locallyStored) {
guild.defaultJoinsound = soundUrl;
await removeLocallyStoredJoinsoundOfTarget({ guildId, default: true });
} else if (soundUrl) {
if (soundUrl) {
guild.defaultJoinsound = 'local';
const error = await storeJoinsoundOfTarget(
{ guildId, default: true },
Expand All @@ -131,7 +119,7 @@ async function setDefaultGuildJoinsound(
}

export async function removeDefaultGuildJoinsound(guildId: string) {
return setDefaultGuildJoinsound(guildId, undefined, true);
return setDefaultGuildJoinsound(guildId, undefined);
}

const defaultFFProbeLocation = '/usr/bin/ffprobe';
Expand All @@ -154,7 +142,8 @@ export async function validateAndSaveJoinsound(
}
if (attachment.size > maximumSingleFileSize) {
interaction.followUp(
`The file you sent is larger than ${maximumSingleFileSize / 1024
`The file you sent is larger than ${
maximumSingleFileSize / 1024
} KB, which is the limit per file!`,
);
return;
Expand Down Expand Up @@ -204,23 +193,12 @@ export async function validateAndSaveJoinsound(

let error: JoinsoundStoreError | null;

const locallyStored = true; // we only support downloading the files

if (defaultForGuildId) {
error = await setDefaultGuildJoinsound(
defaultForGuildId,
soundUrl,
locallyStored,
);
error = await setDefaultGuildJoinsound(defaultForGuildId, soundUrl);
} else if (setDefault) {
error = await setDefaultSound(userId, soundUrl, locallyStored);
error = await setDefaultSound(userId, soundUrl);
} else {
error = await setSound(
userId,
interaction.guild!.id,
soundUrl,
locallyStored,
);
error = await setSound(userId, interaction.guild!.id, soundUrl);
}
if (error) {
if (error === JoinsoundStoreError.noStorageLeftForUser) {
Expand Down Expand Up @@ -346,7 +324,8 @@ export async function getJoinsoundOverviewOfUser(

info.push({
name: 'Storage Used by Joinsounds',
value: `**${(storageUsed / 1024).toFixed(1)} KB** / ${joinsoundStorageUserLimit / 1024
value: `**${(storageUsed / 1024).toFixed(1)} KB** / ${
joinsoundStorageUserLimit / 1024
} KB`,
inline: false,
});
Expand Down

0 comments on commit c5143a9

Please sign in to comment.