sentFromMyUname/index.ts

60 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2024-12-29 09:19:32 -05:00
import { addPreSendListener, removePreSendListener } from "@api/MessageEvents";
import { definePluginSettings, Settings } from "@api/Settings";
2024-12-28 10:15:35 -05:00
import { Devs } from "@utils/constants";
2024-12-29 09:19:32 -05:00
import definePlugin, { OptionType, PluginNative } from "@utils/types";
2024-12-28 10:15:35 -05:00
export const Native = VencordNative.pluginHelpers.SentFromMyUname as PluginNative<typeof import("./native")>;
2024-12-29 09:19:32 -05:00
async function getWhateverShouldBeSentFromMy() {
2024-12-29 11:57:25 -05:00
if (Settings.plugins.SentFromMyUname.signatureToUse === "iPhone") {
return "iPhone";
}
2024-12-29 09:19:32 -05:00
if ((IS_DISCORD_DESKTOP || IS_VESKTOP) && Settings.plugins.SentFromMyUname.signatureToUse === "uname") {
try {
return await Native.getUname();
}
catch {
return navigator.userAgent;
}
}
else return navigator.userAgent;
}
2024-12-28 10:15:35 -05:00
export default definePlugin({
name: "SentFromMyUname",
2024-12-29 09:19:32 -05:00
description: "Add your uname/useragent to every single message you send",
2024-12-28 10:15:35 -05:00
authors: [Devs.nin0dev],
2024-12-29 09:19:32 -05:00
settings: definePluginSettings({
signatureToUse: {
description: "What to show after 'Sent from my'",
type: OptionType.SELECT,
options: [{
label: "Attempt to use uname, useragent if can't use uname",
value: "uname"
}, {
label: "Always use useragent",
value: "useragent"
2024-12-29 11:57:25 -05:00
}, {
label: "Sent from my iPhone",
value: "iPhone"
2024-12-29 09:19:32 -05:00
}],
default: "uname"
},
channelWhitelist: {
description: "If set, only use plugin in this comma-separated channel whitelist",
type: OptionType.STRING
}
}),
2024-12-28 10:15:35 -05:00
start() {
2024-12-29 09:19:32 -05:00
this.preSend = addPreSendListener(async (c, msg) => {
if (Settings.plugins.SentFromMyUname.channelWhitelist && !Settings.plugins.SentFromMyUname.channelWhitelist.includes(c)) return;
if (msg.content.startsWith("nouname ")) { msg.content = msg.content.replace("nouname ", ""); return; }
msg.content += `\n\nSent from my ${await getWhateverShouldBeSentFromMy()}`;
2024-12-28 10:15:35 -05:00
});
2024-12-29 09:19:32 -05:00
},
stop() {
removePreSendListener(this.preSend);
2024-12-28 10:15:35 -05:00
}
});