From add1dbd7898de13bd5e4e0cf888eb85b3cfe5816 Mon Sep 17 00:00:00 2001 From: Sqaaakoi Date: Sun, 29 Dec 2024 14:08:21 +1300 Subject: [PATCH] Refactor code, add settings, add threshold for DMs --- README.md | 11 +++++------ index.tsx | 36 ++++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 81c4177..1a918e6 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,12 @@ Works with SilentTyping ## What it does -Only allows the typing start event listener to be called when at least one the following conditions are met +Only allows the start typing logic to run when at least one the following conditions are met -- You are typing in your current voice channel -- There is at least one message in the current channel that meets all of the following requirements - - Sent by yourself - - Not deleted (MessageLogger) - - Sent within the past 5 minutes +- The channel you are typing in is the voice channel you are currently in +- Your most recent editable message in the channel was posted within the past 5 minutes or 1 day (DMs and group chats) + +These conditions are configurable. ## Installation diff --git a/index.tsx b/index.tsx index eacb1c9..c47e4fb 100644 --- a/index.tsx +++ b/index.tsx @@ -1,15 +1,34 @@ +import { definePluginSettings } from "@api/Settings"; import { Devs } from "@utils/constants"; -import definePlugin from "@utils/types"; -import { MessageStore, SelectedChannelStore, UserStore } from "@webpack/common"; -import { Message } from "discord-types/general"; +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 + } +}); export default definePlugin({ name: "ShyTyping", description: "Prevents you from accidentally revealing that you're lurking in a channel", authors: [Devs.Sqaaakoi], - + settings, patches: [ { + // This patch is intentionally different to the patch used in SilentTyping, so they can be compatible with each other find: '"TypingStore"', replacement: { match: /(TYPING_START_LOCAL:)(\i)/, @@ -25,13 +44,10 @@ export default definePlugin({ }, shouldStartTyping(channelId: string): boolean { - if (SelectedChannelStore.getVoiceChannelId() === channelId) return true; - const meId = UserStore.getCurrentUser().id; - const threshold = Date.now() - (5 * 60 * 1000); + if (settings.store.currentVC && SelectedChannelStore.getVoiceChannelId() === channelId) return true; + const threshold = Date.now() - (settings.store[ChannelStore.getChannel(channelId).isPrivate() ? "thresholdInDms" : "threshold"] * 1000); // discord-types and the MessageStore types are so wrong and cursed - if ((MessageStore.getMessages(channelId)._array as Message[]).filter(m => m.author.id === meId && !(m as any)?.deleted).some(m => +m.timestamp > threshold)) return true; - - + if ((MessageStore as any).getLastEditableMessage(channelId).timestamp > threshold) return true; return false; }