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
|
## 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
|
- The channel you are typing in is the voice channel you are currently in
|
||||||
- There is at least one message in the current channel that meets all of the following requirements
|
- Your most recent editable message in the channel was posted within the past 5 minutes or 1 day (DMs and group chats)
|
||||||
- Sent by yourself
|
|
||||||
- Not deleted (MessageLogger)
|
These conditions are configurable.
|
||||||
- Sent within the past 5 minutes
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|
36
index.tsx
36
index.tsx
|
@ -1,15 +1,34 @@
|
||||||
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { MessageStore, SelectedChannelStore, UserStore } from "@webpack/common";
|
import { ChannelStore, MessageStore, SelectedChannelStore, UserStore } from "@webpack/common";
|
||||||
import { Message } from "discord-types/general";
|
|
||||||
|
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({
|
export default definePlugin({
|
||||||
name: "ShyTyping",
|
name: "ShyTyping",
|
||||||
description: "Prevents you from accidentally revealing that you're lurking in a channel",
|
description: "Prevents you from accidentally revealing that you're lurking in a channel",
|
||||||
authors: [Devs.Sqaaakoi],
|
authors: [Devs.Sqaaakoi],
|
||||||
|
settings,
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
|
// This patch is intentionally different to the patch used in SilentTyping, so they can be compatible with each other
|
||||||
find: '"TypingStore"',
|
find: '"TypingStore"',
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(TYPING_START_LOCAL:)(\i)/,
|
match: /(TYPING_START_LOCAL:)(\i)/,
|
||||||
|
@ -25,13 +44,10 @@ export default definePlugin({
|
||||||
},
|
},
|
||||||
|
|
||||||
shouldStartTyping(channelId: string): boolean {
|
shouldStartTyping(channelId: string): boolean {
|
||||||
if (SelectedChannelStore.getVoiceChannelId() === channelId) return true;
|
if (settings.store.currentVC && SelectedChannelStore.getVoiceChannelId() === channelId) return true;
|
||||||
const meId = UserStore.getCurrentUser().id;
|
const threshold = Date.now() - (settings.store[ChannelStore.getChannel(channelId).isPrivate() ? "thresholdInDms" : "threshold"] * 1000);
|
||||||
const threshold = Date.now() - (5 * 60 * 1000);
|
|
||||||
// discord-types and the MessageStore types are so wrong and cursed
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue