mirror of
https://github.com/Equicord/Equicord.git
synced 2025-01-18 21:33:35 -05:00
plugins(messageLogger): block VOT instead of Gluestick & delete dev-talk
This commit is contained in:
parent
c76ec331a5
commit
0ba03c263d
1 changed files with 506 additions and 435 deletions
|
@ -14,11 +14,14 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "./messageLogger.css";
|
import "./messageLogger.css";
|
||||||
|
|
||||||
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
|
import {
|
||||||
|
findGroupChildrenByChildId,
|
||||||
|
NavContextMenuPatchCallback,
|
||||||
|
} from "@api/ContextMenu";
|
||||||
import { updateMessage } from "@api/MessageUpdater";
|
import { updateMessage } from "@api/MessageUpdater";
|
||||||
import { Settings } from "@api/Settings";
|
import { Settings } from "@api/Settings";
|
||||||
import { disableStyle, enableStyle } from "@api/Styles";
|
import { disableStyle, enableStyle } from "@api/Styles";
|
||||||
|
@ -29,7 +32,18 @@ import { Logger } from "@utils/Logger";
|
||||||
import { classes } from "@utils/misc";
|
import { classes } from "@utils/misc";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { findByCodeLazy, findByPropsLazy } from "@webpack";
|
import { findByCodeLazy, findByPropsLazy } from "@webpack";
|
||||||
import { ChannelStore, FluxDispatcher, i18n, Menu, MessageStore, Parser, SelectedChannelStore, Timestamp, UserStore, useStateFromStores } from "@webpack/common";
|
import {
|
||||||
|
ChannelStore,
|
||||||
|
FluxDispatcher,
|
||||||
|
i18n,
|
||||||
|
Menu,
|
||||||
|
MessageStore,
|
||||||
|
Parser,
|
||||||
|
SelectedChannelStore,
|
||||||
|
Timestamp,
|
||||||
|
UserStore,
|
||||||
|
useStateFromStores,
|
||||||
|
} from "@webpack/common";
|
||||||
import { Message } from "discord-types/general";
|
import { Message } from "discord-types/general";
|
||||||
|
|
||||||
import overlayStyle from "./deleteStyleOverlay.css?managed";
|
import overlayStyle from "./deleteStyleOverlay.css?managed";
|
||||||
|
@ -38,11 +52,15 @@ import { openHistoryModal } from "./HistoryModal";
|
||||||
|
|
||||||
interface MLMessage extends Message {
|
interface MLMessage extends Message {
|
||||||
deleted?: boolean;
|
deleted?: boolean;
|
||||||
editHistory?: { timestamp: Date; content: string; }[];
|
editHistory?: { timestamp: Date; content: string }[];
|
||||||
firstEditTimestamp?: Date;
|
firstEditTimestamp?: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = findByPropsLazy("edited", "communicationDisabled", "isSystemMessage");
|
const styles = findByPropsLazy(
|
||||||
|
"edited",
|
||||||
|
"communicationDisabled",
|
||||||
|
"isSystemMessage",
|
||||||
|
);
|
||||||
const getMessage = findByCodeLazy('replace(/^\\n+|\\n+$/g,"")');
|
const getMessage = findByCodeLazy('replace(/^\\n+|\\n+$/g,"")');
|
||||||
|
|
||||||
function addDeleteStyle() {
|
function addDeleteStyle() {
|
||||||
|
@ -57,7 +75,10 @@ function addDeleteStyle() {
|
||||||
|
|
||||||
const REMOVE_HISTORY_ID = "ml-remove-history";
|
const REMOVE_HISTORY_ID = "ml-remove-history";
|
||||||
const TOGGLE_DELETE_STYLE_ID = "ml-toggle-style";
|
const TOGGLE_DELETE_STYLE_ID = "ml-toggle-style";
|
||||||
const patchMessageContextMenu: NavContextMenuPatchCallback = (children, props) => {
|
const patchMessageContextMenu: NavContextMenuPatchCallback = (
|
||||||
|
children,
|
||||||
|
props,
|
||||||
|
) => {
|
||||||
const { message } = props;
|
const { message } = props;
|
||||||
const { deleted, editHistory, id, channel_id } = message;
|
const { deleted, editHistory, id, channel_id } = message;
|
||||||
|
|
||||||
|
@ -66,20 +87,22 @@ const patchMessageContextMenu: NavContextMenuPatchCallback = (children, props) =
|
||||||
toggle: {
|
toggle: {
|
||||||
if (!deleted) break toggle;
|
if (!deleted) break toggle;
|
||||||
|
|
||||||
const domElement = document.getElementById(`chat-messages-${channel_id}-${id}`);
|
const domElement = document.getElementById(
|
||||||
|
`chat-messages-${channel_id}-${id}`,
|
||||||
|
);
|
||||||
if (!domElement) break toggle;
|
if (!domElement) break toggle;
|
||||||
|
|
||||||
children.push((
|
children.push(
|
||||||
<Menu.MenuItem
|
<Menu.MenuItem
|
||||||
id={TOGGLE_DELETE_STYLE_ID}
|
id={TOGGLE_DELETE_STYLE_ID}
|
||||||
key={TOGGLE_DELETE_STYLE_ID}
|
key={TOGGLE_DELETE_STYLE_ID}
|
||||||
label="Toggle Deleted Highlight"
|
label="Toggle Deleted Highlight"
|
||||||
action={() => domElement.classList.toggle("messagelogger-deleted")}
|
action={() => domElement.classList.toggle("messagelogger-deleted")}
|
||||||
/>
|
/>,
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
children.push((
|
children.push(
|
||||||
<Menu.MenuItem
|
<Menu.MenuItem
|
||||||
id={REMOVE_HISTORY_ID}
|
id={REMOVE_HISTORY_ID}
|
||||||
key={REMOVE_HISTORY_ID}
|
key={REMOVE_HISTORY_ID}
|
||||||
|
@ -91,42 +114,46 @@ const patchMessageContextMenu: NavContextMenuPatchCallback = (children, props) =
|
||||||
type: "MESSAGE_DELETE",
|
type: "MESSAGE_DELETE",
|
||||||
channelId: channel_id,
|
channelId: channel_id,
|
||||||
id,
|
id,
|
||||||
mlDeleted: true
|
mlDeleted: true,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
message.editHistory = [];
|
message.editHistory = [];
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>,
|
||||||
));
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const patchChannelContextMenu: NavContextMenuPatchCallback = (children, { channel }) => {
|
const patchChannelContextMenu: NavContextMenuPatchCallback = (
|
||||||
|
children,
|
||||||
|
{ channel },
|
||||||
|
) => {
|
||||||
const messages = MessageStore.getMessages(channel?.id) as MLMessage[];
|
const messages = MessageStore.getMessages(channel?.id) as MLMessage[];
|
||||||
if (!messages?.some(msg => msg.deleted || msg.editHistory?.length)) return;
|
if (!messages?.some((msg) => msg.deleted || msg.editHistory?.length)) return;
|
||||||
|
|
||||||
const group = findGroupChildrenByChildId("mark-channel-read", children) ?? children;
|
const group =
|
||||||
|
findGroupChildrenByChildId("mark-channel-read", children) ?? children;
|
||||||
group.push(
|
group.push(
|
||||||
<Menu.MenuItem
|
<Menu.MenuItem
|
||||||
id="vc-ml-clear-channel"
|
id="vc-ml-clear-channel"
|
||||||
label="Clear Message Log"
|
label="Clear Message Log"
|
||||||
color="danger"
|
color="danger"
|
||||||
action={() => {
|
action={() => {
|
||||||
messages.forEach(msg => {
|
messages.forEach((msg) => {
|
||||||
if (msg.deleted)
|
if (msg.deleted)
|
||||||
FluxDispatcher.dispatch({
|
FluxDispatcher.dispatch({
|
||||||
type: "MESSAGE_DELETE",
|
type: "MESSAGE_DELETE",
|
||||||
channelId: channel.id,
|
channelId: channel.id,
|
||||||
id: msg.id,
|
id: msg.id,
|
||||||
mlDeleted: true
|
mlDeleted: true,
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
updateMessage(channel.id, msg.id, {
|
updateMessage(channel.id, msg.id, {
|
||||||
editHistory: []
|
editHistory: [],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -149,28 +176,34 @@ export default definePlugin({
|
||||||
dependencies: ["MessageUpdaterAPI"],
|
dependencies: ["MessageUpdaterAPI"],
|
||||||
|
|
||||||
contextMenus: {
|
contextMenus: {
|
||||||
"message": patchMessageContextMenu,
|
message: patchMessageContextMenu,
|
||||||
"channel-context": patchChannelContextMenu,
|
"channel-context": patchChannelContextMenu,
|
||||||
"thread-context": patchChannelContextMenu,
|
"thread-context": patchChannelContextMenu,
|
||||||
"user-context": patchChannelContextMenu,
|
"user-context": patchChannelContextMenu,
|
||||||
"gdm-context": patchChannelContextMenu
|
"gdm-context": patchChannelContextMenu,
|
||||||
},
|
},
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
addDeleteStyle();
|
addDeleteStyle();
|
||||||
},
|
},
|
||||||
|
|
||||||
renderEdits: ErrorBoundary.wrap(({ message: { id: messageId, channel_id: channelId } }: { message: Message; }) => {
|
renderEdits: ErrorBoundary.wrap(
|
||||||
|
({
|
||||||
|
message: { id: messageId, channel_id: channelId },
|
||||||
|
}: {
|
||||||
|
message: Message;
|
||||||
|
}) => {
|
||||||
const message = useStateFromStores(
|
const message = useStateFromStores(
|
||||||
[MessageStore],
|
[MessageStore],
|
||||||
() => MessageStore.getMessage(channelId, messageId) as MLMessage,
|
() => MessageStore.getMessage(channelId, messageId) as MLMessage,
|
||||||
null,
|
null,
|
||||||
(oldMsg, newMsg) => oldMsg?.editHistory === newMsg?.editHistory
|
(oldMsg, newMsg) => oldMsg?.editHistory === newMsg?.editHistory,
|
||||||
);
|
);
|
||||||
|
|
||||||
return Settings.plugins.MessageLogger.inlineEdits && (
|
return (
|
||||||
|
Settings.plugins.MessageLogger.inlineEdits && (
|
||||||
<>
|
<>
|
||||||
{message.editHistory?.map(edit => (
|
{message.editHistory?.map((edit) => (
|
||||||
<div className="messagelogger-edited">
|
<div className="messagelogger-edited">
|
||||||
{parseEditContent(edit.content, message)}
|
{parseEditContent(edit.content, message)}
|
||||||
<Timestamp
|
<Timestamp
|
||||||
|
@ -178,18 +211,24 @@ export default definePlugin({
|
||||||
isEdited={true}
|
isEdited={true}
|
||||||
isInline={false}
|
isInline={false}
|
||||||
>
|
>
|
||||||
<span className={styles.edited}>{" "}({i18n.Messages.MESSAGE_EDITED})</span>
|
<span className={styles.edited}>
|
||||||
|
{" "}
|
||||||
|
({i18n.Messages.MESSAGE_EDITED})
|
||||||
|
</span>
|
||||||
</Timestamp>
|
</Timestamp>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}, { noop: true }),
|
},
|
||||||
|
{ noop: true },
|
||||||
|
),
|
||||||
|
|
||||||
makeEdit(newMessage: any, oldMessage: any): any {
|
makeEdit(newMessage: any, oldMessage: any): any {
|
||||||
return {
|
return {
|
||||||
timestamp: new Date(newMessage.edited_timestamp),
|
timestamp: new Date(newMessage.edited_timestamp),
|
||||||
content: oldMessage.content
|
content: oldMessage.content,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -200,9 +239,9 @@ export default definePlugin({
|
||||||
default: "text",
|
default: "text",
|
||||||
options: [
|
options: [
|
||||||
{ label: "Red text", value: "text", default: true },
|
{ label: "Red text", value: "text", default: true },
|
||||||
{ label: "Red overlay", value: "overlay" }
|
{ label: "Red overlay", value: "overlay" },
|
||||||
],
|
],
|
||||||
onChange: () => addDeleteStyle()
|
onChange: () => addDeleteStyle(),
|
||||||
},
|
},
|
||||||
logDeletes: {
|
logDeletes: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
|
@ -211,8 +250,9 @@ export default definePlugin({
|
||||||
},
|
},
|
||||||
collapseDeleted: {
|
collapseDeleted: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
description: "Whether to collapse deleted messages, similar to blocked messages",
|
description:
|
||||||
default: false
|
"Whether to collapse deleted messages, similar to blocked messages",
|
||||||
|
default: false,
|
||||||
},
|
},
|
||||||
logEdits: {
|
logEdits: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
|
@ -222,36 +262,40 @@ export default definePlugin({
|
||||||
inlineEdits: {
|
inlineEdits: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
description: "Whether to display edit history as part of message content",
|
description: "Whether to display edit history as part of message content",
|
||||||
default: true
|
default: true,
|
||||||
},
|
},
|
||||||
ignoreBots: {
|
ignoreBots: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
description: "Whether to ignore messages by bots",
|
description: "Whether to ignore messages by bots",
|
||||||
default: false
|
default: false,
|
||||||
},
|
},
|
||||||
ignoreSelf: {
|
ignoreSelf: {
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
description: "Whether to ignore messages by yourself",
|
description: "Whether to ignore messages by yourself",
|
||||||
default: false
|
default: false,
|
||||||
},
|
},
|
||||||
ignoreUsers: {
|
ignoreUsers: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Comma-separated list of user IDs to ignore",
|
description: "Comma-separated list of user IDs to ignore",
|
||||||
default: ""
|
default: "",
|
||||||
},
|
},
|
||||||
ignoreChannels: {
|
ignoreChannels: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Comma-separated list of channel IDs to ignore",
|
description: "Comma-separated list of channel IDs to ignore",
|
||||||
default: ""
|
default: "",
|
||||||
},
|
},
|
||||||
ignoreGuilds: {
|
ignoreGuilds: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Comma-separated list of guild IDs to ignore",
|
description: "Comma-separated list of guild IDs to ignore",
|
||||||
default: ""
|
default: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
handleDelete(cache: any, data: { ids: string[], id: string; mlDeleted?: boolean; }, isBulk: boolean) {
|
handleDelete(
|
||||||
|
cache: any,
|
||||||
|
data: { ids: string[]; id: string; mlDeleted?: boolean },
|
||||||
|
isBulk: boolean,
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
if (cache == null || (!isBulk && !cache.has(data.id))) return cache;
|
if (cache == null || (!isBulk && !cache.has(data.id))) return cache;
|
||||||
|
|
||||||
|
@ -260,16 +304,20 @@ export default definePlugin({
|
||||||
if (!msg) return;
|
if (!msg) return;
|
||||||
|
|
||||||
const EPHEMERAL = 64;
|
const EPHEMERAL = 64;
|
||||||
const shouldIgnore = data.mlDeleted ||
|
const shouldIgnore =
|
||||||
|
data.mlDeleted ||
|
||||||
(msg.flags & EPHEMERAL) === EPHEMERAL ||
|
(msg.flags & EPHEMERAL) === EPHEMERAL ||
|
||||||
this.shouldIgnore(msg);
|
this.shouldIgnore(msg);
|
||||||
|
|
||||||
if (shouldIgnore) {
|
if (shouldIgnore) {
|
||||||
cache = cache.remove(id);
|
cache = cache.remove(id);
|
||||||
} else {
|
} else {
|
||||||
cache = cache.update(id, m => m
|
cache = cache.update(id, (m) =>
|
||||||
.set("deleted", true)
|
m.set("deleted", true).set(
|
||||||
.set("attachments", m.attachments.map(a => (a.deleted = true, a))));
|
"attachments",
|
||||||
|
m.attachments.map((a) => ((a.deleted = true), a)),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -285,21 +333,36 @@ export default definePlugin({
|
||||||
},
|
},
|
||||||
|
|
||||||
shouldIgnore(message: any, isEdit = false) {
|
shouldIgnore(message: any, isEdit = false) {
|
||||||
const { ignoreBots, ignoreSelf, ignoreUsers, ignoreChannels, ignoreGuilds, logEdits, logDeletes } = Settings.plugins.MessageLogger;
|
const {
|
||||||
|
ignoreBots,
|
||||||
|
ignoreSelf,
|
||||||
|
ignoreUsers,
|
||||||
|
ignoreChannels,
|
||||||
|
ignoreGuilds,
|
||||||
|
logEdits,
|
||||||
|
logDeletes,
|
||||||
|
} = Settings.plugins.MessageLogger;
|
||||||
const myId = UserStore.getCurrentUser().id;
|
const myId = UserStore.getCurrentUser().id;
|
||||||
|
|
||||||
return ignoreBots && message.author?.bot ||
|
return (
|
||||||
ignoreSelf && message.author?.id === myId ||
|
(ignoreBots && message.author?.bot) ||
|
||||||
|
(ignoreSelf && message.author?.id === myId) ||
|
||||||
ignoreUsers.includes(message.author?.id) ||
|
ignoreUsers.includes(message.author?.id) ||
|
||||||
ignoreChannels.includes(message.channel_id) ||
|
ignoreChannels.includes(message.channel_id) ||
|
||||||
ignoreChannels.includes(ChannelStore.getChannel(message.channel_id)?.parent_id) ||
|
ignoreChannels.includes(
|
||||||
|
ChannelStore.getChannel(message.channel_id)?.parent_id,
|
||||||
|
) ||
|
||||||
(isEdit ? !logEdits : !logDeletes) ||
|
(isEdit ? !logEdits : !logDeletes) ||
|
||||||
ignoreGuilds.includes(ChannelStore.getChannel(message.channel_id)?.guild_id) ||
|
ignoreGuilds.includes(
|
||||||
|
ChannelStore.getChannel(message.channel_id)?.guild_id,
|
||||||
|
) ||
|
||||||
// Ignore Venbot in the support channel
|
// Ignore Venbot in the support channel
|
||||||
(message.channel_id === "1026515880080842772" && message.author?.id === "1017176847865352332")
|
(message.channel_id === "1026515880080842772" &&
|
||||||
|| // Ignore Gluestick on dev-talk & dev-playground
|
message.author?.id === "1017176847865352332") ||
|
||||||
(message.channel_id === "1297239805972709521" && message.author?.id === "1247291758857949224") ||
|
// Ignore VOT on dev-playground
|
||||||
(message.channel_id === "1297078407653228575" && message.author?.id === "1247291758857949224");
|
(message.channel_id === "1297239805972709521" &&
|
||||||
|
message.author?.id === "1199905841004937257")
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
EditMarker({ message, className, children, ...props }: any) {
|
EditMarker({ message, className, children, ...props }: any) {
|
||||||
|
@ -316,7 +379,9 @@ export default definePlugin({
|
||||||
},
|
},
|
||||||
|
|
||||||
Messages: proxyLazy(() => ({
|
Messages: proxyLazy(() => ({
|
||||||
DELETED_MESSAGE_COUNT: getMessage("{count, plural, =0 {No deleted messages} one {{count} deleted message} other {{count} deleted messages}}")
|
DELETED_MESSAGE_COUNT: getMessage(
|
||||||
|
"{count, plural, =0 {No deleted messages} one {{count} deleted message} other {{count} deleted messages}}",
|
||||||
|
),
|
||||||
})),
|
})),
|
||||||
|
|
||||||
patches: [
|
patches: [
|
||||||
|
@ -326,42 +391,45 @@ export default definePlugin({
|
||||||
replacement: [
|
replacement: [
|
||||||
{
|
{
|
||||||
// Add deleted=true to all target messages in the MESSAGE_DELETE event
|
// Add deleted=true to all target messages in the MESSAGE_DELETE event
|
||||||
match: /MESSAGE_DELETE:function\((\i)\){let.+?((?:\i\.){2})getOrCreate.+?},/,
|
match:
|
||||||
|
/MESSAGE_DELETE:function\((\i)\){let.+?((?:\i\.){2})getOrCreate.+?},/,
|
||||||
replace:
|
replace:
|
||||||
"MESSAGE_DELETE:function($1){" +
|
"MESSAGE_DELETE:function($1){" +
|
||||||
" var cache = $2getOrCreate($1.channelId);" +
|
" var cache = $2getOrCreate($1.channelId);" +
|
||||||
" cache = $self.handleDelete(cache, $1, false);" +
|
" cache = $self.handleDelete(cache, $1, false);" +
|
||||||
" $2commit(cache);" +
|
" $2commit(cache);" +
|
||||||
"},"
|
"},",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Add deleted=true to all target messages in the MESSAGE_DELETE_BULK event
|
// Add deleted=true to all target messages in the MESSAGE_DELETE_BULK event
|
||||||
match: /MESSAGE_DELETE_BULK:function\((\i)\){let.+?((?:\i\.){2})getOrCreate.+?},/,
|
match:
|
||||||
|
/MESSAGE_DELETE_BULK:function\((\i)\){let.+?((?:\i\.){2})getOrCreate.+?},/,
|
||||||
replace:
|
replace:
|
||||||
"MESSAGE_DELETE_BULK:function($1){" +
|
"MESSAGE_DELETE_BULK:function($1){" +
|
||||||
" var cache = $2getOrCreate($1.channelId);" +
|
" var cache = $2getOrCreate($1.channelId);" +
|
||||||
" cache = $self.handleDelete(cache, $1, true);" +
|
" cache = $self.handleDelete(cache, $1, true);" +
|
||||||
" $2commit(cache);" +
|
" $2commit(cache);" +
|
||||||
"},"
|
"},",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Add current cached content + new edit time to cached message's editHistory
|
// Add current cached content + new edit time to cached message's editHistory
|
||||||
match: /(MESSAGE_UPDATE:function\((\i)\).+?)\.update\((\i)/,
|
match: /(MESSAGE_UPDATE:function\((\i)\).+?)\.update\((\i)/,
|
||||||
replace: "$1" +
|
replace:
|
||||||
|
"$1" +
|
||||||
".update($3,m =>" +
|
".update($3,m =>" +
|
||||||
" (($2.message.flags & 64) === 64 || $self.shouldIgnore($2.message, true)) ? m :" +
|
" (($2.message.flags & 64) === 64 || $self.shouldIgnore($2.message, true)) ? m :" +
|
||||||
" $2.message.edited_timestamp && $2.message.content !== m.content ?" +
|
" $2.message.edited_timestamp && $2.message.content !== m.content ?" +
|
||||||
" m.set('editHistory',[...(m.editHistory || []), $self.makeEdit($2.message, m)]) :" +
|
" m.set('editHistory',[...(m.editHistory || []), $self.makeEdit($2.message, m)]) :" +
|
||||||
" m" +
|
" m" +
|
||||||
")" +
|
")" +
|
||||||
".update($3"
|
".update($3",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// fix up key (edit last message) attempting to edit a deleted message
|
// fix up key (edit last message) attempting to edit a deleted message
|
||||||
match: /(?<=getLastEditableMessage\(\i\)\{.{0,200}\.find\((\i)=>)/,
|
match: /(?<=getLastEditableMessage\(\i\)\{.{0,200}\.find\((\i)=>)/,
|
||||||
replace: "!$1.deleted &&"
|
replace: "!$1.deleted &&",
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -370,12 +438,13 @@ export default definePlugin({
|
||||||
replacement: [
|
replacement: [
|
||||||
{
|
{
|
||||||
match: /this\.customRenderedContent=(\i)\.customRenderedContent,/,
|
match: /this\.customRenderedContent=(\i)\.customRenderedContent,/,
|
||||||
replace: "this.customRenderedContent = $1.customRenderedContent," +
|
replace:
|
||||||
|
"this.customRenderedContent = $1.customRenderedContent," +
|
||||||
"this.deleted = $1.deleted || false," +
|
"this.deleted = $1.deleted || false," +
|
||||||
"this.editHistory = $1.editHistory || []," +
|
"this.editHistory = $1.editHistory || []," +
|
||||||
"this.firstEditTimestamp = $1.firstEditTimestamp || this.editedTimestamp || this.timestamp,"
|
"this.firstEditTimestamp = $1.firstEditTimestamp || this.editedTimestamp || this.timestamp,",
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -384,9 +453,10 @@ export default definePlugin({
|
||||||
replacement: [
|
replacement: [
|
||||||
{
|
{
|
||||||
// Pass through editHistory & deleted & original attachments to the "edited message" transformer
|
// Pass through editHistory & deleted & original attachments to the "edited message" transformer
|
||||||
match: /(?<=null!=\i\.edited_timestamp\)return )\i\(\i,\{reactions:(\i)\.reactions.{0,50}\}\)/,
|
match:
|
||||||
|
/(?<=null!=\i\.edited_timestamp\)return )\i\(\i,\{reactions:(\i)\.reactions.{0,50}\}\)/,
|
||||||
replace:
|
replace:
|
||||||
"Object.assign($&,{ deleted:$1.deleted, editHistory:$1.editHistory, firstEditTimestamp:$1.firstEditTimestamp })"
|
"Object.assign($&,{ deleted:$1.deleted, editHistory:$1.editHistory, firstEditTimestamp:$1.firstEditTimestamp })",
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -406,16 +476,14 @@ export default definePlugin({
|
||||||
"})())," +
|
"})())," +
|
||||||
"deleted: arguments[1]?.deleted," +
|
"deleted: arguments[1]?.deleted," +
|
||||||
"editHistory: arguments[1]?.editHistory," +
|
"editHistory: arguments[1]?.editHistory," +
|
||||||
"firstEditTimestamp: new Date(arguments[1]?.firstEditTimestamp ?? $2.editedTimestamp ?? $2.timestamp)"
|
"firstEditTimestamp: new Date(arguments[1]?.firstEditTimestamp ?? $2.editedTimestamp ?? $2.timestamp)",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Preserve deleted attribute on attachments
|
// Preserve deleted attribute on attachments
|
||||||
match: /(\((\i)\){return null==\2\.attachments.+?)spoiler:/,
|
match: /(\((\i)\){return null==\2\.attachments.+?)spoiler:/,
|
||||||
replace:
|
replace: "$1deleted: arguments[0]?.deleted," + "spoiler:",
|
||||||
"$1deleted: arguments[0]?.deleted," +
|
},
|
||||||
"spoiler:"
|
],
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -425,13 +493,13 @@ export default definePlugin({
|
||||||
replacement: [
|
replacement: [
|
||||||
{
|
{
|
||||||
match: /(className:\i,item:\i),/,
|
match: /(className:\i,item:\i),/,
|
||||||
replace: "$1,item: deleted,"
|
replace: "$1,item: deleted,",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
match: /\[\i\.obscured\]:.+?,/,
|
match: /\[\i\.obscured\]:.+?,/,
|
||||||
replace: "$& 'messagelogger-deleted-attachment': deleted,"
|
replace: "$& 'messagelogger-deleted-attachment': deleted,",
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -441,26 +509,28 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
// Append messagelogger-deleted to classNames if deleted
|
// Append messagelogger-deleted to classNames if deleted
|
||||||
match: /\)\("li",\{(.+?),className:/,
|
match: /\)\("li",\{(.+?),className:/,
|
||||||
replace: ")(\"li\",{$1,className:(arguments[0].message.deleted ? \"messagelogger-deleted \" : \"\")+"
|
replace:
|
||||||
}
|
')("li",{$1,className:(arguments[0].message.deleted ? "messagelogger-deleted " : "")+',
|
||||||
]
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
// Message content renderer
|
// Message content renderer
|
||||||
find: "Messages.MESSAGE_EDITED,\")\"",
|
find: 'Messages.MESSAGE_EDITED,")"',
|
||||||
replacement: [
|
replacement: [
|
||||||
{
|
{
|
||||||
// Render editHistory in the deepest div for message content
|
// Render editHistory in the deepest div for message content
|
||||||
match: /(\)\("div",\{id:.+?children:\[)/,
|
match: /(\)\("div",\{id:.+?children:\[)/,
|
||||||
replace: "$1 (!!arguments[0].message.editHistory?.length && $self.renderEdits(arguments[0])),"
|
replace:
|
||||||
|
"$1 (!!arguments[0].message.editHistory?.length && $self.renderEdits(arguments[0])),",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Make edit marker clickable
|
// Make edit marker clickable
|
||||||
match: /"span",\{(?=className:\i\.edited,)/,
|
match: /"span",\{(?=className:\i\.edited,)/,
|
||||||
replace: "$self.EditMarker,{message:arguments[0].message,"
|
replace: "$self.EditMarker,{message:arguments[0].message,",
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -469,13 +539,13 @@ export default definePlugin({
|
||||||
replacement: [
|
replacement: [
|
||||||
{
|
{
|
||||||
match: /MESSAGE_DELETE:function\((\i)\).+?},/,
|
match: /MESSAGE_DELETE:function\((\i)\).+?},/,
|
||||||
replace: "MESSAGE_DELETE:function($1){},"
|
replace: "MESSAGE_DELETE:function($1){},",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
match: /MESSAGE_DELETE_BULK:function\((\i)\).+?},/,
|
match: /MESSAGE_DELETE_BULK:function\((\i)\).+?},/,
|
||||||
replace: "MESSAGE_DELETE_BULK:function($1){},"
|
replace: "MESSAGE_DELETE_BULK:function($1){},",
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -485,9 +555,9 @@ export default definePlugin({
|
||||||
{
|
{
|
||||||
// Remove the first section if message is deleted
|
// Remove the first section if message is deleted
|
||||||
match: /children:(\[""===.+?\])/,
|
match: /children:(\[""===.+?\])/,
|
||||||
replace: "children:arguments[0].message.deleted?[]:$1"
|
replace: "children:arguments[0].message.deleted?[]:$1",
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Message grouping
|
// Message grouping
|
||||||
|
@ -496,7 +566,7 @@ export default definePlugin({
|
||||||
match: /if\((\i)\.blocked\)return \i\.\i\.MESSAGE_GROUP_BLOCKED;/,
|
match: /if\((\i)\.blocked\)return \i\.\i\.MESSAGE_GROUP_BLOCKED;/,
|
||||||
replace: '$&else if($1.deleted) return"MESSAGE_GROUP_DELETED";',
|
replace: '$&else if($1.deleted) return"MESSAGE_GROUP_DELETED";',
|
||||||
},
|
},
|
||||||
predicate: () => Settings.plugins.MessageLogger.collapseDeleted
|
predicate: () => Settings.plugins.MessageLogger.collapseDeleted,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Message group rendering
|
// Message group rendering
|
||||||
|
@ -508,10 +578,11 @@ export default definePlugin({
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
match: /(\i).type===\i\.\i\.MESSAGE_GROUP_BLOCKED\?.*?:/,
|
match: /(\i).type===\i\.\i\.MESSAGE_GROUP_BLOCKED\?.*?:/,
|
||||||
replace: '$&$1.type==="MESSAGE_GROUP_DELETED"?$self.Messages.DELETED_MESSAGE_COUNT:',
|
replace:
|
||||||
|
'$&$1.type==="MESSAGE_GROUP_DELETED"?$self.Messages.DELETED_MESSAGE_COUNT:',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
predicate: () => Settings.plugins.MessageLogger.collapseDeleted,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
predicate: () => Settings.plugins.MessageLogger.collapseDeleted
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue