shyTyping/index.tsx

55 lines
2 KiB
TypeScript
Raw Normal View History

import { definePluginSettings } from "@api/Settings";
2024-12-28 02:24:40 -05:00
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { ChannelStore, MessageStore, SelectedChannelStore, UserStore } from "@webpack/common";
const settings = definePluginSettings({
currentVC: {
type: OptionType.BOOLEAN,
description: "Always show you are typing in your current voice channel",
default: true
},
threshold: {
type: OptionType.NUMBER,
description: "Last message must be sent in the current channel within the past [threshold] seconds for the typing indicator to be shown",
default: 300
},
thresholdInDms: {
type: OptionType.NUMBER,
description: "Threshold above, for DMs and group chats",
default: 86400
}
});
2024-12-28 02:24:40 -05:00
export default definePlugin({
name: "ShyTyping",
description: "Prevents you from accidentally revealing that you're lurking in a channel",
authors: [Devs.Sqaaakoi],
settings,
2024-12-28 02:24:40 -05:00
patches: [
{
// This patch is intentionally different to the patch used in SilentTyping, so they can be compatible with each other
2024-12-28 02:24:40 -05:00
find: '"TypingStore"',
replacement: {
match: /(TYPING_START_LOCAL:)(\i)/,
replace: "$1$self.wrap($2)"
}
}
],
wrap(startTyping: ({ channelId }: { channelId: string; }) => void) {
return (e: { channelId: string; }) => {
return this.shouldStartTyping(e.channelId) && startTyping(e);
};
},
shouldStartTyping(channelId: string): boolean {
if (settings.store.currentVC && SelectedChannelStore.getVoiceChannelId() === channelId) return true;
const threshold = Date.now() - (settings.store[ChannelStore.getChannel(channelId).isPrivate() ? "thresholdInDms" : "threshold"] * 1000);
2024-12-28 02:24:40 -05:00
// discord-types and the MessageStore types are so wrong and cursed
if ((MessageStore as any).getLastEditableMessage(channelId).timestamp > threshold) return true;
2024-12-28 02:24:40 -05:00
return false;
}
});