1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-10 01:46:23 +00:00

migrate plugins

This commit is contained in:
Vendicated 2024-11-21 04:11:23 +01:00
parent f6803d0c55
commit 5da1c26163
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
13 changed files with 264 additions and 336 deletions

View file

@ -16,7 +16,6 @@
* 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 { addMessageAccessory } from "@api/MessageAccessories";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { getUserSettingLazy } from "@api/UserSettings"; import { getUserSettingLazy } from "@api/UserSettings";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
@ -235,6 +234,85 @@ export default definePlugin({
} }
}, },
renderMessageAccessory(props) {
const buttons = [] as JSX.Element[];
const shouldAddUpdateButton =
!IS_UPDATER_DISABLED
&& (
(props.channel.id === KNOWN_ISSUES_CHANNEL_ID) ||
(props.channel.id === SUPPORT_CHANNEL_ID && props.message.author.id === VENBOT_USER_ID)
)
&& props.message.content?.includes("update");
if (shouldAddUpdateButton) {
buttons.push(
<Button
key="vc-update"
color={Button.Colors.GREEN}
onClick={async () => {
try {
if (await forceUpdate())
showToast("Success! Restarting...", Toasts.Type.SUCCESS);
else
showToast("Already up to date!", Toasts.Type.MESSAGE);
} catch (e) {
new Logger(this.name).error("Error while updating:", e);
showToast("Failed to update :(", Toasts.Type.FAILURE);
}
}}
>
Update Now
</Button>
);
}
if (props.channel.id === SUPPORT_CHANNEL_ID) {
if (props.message.content.includes("/vencord-debug") || props.message.content.includes("/vencord-plugins")) {
buttons.push(
<Button
key="vc-dbg"
onClick={async () => sendMessage(props.channel.id, { content: await generateDebugInfoMessage() })}
>
Run /vencord-debug
</Button>,
<Button
key="vc-plg-list"
onClick={async () => sendMessage(props.channel.id, { content: generatePluginList() })}
>
Run /vencord-plugins
</Button>
);
}
if (props.message.author.id === VENBOT_USER_ID) {
const match = CodeBlockRe.exec(props.message.content || props.message.embeds[0]?.rawDescription || "");
if (match) {
buttons.push(
<Button
key="vc-run-snippet"
onClick={async () => {
try {
await AsyncFunction(match[1])();
showToast("Success!", Toasts.Type.SUCCESS);
} catch (e) {
new Logger(this.name).error("Error while running snippet:", e);
showToast("Failed to run snippet :(", Toasts.Type.FAILURE);
}
}}
>
Run Snippet
</Button>
);
}
}
}
return buttons.length
? <Flex>{buttons}</Flex>
: null;
},
renderContributorDmWarningCard: ErrorBoundary.wrap(({ channel }) => { renderContributorDmWarningCard: ErrorBoundary.wrap(({ channel }) => {
const userId = channel.getRecipientId(); const userId = channel.getRecipientId();
if (!isPluginDev(userId)) return null; if (!isPluginDev(userId)) return null;
@ -249,85 +327,4 @@ export default definePlugin({
</Card> </Card>
); );
}, { noop: true }), }, { noop: true }),
start() {
addMessageAccessory("vencord-debug", props => {
const buttons = [] as JSX.Element[];
const shouldAddUpdateButton =
!IS_UPDATER_DISABLED
&& (
(props.channel.id === KNOWN_ISSUES_CHANNEL_ID) ||
(props.channel.id === SUPPORT_CHANNEL_ID && props.message.author.id === VENBOT_USER_ID)
)
&& props.message.content?.includes("update");
if (shouldAddUpdateButton) {
buttons.push(
<Button
key="vc-update"
color={Button.Colors.GREEN}
onClick={async () => {
try {
if (await forceUpdate())
showToast("Success! Restarting...", Toasts.Type.SUCCESS);
else
showToast("Already up to date!", Toasts.Type.MESSAGE);
} catch (e) {
new Logger(this.name).error("Error while updating:", e);
showToast("Failed to update :(", Toasts.Type.FAILURE);
}
}}
>
Update Now
</Button>
);
}
if (props.channel.id === SUPPORT_CHANNEL_ID) {
if (props.message.content.includes("/vencord-debug") || props.message.content.includes("/vencord-plugins")) {
buttons.push(
<Button
key="vc-dbg"
onClick={async () => sendMessage(props.channel.id, { content: await generateDebugInfoMessage() })}
>
Run /vencord-debug
</Button>,
<Button
key="vc-plg-list"
onClick={async () => sendMessage(props.channel.id, { content: generatePluginList() })}
>
Run /vencord-plugins
</Button>
);
}
if (props.message.author.id === VENBOT_USER_ID) {
const match = CodeBlockRe.exec(props.message.content || props.message.embeds[0]?.rawDescription || "");
if (match) {
buttons.push(
<Button
key="vc-run-snippet"
onClick={async () => {
try {
await AsyncFunction(match[1])();
showToast("Success!", Toasts.Type.SUCCESS);
} catch (e) {
new Logger(this.name).error("Error while running snippet:", e);
showToast("Failed to run snippet :(", Toasts.Type.FAILURE);
}
}}
>
Run Snippet
</Button>
);
}
}
}
return buttons.length
? <Flex>{buttons}</Flex>
: null;
});
},
}); });

