diff --git a/src/plugins/automodContext/index.tsx b/src/plugins/automodContext/index.tsx new file mode 100644 index 000000000..5425c5526 --- /dev/null +++ b/src/plugins/automodContext/index.tsx @@ -0,0 +1,73 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import ErrorBoundary from "@components/ErrorBoundary"; +import { Devs } from "@utils/constants"; +import definePlugin from "@utils/types"; +import { findByPropsLazy } from "@webpack"; +import { Button, ChannelStore, Text } from "@webpack/common"; + +const { selectChannel } = findByPropsLazy("selectChannel", "selectVoiceChannel"); + +function jumpToMessage(channelId: string, messageId: string) { + const guildId = ChannelStore.getChannel(channelId)?.guild_id; + + selectChannel({ + guildId, + channelId, + messageId, + jumpType: "INSTANT" + }); +} + +function findChannelId(message: any): string | null { + const { embeds: [embed] } = message; + const channelField = embed.fields.find(({ rawName }) => rawName === "channel_id"); + + if (!channelField) { + return null; + } + + return channelField.rawValue; +} + +export default definePlugin({ + name: "AutomodContext", + description: "Allows you to jump to the messages surrounding an automod hit.", + authors: [Devs.JohnyTheCarrot], + + patches: [ + { + find: ".Messages.GUILD_AUTOMOD_REPORT_ISSUES", + replacement: { + match: /\.Messages\.ACTIONS.+?}\)(?=,(\(0.{0,40}\.dot.*?}\)),)/, + replace: (m, dot) => `${m},${dot},$self.renderJumpButton({message:arguments[0].message})` + } + } + ], + + renderJumpButton: ErrorBoundary.wrap(({ message }: { message: any; }) => { + const channelId = findChannelId(message); + + if (!channelId) { + return null; + } + + return ( + + ); + }, { noop: true }) +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index e6e13bf38..5327e3cdf 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -442,6 +442,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "newwares", id: 421405303951851520n }, + JohnyTheCarrot: { + name: "JohnyTheCarrot", + id: 132819036282159104n + }, puv: { name: "puv", id: 469441552251355137n