Skip to content

Commit

Permalink
update Message module search
Browse files Browse the repository at this point in the history
the coremod now loads asynchronously & will not log an error if the message module isn't found
(it will just never load)
  • Loading branch information
Penguin-Spy committed Jan 12, 2025
1 parent bc46562 commit cfb0d34
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/renderer/coremods/utilityClasses/index.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injector } from "@replugged";
import { getByProps, getByStoreName } from "src/renderer/modules/webpack";
import { filters, getByProps, getByStoreName, waitForModule } from "src/renderer/modules/webpack";
import { users } from "@common";
import type React from "react";
import type { Store } from "src/renderer/modules/common/flux";
Expand Down Expand Up @@ -70,19 +70,14 @@ function nitroThemeClass(): void {
onNitroThemeChange(ClientThemesBackgroundStore, ThemeIDMap);
}

function messageDataAttributes(): void {
const Message = getByProps<{
default: { type: (msg: { message: Message }) => React.ReactElement };
getElementFromMessage: unknown;
}>("getElementFromMessage");
async function messageDataAttributes(): Promise<void> {
const Message = await waitForModule<{
ZP: { type: (msg: { message: Message }) => React.ReactElement };
}>(filters.bySource(/channel:{id:\w},compact:\w=!1,/i));

if (!Message) {
throw new Error("Failed to find Message module!");
}

inject.after(Message.default, "type", ([{ message }], res) => {
const props = res.props?.children?.props?.children?.props;
if (!props) return;
inject.after(Message.ZP, "type", ([{ message }], res) => {
const props = res.props?.children?.props?.children?.[1]?.props;
if (!props) return res;
props["data-is-author-self"] = message.author.id === users.getCurrentUser().id;
props["data-is-author-bot"] = message.author.bot;
// webhooks are also considered bots
Expand All @@ -104,10 +99,10 @@ function addHtmlClasses(): void {

let observer: MutationObserver;

export function start(): void {
export async function start(): Promise<void> {
tabBarItemId();
nitroThemeClass();
messageDataAttributes();
await messageDataAttributes();

// generic stuff
observer = new MutationObserver(addHtmlClasses);
Expand Down

0 comments on commit cfb0d34

Please sign in to comment.