This commit is contained in:
thororen1234 2025-12-31 21:02:09 -05:00
parent 8eeca5a940
commit c00fad66da
No known key found for this signature in database
2 changed files with 39 additions and 36 deletions

View file

@ -4,14 +4,15 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { ApplicationCommandType } from "@api/Commands";
import { ApplicationCommandInputType } from "@api/Commands";
import { showNotification } from "@api/Notifications";
import { isPluginEnabled } from "@api/PluginManager";
import { definePluginSettings } from "@api/Settings";
import equicordToolbox from "@equicordplugins/equicordToolbox";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { saveFile } from "@utils/web";
import { UserSettingsActionCreators } from "@webpack/common";
import { Menu, UserSettingsActionCreators } from "@webpack/common";
async function saveContentToFile(content: string, filename: string) {
try {
@ -45,7 +46,7 @@ function getGifUrls(): string[] {
async function saveAllGifs() {
const filename = `favorite-gifs-${new Date().toISOString().split("T")[0]}.txt`;
const gifUrls = getGifUrls();
if (gifUrls.length === 0) {
showNotification({ title: "Save Favorite GIFs", body: "No favorite GIFs found..?" });
return;
@ -57,7 +58,7 @@ async function saveAllGifs() {
async function saveWorkingGifs() {
const gifUrls = getGifUrls();
if (gifUrls.length === 0) {
showNotification({ title: "Save Favorite GIFs", body: "No favorite GIFs found?" });
return;
@ -66,12 +67,11 @@ async function saveWorkingGifs() {
showNotification({
title: "Save Favorite GIFs",
body: `Testing ${gifUrls.length} GIFs.. This may take a moment...`,
loading: true
});
const workingUrls: string[] = [];
await Promise.all(gifUrls.map(async (url) => {
await Promise.all(gifUrls.map(async url => {
try {
const response = await fetch(url, { method: "HEAD" });
if (response.ok) workingUrls.push(url);
@ -90,9 +90,9 @@ async function saveWorkingGifs() {
const filename = `working-gifs-${new Date().toISOString().split("T")[0]}.txt`;
const content = workingUrls.join("\n");
await saveContentToFile(content, filename);
showNotification({
title: "Save Favorite GIFs",
body: `Filtered ${gifUrls.length - workingUrls.length} possibly broken GIFs. Saved ${workingUrls.length} working GIFs.`,
@ -121,24 +121,27 @@ export default definePlugin({
{
name: "savegifs",
description: "Save all favorite GIF urls to a text file",
type: ApplicationCommandType.Chat,
action: saveAllGifs
inputType: ApplicationCommandInputType.BUILT_IN,
execute: saveAllGifs
},
{
name: "saveworkinggifs",
description: "Test all favorite GIFs and only save the ones that are still working",
type: ApplicationCommandType.Chat,
action: saveWorkingGifs
inputType: ApplicationCommandInputType.BUILT_IN,
execute: saveWorkingGifs
}
],
toolboxActions() {
const { showToolboxButton } = settings.use(["showToolboxButton"]);
if (!showToolboxButton) return null;
return {
"Save Favorite GIFs": () => {
saveAllGifs();
}
};
return (
<Menu.MenuItem
id="save-favorite-gifs-toolbox"
label="Save Favorite GIFs"
action={saveAllGifs}
/>
);
}
});

View file

@ -126,26 +126,26 @@ export default definePlugin({
"textarea-context": ChatBarContextCheckbox
},
commands: [{
name: "Signature",
description: "Toggle your signature",
inputType: ApplicationCommandInputType.BUILT_IN,
options: [
{
name: "value",
description: "Toggle your signature (default is toggle)",
required: false,
type: ApplicationCommandOptionType.BOOLEAN,
commands: [
{
name: "signature",
description: "Toggle your signature",
inputType: ApplicationCommandInputType.BUILT_IN,
options: [
{
name: "value",
description: "Toggle your signature (default is toggle)",
required: false,
type: ApplicationCommandOptionType.BOOLEAN,
},
],
execute: async (args, ctx) => {
settings.store.isEnabled = !!findOption(args, "value", !settings.store.isEnabled);
sendBotMessage(ctx.channel.id, {
content: settings.store.isEnabled ? "Signature enabled!" : "Signature disabled!",
});
},
],
execute: async (args, ctx) => {
settings.store.isEnabled = !!findOption(args, "value", !settings.store.isEnabled);
sendBotMessage(ctx.channel.id, {
content: settings.store.isEnabled ? "Signature enabled!" : "Signature disabled!",
});
},
}
}
],
});