View file

@ -17,11 +17,7 @@
*/ */
import { import {
addPreEditListener, MessageObject
addPreSendListener,
MessageObject,
removePreEditListener,
removePreSendListener
} from "@api/MessageEvents"; } from "@api/MessageEvents";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
@ -36,7 +32,14 @@ export default definePlugin({
name: "ClearURLs", name: "ClearURLs",
description: "Removes tracking garbage from URLs", description: "Removes tracking garbage from URLs",
authors: [Devs.adryd], authors: [Devs.adryd],
dependencies: ["MessageEventsAPI"],
onBeforeMessageSend(_, msg) {
return this.onSend(msg);
},
onBeforeMessageEdit(_cid, _mid, msg) {
return this.onSend(msg);
},
escapeRegExp(str: string) { escapeRegExp(str: string) {
return (str && reHasRegExpChar.test(str)) return (str && reHasRegExpChar.test(str))
@ -133,17 +136,4 @@ export default definePlugin({
); );
} }
}, },
start() {
this.createRules();
this.preSend = addPreSendListener((_, msg) => this.onSend(msg));
this.preEdit = addPreEditListener((_cid, _mid, msg) =>
this.onSend(msg)
);
},
stop() {
removePreSendListener(this.preSend);
removePreEditListener(this.preEdit);
},
}); });

View file

