- {Object.entries(groupedEmojis).map(([guildId, emojis]) => (
-
-
-
toggleGroupCollapse(guildId)}>
- {guildId === "default" ? "Default Emojis" : `${GuildStore.getGuild(guildId)?.name || `Guild ${guildId}`} Emojis`}
-
-
-
- {!collapsedGroups[guildId] && (
-
- {emojis.map(emoji => (
-
-
{emoji.name}
- {emoji.surrogates ? (
-
{emoji.surrogates}
- ) : (
-

- )}
-
-
- ))}
-
- )}
-
- ))}
- {whitelistedEmojis.length === 0 && (
-
No emojis in the whitelist.
- )}
-
- );
-};
-
-const exportEmojis = async () => {
- const fileName = "whitelisted-emojis.json";
- const exportData = await exportEmojisToJson();
- const data = new TextEncoder().encode(exportData);
-
- if (IS_WEB || IS_EQUIBOP || IS_VESKTOP) {
- const file = new File([data], fileName, { type: "application/json" });
- const a = document.createElement("a");
- a.href = URL.createObjectURL(file);
- a.download = fileName;
-
- document.body.appendChild(a);
- a.click();
- setImmediate(() => {
- URL.revokeObjectURL(a.href);
- document.body.removeChild(a);
- });
- } else {
- DiscordNative.fileManager.saveWithDialog(data, fileName);
- }
-
- if (!settings.store.disableToasts) {
- Toasts.show({
- message: "Successfully exported emojis",
- type: Toasts.Type.SUCCESS,
- id: Toasts.genId(),
- options: {
- duration: 3000,
- position: Toasts.Position.BOTTOM
- }
- });
- }
-};
-
-async function exportEmojisToJson() {
- const emojis = await getAllowedList();
- return JSON.stringify({ emojis }, null, 4);
-}
-
-const uploadEmojis = async () => {
- if (IS_WEB || IS_EQUIBOP || IS_VESKTOP) {
- const input = document.createElement("input");
- input.type = "file";
- input.style.display = "none";
- input.accept = "application/json";
- input.onchange = async () => {
- const file = input.files?.[0];
- if (!file) return;
-
- const reader = new FileReader();
- reader.onload = async () => {
- const data = reader.result as string;
- await importEmojis(data);
- };
-
- reader.readAsText(file);
- };
-
- document.body.appendChild(input);
- input.click();
- setImmediate(() => {
- document.body.removeChild(input);
- });
- } else {
- const [file] = await DiscordNative.fileManager.openFiles({
- filters: [
- { name: "Whitelisted Emojis", extensions: ["json"] },
- { name: "all", extensions: ["*"] }
- ]
- });
-
- if (file) {
- try {
- await importEmojis(new TextDecoder().decode(file.data));
- } catch (err) {
- console.error(err);
- if (!settings.store.disableToasts) {
- Toasts.show({
- message: `Failed to import emojis: ${err}`,
- type: Toasts.Type.FAILURE,
- id: Toasts.genId(),
- options: {
- duration: 3000,
- position: Toasts.Position.BOTTOM
- }
- });
- }
- }
- }
- }
-};
-
-const importEmojis = async (data: string) => {
- try {
- const parsed = JSON.parse(data);
- if (parsed && typeof parsed === "object" && Array.isArray(parsed.emojis)) {
- await DataStore.set(DATA_COLLECTION_NAME, parsed.emojis);
- cache_allowedList = await getAllowedList();
-
- if (!settings.store.disableToasts) {
- Toasts.show({
- message: "Successfully imported emojis",
- type: Toasts.Type.SUCCESS,
- id: Toasts.genId(),
- options: {
- duration: 3000,
- position: Toasts.Position.BOTTOM
- }
- });
- }
- } else {
- if (!settings.store.disableToasts) {
- Toasts.show({
- message: "Invalid JSON data",
- type: Toasts.Type.FAILURE,
- id: Toasts.genId(),
- options: {
- duration: 3000,
- position: Toasts.Position.BOTTOM
- }
- });
- }
- }
- } catch (err) {
- if (!settings.store.disableToasts) {
- Toasts.show({
- message: `Failed to import emojis: ${err}`,
- type: Toasts.Type.FAILURE,
- id: Toasts.genId(),
- options: {
- duration: 3000,
- position: Toasts.Position.BOTTOM
- }
- });
- }
- }
-};
-
-const resetEmojis = async () => {
- await DataStore.set(DATA_COLLECTION_NAME, []);
- cache_allowedList = await getAllowedList();
-
- if (!settings.store.disableToasts) {
- Toasts.show({
- message: "Reset emojis",
- type: Toasts.Type.SUCCESS,
- id: Toasts.genId(),
- options: {
- duration: 3000,
- position: Toasts.Position.BOTTOM
- }
- });
- }
-};
-
-const settings = definePluginSettings({
- defaultEmojis: {
- type: OptionType.BOOLEAN,
- description: "Hide default emojis",
- default: true
- },
- serverEmojis: {
- type: OptionType.BOOLEAN,
- description: "Hide server emojis",
- default: true
- },
- disableToasts: {
- type: OptionType.BOOLEAN,
- description: "Disable toasts",
- default: false
- },
- whiteListedEmojis: {
- type: OptionType.COMPONENT,
- description: "Whitelisted Emojis",
- component: WhiteListedEmojisComponent
- },
- exportEmojis: {
- type: OptionType.COMPONENT,
- description: "Export Emojis",
- component: () => (
-