SendTimestamps: add setting to disable message replacement (#2076)
This commit is contained in:
parent
6530526fb2
commit
be9ec3b7ac
2 changed files with 20 additions and 3 deletions
|
@ -19,14 +19,23 @@
|
||||||
import "./styles.css";
|
import "./styles.css";
|
||||||
|
|
||||||
import { addPreSendListener, removePreSendListener } from "@api/MessageEvents";
|
import { addPreSendListener, removePreSendListener } from "@api/MessageEvents";
|
||||||
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import { classNameFactory } from "@api/Styles";
|
import { classNameFactory } from "@api/Styles";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { getTheme, insertTextIntoChatInputBox, Theme } from "@utils/discord";
|
import { getTheme, insertTextIntoChatInputBox, Theme } from "@utils/discord";
|
||||||
import { Margins } from "@utils/margins";
|
import { Margins } from "@utils/margins";
|
||||||
import { closeModal, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModal } from "@utils/modal";
|
import { closeModal, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModal } from "@utils/modal";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { Button, ButtonLooks, ButtonWrapperClasses, Forms, Parser, Select, Tooltip, useMemo, useState } from "@webpack/common";
|
import { Button, ButtonLooks, ButtonWrapperClasses, Forms, Parser, Select, Tooltip, useMemo, useState } from "@webpack/common";
|
||||||
|
|
||||||
|
const settings = definePluginSettings({
|
||||||
|
replaceMessageContents: {
|
||||||
|
description: "Replace timestamps in message contents",
|
||||||
|
type: OptionType.BOOLEAN,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
function parseTime(time: string) {
|
function parseTime(time: string) {
|
||||||
const cleanTime = time.slice(1, -1).replace(/(\d)(AM|PM)$/i, "$1 $2");
|
const cleanTime = time.slice(1, -1).replace(/(\d)(AM|PM)$/i, "$1 $2");
|
||||||
|
|
||||||
|
@ -116,9 +125,11 @@ function PickerModal({ rootProps, close }: { rootProps: ModalProps, close(): voi
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "SendTimestamps",
|
name: "SendTimestamps",
|
||||||
description: "Send timestamps easily via chat box button & text shortcuts. Read the extended description!",
|
description: "Send timestamps easily via chat box button & text shortcuts. Read the extended description!",
|
||||||
authors: [Devs.Ven, Devs.Tyler],
|
authors: [Devs.Ven, Devs.Tyler, Devs.Grzesiek11],
|
||||||
dependencies: ["MessageEventsAPI"],
|
dependencies: ["MessageEventsAPI"],
|
||||||
|
|
||||||
|
settings: settings,
|
||||||
|
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
find: "ChannelTextAreaButtons",
|
find: "ChannelTextAreaButtons",
|
||||||
|
@ -131,7 +142,9 @@ export default definePlugin({
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
this.listener = addPreSendListener((_, msg) => {
|
this.listener = addPreSendListener((_, msg) => {
|
||||||
|
if (settings.store.replaceMessageContents) {
|
||||||
msg.content = msg.content.replace(/`\d{1,2}:\d{2} ?(?:AM|PM)?`/gi, parseTime);
|
msg.content = msg.content.replace(/`\d{1,2}:\d{2} ?(?:AM|PM)?`/gi, parseTime);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -399,6 +399,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({
|
||||||
name: "maisy",
|
name: "maisy",
|
||||||
id: 257109471589957632n,
|
id: 257109471589957632n,
|
||||||
},
|
},
|
||||||
|
Grzesiek11: {
|
||||||
|
name: "Grzesiek11",
|
||||||
|
id: 368475654662127616n,
|
||||||
|
},
|
||||||
} satisfies Record<string, Dev>);
|
} satisfies Record<string, Dev>);
|
||||||
|
|
||||||
// iife so #__PURE__ works correctly
|
// iife so #__PURE__ works correctly
|
||||||
|
|
Loading…
Reference in a new issue