Refactor code, add settings, add threshold for DMs
This commit is contained in:
parent
53f3f71d02
commit
add1dbd789
2 changed files with 31 additions and 16 deletions
11
README.md
11
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
|
||||
|
||||
|
|
36
index.tsx
36
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue