Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EmoteCloner: Fix a hang when the sticker/original server is deleted #3087

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 39 additions & 9 deletions src/plugins/emoteCloner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,20 @@ async function fetchSticker(id: string) {
const cached = StickersStore.getStickerById(id);
if (cached) return cached;

const { body } = await RestAPI.get({
url: Constants.Endpoints.STICKER(id)
});
try {
const { body } = await RestAPI.get({
url: Constants.Endpoints.STICKER(id)
});

FluxDispatcher.dispatch({
type: "STICKER_FETCH_SUCCESS",
sticker: body
});
FluxDispatcher.dispatch({
type: "STICKER_FETCH_SUCCESS",
sticker: body
});

return body as Sticker;
return body as Sticker;
} catch (err) {
return undefined;
Comment on lines +77 to +78
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (err) {
return undefined;
} catch {
// do nothing

}
}

async function cloneSticker(guildId: string, sticker: Sticker) {
Expand Down Expand Up @@ -336,7 +340,33 @@ const messageContextMenuPatch: NavContextMenuPatchCallback = (children, props) =
const sticker = props.message.stickerItems.find(s => s.id === favoriteableId);
if (sticker?.format_type === 3 /* LOTTIE */) return;

return buildMenuItem("Sticker", () => fetchSticker(favoriteableId));
// Workaround for cases when it's not available
// (e.g when using MessageLinkEmkbeds)
if (sticker === undefined) {
return;
}
Comment on lines +345 to +347
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (sticker === undefined) {
return;
}
if (!sticker) return;


return buildMenuItem("Sticker", async () => {
const fetchedSticker = await fetchSticker(favoriteableId);

// Workaround for incase the sticker or the server it's from is deleted.
// Allows the sticker to still be cloned.
if (fetchedSticker === undefined) {
return {
"id": sticker?.id,
"name": sticker?.name,
"format_type": sticker?.format_type,
// Discord has a character limit of at least 1 for tags (aka related emoji)
"tags": " ",
"description": "",
"type": "2",
"available": true,
"guild_id": 0
Comment on lines +356 to +364
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format to have normal key names not in quotes

};
} else {
return fetchedSticker;
}
Comment on lines +366 to +368
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else {
return fetchedSticker;
}
}
return fetchedSticker;

});
}
})();

Expand Down
Loading