2026-04-22 22:02:36 -04:00
|
|
|
import { definePluginSettings } from "@api/Settings";
|
|
|
|
|
import { OptionType } from "@utils/types";
|
|
|
|
|
import { Button, showToast, Toasts } from "@webpack/common";
|
|
|
|
|
|
|
|
|
|
import { sendTestWebhook } from "./webhook";
|
|
|
|
|
|
2026-04-28 00:25:17 -04:00
|
|
|
function getToastErrorMessage(error: unknown) {
|
|
|
|
|
return error instanceof Error
|
|
|
|
|
? error.message
|
|
|
|
|
: "Failed to send test webhook.";
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 22:02:36 -04:00
|
|
|
function TestWebhookButton() {
|
|
|
|
|
const { webhookUrl } = settings.use(["webhookUrl"]);
|
|
|
|
|
const disabled = webhookUrl.trim().length === 0;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Button
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
void sendTestWebhook(webhookUrl)
|
|
|
|
|
.then(() => {
|
|
|
|
|
showToast("Test webhook sent successfully.", Toasts.Type.SUCCESS);
|
|
|
|
|
})
|
2026-04-28 00:25:17 -04:00
|
|
|
.catch((error: unknown) => {
|
|
|
|
|
showToast(getToastErrorMessage(error), Toasts.Type.FAILURE);
|
2026-04-22 22:02:36 -04:00
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Send Test Webhook
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const settings = definePluginSettings({
|
|
|
|
|
ignoreOwnGiftLinks: {
|
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
|
description: "Do not redeem Nitro gift links from messages sent by you.",
|
|
|
|
|
default: false,
|
|
|
|
|
restartNeeded: false
|
|
|
|
|
},
|
|
|
|
|
webhookUrl: {
|
|
|
|
|
type: OptionType.STRING,
|
|
|
|
|
description: "Discord webhook URL to notify after each redeem attempt. Leave empty to disable.",
|
|
|
|
|
default: "",
|
|
|
|
|
restartNeeded: false
|
|
|
|
|
},
|
|
|
|
|
testWebhook: {
|
|
|
|
|
type: OptionType.COMPONENT,
|
|
|
|
|
description: "Send a test message to the configured webhook.",
|
|
|
|
|
component: TestWebhookButton
|
|
|
|
|
}
|
|
|
|
|
});
|