From 8be433bd72acdf806ad8e47087de9e4d738efd2a Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Sun, 27 Oct 2024 02:48:11 -0400 Subject: [PATCH] Some Request Stuff --- src/equicordplugins/blockKeywords/index.ts | 25 ++++- .../customTimestamps/index.tsx | 98 +++++++++++++++++++ src/utils/constants.ts | 6 +- 3 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 src/equicordplugins/customTimestamps/index.tsx diff --git a/src/equicordplugins/blockKeywords/index.ts b/src/equicordplugins/blockKeywords/index.ts index f610c0e6..ccde2ec0 100644 --- a/src/equicordplugins/blockKeywords/index.ts +++ b/src/equicordplugins/blockKeywords/index.ts @@ -7,9 +7,12 @@ import { definePluginSettings, Settings } from "@api/Settings"; import { EquicordDevs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; +import { findByPropsLazy } from "@webpack"; import { MessageJSON } from "discord-types/general"; -var blockedKeywords: Array; +const RelationshipStore = findByPropsLazy("getRelationships", "isBlocked"); + +let blockedKeywords: Array; const settings = definePluginSettings({ blockedWords: { @@ -29,7 +32,13 @@ const settings = definePluginSettings({ description: "Whether to use a case sensitive search or not", default: false, restartNeeded: true - } + }, + ignoreBlockedMessages: { + description: "Completely ignores (recent) new messages bar", + type: OptionType.BOOLEAN, + default: true, + restartNeeded: true, + }, }); export default definePlugin({ @@ -44,6 +53,18 @@ export default definePlugin({ replace: "$&$1=$self.blockMessagesWithKeywords($1);" } }, + ...[ + '"ReadStateStore"' + ].map(find => ({ + find, + predicate: () => Settings.plugins.BlockKeywords.ignoreBlockedMessages && !Settings.plugins.NoBlockedMessages.ignoreBlockedMessages, + replacement: [ + { + match: /(?<=MESSAGE_CREATE:function\((\i)\){)/, + replace: (_, props) => `if($self.containsBlockedKeywords(${props}.message))return;` + } + ] + })), ], settings, diff --git a/src/equicordplugins/customTimestamps/index.tsx b/src/equicordplugins/customTimestamps/index.tsx new file mode 100644 index 00000000..59024930 --- /dev/null +++ b/src/equicordplugins/customTimestamps/index.tsx @@ -0,0 +1,98 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { definePluginSettings } from "@api/Settings"; +import { Link } from "@components/Link"; +import { Devs, EquicordDevs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { Forms, moment } from "@webpack/common"; + +const settings = definePluginSettings({ + cozyFormat: { + type: OptionType.STRING, + default: "[calendar]", + description: "time format to use in messages on cozy mode", + }, + compactFormat: { + type: OptionType.STRING, + default: "LT", + description: "time format on compact mode and hovering messages", + }, + tooltipFormat: { + type: OptionType.STRING, + default: "LLLL • [relative]", + description: "time format to use on tooltips", + }, + sameDayFormat: { + type: OptionType.STRING, + default: "HH:mm:ss", + description: "[calendar] format for today" + }, + lastDayFormat: { + type: OptionType.STRING, + default: "[yesterday] HH:mm:ss", + description: "[calendar] format for yesterday" + }, + lastWeekFormat: { + type: OptionType.STRING, + default: "ddd DD.MM.YYYY HH:mm:ss", + description: "[calendar] format for last week" + }, + sameElseFormat: { + type: OptionType.STRING, + default: "ddd DD.MM.YYYY HH:mm:ss", + description: "[calendar] format for older dates" + }, +}); + +export default definePlugin({ + name: "CustomTimestamps", + description: "Custom timestamps on messages and tooltips", + authors: [Devs.Rini, EquicordDevs.nvhhr], + settings, + settingsAboutComponent: () => ( + <> + How to use: + + Moment.js formatting documentation +

+ Additionally you can use these in your inputs:
+ [calendar] enables dynamic date formatting (see options below),
+ [relative] gives you times such as "4 hours ago".
+

+
+ + ), + patches: [{ + find: "MESSAGE_EDITED_TIMESTAMP_A11Y_LABEL.format", + replacement: [ + { + match: /(?<=\i=\i\?)\(0,\i\.\i\)\((\i),"LT"\):\(0,\i\.\i\)\(\i\)/, + replace: '$self.format($1,"compactFormat","[calendar]"):$self.format($1,"cozyFormat","LT")', + }, + { + match: /(?<=text:)\(0,\i.\i\)\((\i),"LLLL"\)(?=,)/, + replace: '$self.format($1,"tooltipFormat","LLLL")', + }, + ] + }], + + format(date: Date, key: string, fallback: string) { + const t = moment(date); + const sameDayFormat = settings.store.sameDayFormat || "HH:mm:ss"; + const lastDayFormat = settings.store.lastDayFormat || "[yesterday] HH:mm:ss"; + const lastWeekFormat = settings.store.lastWeekFormat || "ddd DD.MM.YYYY HH:mm:ss"; + const sameElseFormat = settings.store.sameElseFormat || "ddd DD.MM.YYYY HH:mm:ss"; + return t.format(settings.store[key] || fallback) + .replace("relative", () => t.fromNow()) + .replace("calendar", () => t.calendar(null, { + sameDay: sameDayFormat, + lastDay: lastDayFormat, + lastWeek: lastWeekFormat, + sameElse: sameElseFormat + })); + }, +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index f0840390..ac6d2394 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -945,7 +945,11 @@ export const EquicordDevs = Object.freeze({ }, SomeAspy: { name: "SomeAspy", - id: 516750892372852754n, + id: 516750892372852754n + }, + nvhhr: { + name: "nvhhr", + id: 165098921071345666n }, } satisfies Record);