@ -17,7 +17,6 @@
*/ */
import { get, set } from "@api/DataStore"; import { get, set } from "@api/DataStore";
import { addMessagePopoverButton, removeMessagePopoverButton } from "@api/MessagePopover";
import { ImageInvisible, ImageVisible } from "@components/Icons"; import { ImageInvisible, ImageVisible } from "@components/Icons";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
@ -38,7 +37,20 @@ export default definePlugin({
name: "HideAttachments", name: "HideAttachments",
description: "Hide attachments and Embeds for individual messages via hover button", description: "Hide attachments and Embeds for individual messages via hover button",
authors: [Devs.Ven], authors: [Devs.Ven],
dependencies: ["MessagePopoverAPI"],
renderMessagePopoverButton(msg) {
if (!msg.attachments.length && !msg.embeds.length && !msg.stickerItems.length) return null;
const isHidden = hiddenMessages.has(msg.id);
return {
label: isHidden ? "Show Attachments" : "Hide Attachments",
icon: isHidden ? ImageVisible : ImageInvisible,
message: msg,
channel: ChannelStore.getChannel(msg.channel_id),
onClick: () => this.toggleHide(msg.id)
};
},
async start() { async start() {
style = document.createElement("style"); style = document.createElement("style");
@ -47,26 +59,11 @@ export default definePlugin({
await getHiddenMessages(); await getHiddenMessages();
await this.buildCss(); await this.buildCss();
addMessagePopoverButton("HideAttachments", msg => {
if (!msg.attachments.length && !msg.embeds.length && !msg.stickerItems.length) return null;
const isHidden = hiddenMessages.has(msg.id);
return {
label: isHidden ? "Show Attachments" : "Hide Attachments",
icon: isHidden ? ImageVisible : ImageInvisible,
message: msg,
channel: ChannelStore.getChannel(msg.channel_id),
onClick: () => this.toggleHide(msg.id)
};
});
}, },
stop() { stop() {
style.remove(); style.remove();
hiddenMessages.clear(); hiddenMessages.clear();
removeMessagePopoverButton("HideAttachments");
}, },
async buildCss() { async buildCss() {

View file

@ -16,8 +16,7 @@
* 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 { addChatBarButton, ChatBarButton, ChatBarButtonFactory } from "@api/ChatButtons"; import { ChatBarButton, ChatBarButtonFactory } from "@api/ChatButtons";
import { addMessagePopoverButton, removeMessagePopoverButton } from "@api/MessagePopover";
import { updateMessage } from "@api/MessageUpdater"; import { updateMessage } from "@api/MessageUpdater";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
@ -104,7 +103,7 @@ export default definePlugin({
name: "InvisibleChat", name: "InvisibleChat",
description: "Encrypt your Messages in a non-suspicious way!", description: "Encrypt your Messages in a non-suspicious way!",
authors: [Devs.SammCheese], authors: [Devs.SammCheese],
dependencies: ["MessagePopoverAPI", "ChatInputButtonAPI", "MessageUpdaterAPI"], dependencies: ["MessageUpdaterAPI"],
reporterTestable: ReporterTestable.Patches, reporterTestable: ReporterTestable.Patches,
settings, settings,
@ -125,36 +124,31 @@ export default definePlugin({
/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/, /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/,
), ),
async start() { async start() {
addMessagePopoverButton("InvisibleChat", message => {
return this.INV_REGEX.test(message?.content)
? {
label: "Decrypt Message",
icon: this.popOverIcon,
message: message,
channel: ChannelStore.getChannel(message.channel_id),
onClick: async () => {
const res = await iteratePasswords(message);
if (res)
this.buildEmbed(message, res);
else
buildDecModal({ message });
}
}
: null;
});
addChatBarButton("InvisibleChat", ChatBarIcon);
const { default: StegCloak } = await getStegCloak(); const { default: StegCloak } = await getStegCloak();
steggo = new StegCloak(true, false); steggo = new StegCloak(true, false);
}, },
stop() { renderMessagePopoverButton(message) {
removeMessagePopoverButton("InvisibleChat"); return this.INV_REGEX.test(message?.content)
removeMessagePopoverButton("InvisibleChat"); ? {
label: "Decrypt Message",
icon: this.popOverIcon,
message: message,
channel: ChannelStore.getChannel(message.channel_id),
onClick: async () => {
const res = await iteratePasswords(message);
if (res)
this.buildEmbed(message, res);
else
buildDecModal({ message });
}
}
: null;
}, },
renderChatBarButton: ChatBarIcon,
// Gets the Embed of a Link // Gets the Embed of a Link
async getEmbed(url: URL): Promise<Object | {}> { async getEmbed(url: URL): Promise<Object | {}> {
const { body } = await RestAPI.post({ const { body } = await RestAPI.post({

View file

@ -16,7 +16,6 @@
* 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 { addMessageClickListener, removeMessageClickListener } from "@api/MessageEvents";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
@ -57,66 +56,64 @@ export default definePlugin({
name: "MessageClickActions", name: "MessageClickActions",
description: "Hold Backspace and click to delete, double click to edit/reply", description: "Hold Backspace and click to delete, double click to edit/reply",
authors: [Devs.Ven], authors: [Devs.Ven],
dependencies: ["MessageEventsAPI"],
settings, settings,
start() { start() {
document.addEventListener("keydown", keydown); document.addEventListener("keydown", keydown);
document.addEventListener("keyup", keyup); document.addEventListener("keyup", keyup);
this.onClick = addMessageClickListener((msg: any, channel, event) => {
const isMe = msg.author.id === UserStore.getCurrentUser().id;
if (!isDeletePressed) {
if (event.detail < 2) return;
if (settings.store.requireModifier && !event.ctrlKey && !event.shiftKey) return;
if (channel.guild_id && !PermissionStore.can(PermissionsBits.SEND_MESSAGES, channel)) return;
if (msg.deleted === true) return;
if (isMe) {
if (!settings.store.enableDoubleClickToEdit || EditStore.isEditing(channel.id, msg.id) || msg.state !== "SENT") return;
MessageActions.startEditMessage(channel.id, msg.id, msg.content);
event.preventDefault();
} else {
if (!settings.store.enableDoubleClickToReply) return;
const EPHEMERAL = 64;
if (msg.hasFlag(EPHEMERAL)) return;
const isShiftPress = event.shiftKey && !settings.store.requireModifier;
const NoReplyMention = Vencord.Plugins.plugins.NoReplyMention as any as typeof import("../noReplyMention").default;
const shouldMention = Vencord.Plugins.isPluginEnabled("NoReplyMention")
? NoReplyMention.shouldMention(msg, isShiftPress)
: !isShiftPress;
FluxDispatcher.dispatch({
type: "CREATE_PENDING_REPLY",
channel,
message: msg,
shouldMention,
showMentionToggle: channel.guild_id !== null
});
}
} else if (settings.store.enableDeleteOnClick && (isMe || PermissionStore.can(PermissionsBits.MANAGE_MESSAGES, channel))) {
if (msg.deleted) {
FluxDispatcher.dispatch({
type: "MESSAGE_DELETE",
channelId: channel.id,
id: msg.id,
mlDeleted: true
});
} else {
MessageActions.deleteMessage(channel.id, msg.id);
}
event.preventDefault();
}
});
}, },
stop() { stop() {
removeMessageClickListener(this.onClick);
document.removeEventListener("keydown", keydown); document.removeEventListener("keydown", keydown);
document.removeEventListener("keyup", keyup); document.removeEventListener("keyup", keyup);
} },
onMessageClick(msg: any, channel, event) {
const isMe = msg.author.id === UserStore.getCurrentUser().id;
if (!isDeletePressed) {
if (event.detail < 2) return;
if (settings.store.requireModifier && !event.ctrlKey && !event.shiftKey) return;
if (channel.guild_id && !PermissionStore.can(PermissionsBits.SEND_MESSAGES, channel)) return;
if (msg.deleted === true) return;
if (isMe) {
if (!settings.store.enableDoubleClickToEdit || EditStore.isEditing(channel.id, msg.id) || msg.state !== "SENT") return;
MessageActions.startEditMessage(channel.id, msg.id, msg.content);
event.preventDefault();
} else {
if (!settings.store.enableDoubleClickToReply) return;
const EPHEMERAL = 64;
if (msg.hasFlag(EPHEMERAL)) return;
const isShiftPress = event.shiftKey && !settings.store.requireModifier;
const NoReplyMention = Vencord.Plugins.plugins.NoReplyMention as any as typeof import("../noReplyMention").default;
const shouldMention = Vencord.Plugins.isPluginEnabled("NoReplyMention")
? NoReplyMention.shouldMention(msg, isShiftPress)
: !isShiftPress;
FluxDispatcher.dispatch({
type: "CREATE_PENDING_REPLY",
channel,
message: msg,
shouldMention,
showMentionToggle: channel.guild_id !== null
});
}
} else if (settings.store.enableDeleteOnClick && (isMe || PermissionStore.can(PermissionsBits.MANAGE_MESSAGES, channel))) {
if (msg.deleted) {
FluxDispatcher.dispatch({
type: "MESSAGE_DELETE",
channelId: channel.id,
id: msg.id,
mlDeleted: true
});
} else {
MessageActions.deleteMessage(channel.id, msg.id);
}
event.preventDefault();
}
},
}); });

View file

@ -16,7 +16,6 @@
* 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 { addMessagePopoverButton, removeMessagePopoverButton } from "@api/MessagePopover";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { insertTextIntoChatInputBox } from "@utils/discord"; import { insertTextIntoChatInputBox } from "@utils/discord";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
@ -26,24 +25,18 @@ export default definePlugin({
name: "QuickMention", name: "QuickMention",
authors: [Devs.kemo], authors: [Devs.kemo],
description: "Adds a quick mention button to the message actions bar", description: "Adds a quick mention button to the message actions bar",
dependencies: ["MessagePopoverAPI"],
start() { renderMessagePopoverButton(msg) {
addMessagePopoverButton("QuickMention", msg => { const channel = ChannelStore.getChannel(msg.channel_id);
const channel = ChannelStore.getChannel(msg.channel_id); if (channel.guild_id && !PermissionStore.can(PermissionsBits.SEND_MESSAGES, channel)) return null;
if (channel.guild_id && !PermissionStore.can(PermissionsBits.SEND_MESSAGES, channel)) return null;
return { return {
label: "Quick Mention", label: "Quick Mention",
icon: this.Icon, icon: this.Icon,
message: msg, message: msg,
channel, channel,
onClick: () => insertTextIntoChatInputBox(`<@${msg.author.id}> `) onClick: () => insertTextIntoChatInputBox(`<@${msg.author.id}> `)
}; };
});
},
stop() {
removeMessagePopoverButton("QuickMention");
}, },
Icon: () => ( Icon: () => (

View file

@ -18,8 +18,7 @@
import "./styles.css"; import "./styles.css";
import { addChatBarButton, ChatBarButton, ChatBarButtonFactory, removeChatBarButton } from "@api/ChatButtons"; import { ChatBarButton, ChatBarButtonFactory } from "@api/ChatButtons";
import { addPreSendListener, removePreSendListener } from "@api/MessageEvents";
import { definePluginSettings } from "@api/Settings"; 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";
@ -160,22 +159,14 @@ 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, Devs.Grzesiek11], authors: [Devs.Ven, Devs.Tyler, Devs.Grzesiek11],
dependencies: ["MessageEventsAPI", "ChatInputButtonAPI"],
settings, settings,
start() { renderChatBarButton: ChatBarIcon,
addChatBarButton("SendTimestamps", ChatBarIcon);
this.listener = addPreSendListener((_, msg) => {
if (settings.store.replaceMessageContents) {
msg.content = msg.content.replace(/`\d{1,2}:\d{2} ?(?:AM|PM)?`/gi, parseTime);
}
});
},
stop() { onBeforeMessageSend(_, msg) {
removeChatBarButton("SendTimestamps"); if (settings.store.replaceMessageContents) {
removePreSendListener(this.listener); msg.content = msg.content.replace(/`\d{1,2}:\d{2} ?(?:AM|PM)?`/gi, parseTime);
}
}, },
settingsAboutComponent() { settingsAboutComponent() {

View file

@ -16,7 +16,7 @@
* 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 { addChatBarButton, ChatBarButton, ChatBarButtonFactory, removeChatBarButton } from "@api/ChatButtons"; import { ChatBarButton, ChatBarButtonFactory } from "@api/ChatButtons";
import { addPreSendListener, MessageSendListener, removePreSendListener } from "@api/MessageEvents"; import { addPreSendListener, MessageSendListener, removePreSendListener } from "@api/MessageEvents";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
@ -91,9 +91,7 @@ export default definePlugin({
name: "SilentMessageToggle", name: "SilentMessageToggle",
authors: [Devs.Nuckyz, Devs.CatNoir], authors: [Devs.Nuckyz, Devs.CatNoir],
description: "Adds a button to the chat bar to toggle sending a silent message.", description: "Adds a button to the chat bar to toggle sending a silent message.",
dependencies: ["MessageEventsAPI", "ChatInputButtonAPI"],
settings, settings,
start: () => addChatBarButton("SilentMessageToggle", SilentMessageToggle), renderChatBarButton: SilentMessageToggle,
stop: () => removeChatBarButton("SilentMessageToggle")
}); });

View file

@ -16,7 +16,7 @@
* 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 { addChatBarButton, ChatBarButton, ChatBarButtonFactory, removeChatBarButton } from "@api/ChatButtons"; import { ChatBarButton, ChatBarButtonFactory } from "@api/ChatButtons";
import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands";
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu"; import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
@ -88,11 +88,12 @@ export default definePlugin({
name: "SilentTyping", name: "SilentTyping",
authors: [Devs.Ven, Devs.Rini, Devs.ImBanana], authors: [Devs.Ven, Devs.Rini, Devs.ImBanana],
description: "Hide that you are typing", description: "Hide that you are typing",
dependencies: ["ChatInputButtonAPI"],
settings, settings,
contextMenus: { contextMenus: {
"textarea-context": ChatBarContextCheckbox "textarea-context": ChatBarContextCheckbox
}, },
patches: [ patches: [
{ {
find: '.dispatch({type:"TYPING_START_LOCAL"', find: '.dispatch({type:"TYPING_START_LOCAL"',
@ -128,6 +129,5 @@ export default definePlugin({
FluxDispatcher.dispatch({ type: "TYPING_START_LOCAL", channelId }); FluxDispatcher.dispatch({ type: "TYPING_START_LOCAL", channelId });
}, },
start: () => addChatBarButton("SilentTyping", SilentTypingToggle), renderChatBarButton: SilentTypingToggle,
stop: () => removeChatBarButton("SilentTyping"),
}); });

View file

@ -17,7 +17,6 @@
*/ */
import { DataStore } from "@api/index"; import { DataStore } from "@api/index";
import { addPreSendListener, removePreSendListener } from "@api/MessageEvents";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { Flex } from "@components/Flex"; import { Flex } from "@components/Flex";
import { DeleteIcon } from "@components/Icons"; import { DeleteIcon } from "@components/Icons";
@ -244,22 +243,17 @@ export default definePlugin({
name: "TextReplace", name: "TextReplace",
description: "Replace text in your messages. You can find pre-made rules in the #textreplace-rules channel in Vencord's Server", description: "Replace text in your messages. You can find pre-made rules in the #textreplace-rules channel in Vencord's Server",
authors: [Devs.AutumnVN, Devs.TheKodeToad], authors: [Devs.AutumnVN, Devs.TheKodeToad],
dependencies: ["MessageEventsAPI"],
settings, settings,
onBeforeMessageSend(channelId, msg) {
// Channel used for sharing rules, applying rules here would be messy
if (channelId === TEXT_REPLACE_RULES_CHANNEL_ID) return;
msg.content = applyRules(msg.content);
},
async start() { async start() {
stringRules = await DataStore.get(STRING_RULES_KEY) ?? makeEmptyRuleArray(); stringRules = await DataStore.get(STRING_RULES_KEY) ?? makeEmptyRuleArray();
regexRules = await DataStore.get(REGEX_RULES_KEY) ?? makeEmptyRuleArray(); regexRules = await DataStore.get(REGEX_RULES_KEY) ?? makeEmptyRuleArray();
this.preSend = addPreSendListener((channelId, msg) => {
// Channel used for sharing rules, applying rules here would be messy
if (channelId === TEXT_REPLACE_RULES_CHANNEL_ID) return;
msg.content = applyRules(msg.content);
});
},
stop() {
removePreSendListener(this.preSend);
} }
}); });

View file

@ -18,11 +18,7 @@
import "./styles.css"; import "./styles.css";
import { addChatBarButton, removeChatBarButton } from "@api/ChatButtons";
import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu"; import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu";
import { addMessageAccessory, removeMessageAccessory } from "@api/MessageAccessories";
import { addPreSendListener, removePreSendListener } from "@api/MessageEvents";
import { addMessagePopoverButton, removeMessagePopoverButton } from "@api/MessagePopover";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { ChannelStore, Menu } from "@webpack/common"; import { ChannelStore, Menu } from "@webpack/common";
@ -51,11 +47,12 @@ const messageCtxPatch: NavContextMenuPatchCallback = (children, { message }) =>
)); ));
}; };
let tooltipTimeout: any;
export default definePlugin({ export default definePlugin({
name: "Translate", name: "Translate",
description: "Translate messages with Google Translate or DeepL", description: "Translate messages with Google Translate or DeepL",
authors: [Devs.Ven, Devs.AshtonMemer], authors: [Devs.Ven, Devs.AshtonMemer],
dependencies: ["MessageAccessoriesAPI", "MessagePopoverAPI", "MessageEventsAPI", "ChatInputButtonAPI"],
settings, settings,
contextMenus: { contextMenus: {
"message": messageCtxPatch "message": messageCtxPatch
@ -63,45 +60,34 @@ export default definePlugin({
// not used, just here in case some other plugin wants it or w/e // not used, just here in case some other plugin wants it or w/e
translate, translate,
start() { renderMessageAccessory: props => <TranslationAccessory message={props.message} />,
addMessageAccessory("vc-translation", props => <TranslationAccessory message={props.message} />);
addChatBarButton("vc-translate", TranslateChatBarIcon); renderChatBarButton: TranslateChatBarIcon,
addMessagePopoverButton("vc-translate", message => { renderMessagePopoverButton(message) {
if (!message.content) return null; if (!message.content) return null;
return { return {
label: "Translate", label: "Translate",
icon: TranslateIcon, icon: TranslateIcon,
message, message,
channel: ChannelStore.getChannel(message.channel_id), channel: ChannelStore.getChannel(message.channel_id),
onClick: async () => { onClick: async () => {
const trans = await translate("received", message.content); const trans = await translate("received", message.content);
handleTranslate(message.id, trans); handleTranslate(message.id, trans);
} }
}; };
});
let tooltipTimeout: any;
this.preSend = addPreSendListener(async (_, message) => {
if (!settings.store.autoTranslate) return;
if (!message.content) return;
setShouldShowTranslateEnabledTooltip?.(true);
clearTimeout(tooltipTimeout);
tooltipTimeout = setTimeout(() => setShouldShowTranslateEnabledTooltip?.(false), 2000);
const trans = await translate("sent", message.content);
message.content = trans.text;
});
}, },
stop() { async onBeforeMessageSend(_, message) {
removePreSendListener(this.preSend); if (!settings.store.autoTranslate) return;
removeChatBarButton("vc-translate"); if (!message.content) return;
removeMessagePopoverButton("vc-translate");
removeMessageAccessory("vc-translation"); setShouldShowTranslateEnabledTooltip?.(true);
}, clearTimeout(tooltipTimeout);
tooltipTimeout = setTimeout(() => setShouldShowTranslateEnabledTooltip?.(false), 2000);
const trans = await translate("sent", message.content);
message.content = trans.text;
}
}); });

View file

@ -16,7 +16,7 @@
* 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 { addPreEditListener, addPreSendListener, MessageObject, removePreEditListener, removePreSendListener } from "@api/MessageEvents"; import { MessageObject } from "@api/MessageEvents";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
@ -24,7 +24,7 @@ export default definePlugin({
name: "Unindent", name: "Unindent",
description: "Trims leading indentation from codeblocks", description: "Trims leading indentation from codeblocks",
authors: [Devs.Ven], authors: [Devs.Ven],
dependencies: ["MessageEventsAPI"],
patches: [ patches: [
{ {
find: "inQuote:", find: "inQuote:",
@ -55,13 +55,11 @@ export default definePlugin({
}); });
}, },
start() { onBeforeMessageSend(_, msg) {
this.preSend = addPreSendListener((_, msg) => this.unindentMsg(msg)); return this.unindentMsg(msg);
this.preEdit = addPreEditListener((_cid, _mid, msg) => this.unindentMsg(msg));
}, },
stop() { onBeforeMessageEdit(_cid, _mid, msg) {
removePreSendListener(this.preSend); return this.unindentMsg(msg);
removePreEditListener(this.preEdit);
} }
}); });

View file

@ -17,7 +17,6 @@
*/ */
import { NavContextMenuPatchCallback } from "@api/ContextMenu"; import { NavContextMenuPatchCallback } from "@api/ContextMenu";
import { addMessagePopoverButton, removeMessagePopoverButton } from "@api/MessagePopover";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { CodeBlock } from "@components/CodeBlock"; import { CodeBlock } from "@components/CodeBlock";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
@ -149,8 +148,8 @@ export default definePlugin({
name: "ViewRaw", name: "ViewRaw",
description: "Copy and view the raw content/data of any message, channel or guild", description: "Copy and view the raw content/data of any message, channel or guild",
authors: [Devs.KingFish, Devs.Ven, Devs.rad, Devs.ImLvna], authors: [Devs.KingFish, Devs.Ven, Devs.rad, Devs.ImLvna],
dependencies: ["MessagePopoverAPI"],
settings, settings,
contextMenus: { contextMenus: {
"guild-context": MakeContextCallback("Guild"), "guild-context": MakeContextCallback("Guild"),
"channel-context": MakeContextCallback("Channel"), "channel-context": MakeContextCallback("Channel"),
@ -159,44 +158,38 @@ export default definePlugin({
"user-context": MakeContextCallback("User") "user-context": MakeContextCallback("User")
}, },
start() { renderMessagePopoverButton(msg) {
addMessagePopoverButton("ViewRaw", msg => { const handleClick = () => {
const handleClick = () => { if (settings.store.clickMethod === "Right") {
if (settings.store.clickMethod === "Right") { copyWithToast(msg.content);
copyWithToast(msg.content); } else {
} else { openViewRawModalMessage(msg);
openViewRawModalMessage(msg); }
} };
};
const handleContextMenu = e => { const handleContextMenu = e => {
if (settings.store.clickMethod === "Left") { if (settings.store.clickMethod === "Left") {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
copyWithToast(msg.content); copyWithToast(msg.content);
} else { } else {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
openViewRawModalMessage(msg); openViewRawModalMessage(msg);
} }
}; };
const label = settings.store.clickMethod === "Right" const label = settings.store.clickMethod === "Right"
? "Copy Raw (Left Click) / View Raw (Right Click)" ? "Copy Raw (Left Click) / View Raw (Right Click)"
: "View Raw (Left Click) / Copy Raw (Right Click)"; : "View Raw (Left Click) / Copy Raw (Right Click)";
return { return {
label, label,
icon: CopyIcon, icon: CopyIcon,
message: msg, message: msg,
channel: ChannelStore.getChannel(msg.channel_id), channel: ChannelStore.getChannel(msg.channel_id),
onClick: handleClick, onClick: handleClick,
onContextMenu: handleContextMenu onContextMenu: handleContextMenu
}; };
});
},
stop() {
removeMessagePopoverButton("ViewRaw");
} }
}); });