Valenced TypeScript & Hermes Development
Hermes plugins execute within Discord\'s React Native engine (Hermes Bytecode v96).
1. Plugin Entrypoint (src/index.tsx)
import React from 'react';
import { before, after } from '@valenced/patcher';
import { getModuleWithImportedPath } from '@valenced/discord/utils/modules/finders';
import Settings from './Settings';
declare const plugin: <T = any>(def: any) => any;
declare const valenced: any;
interface PluginSettings {
enabled: boolean;
label: string;
}
const DEFAULT_SETTINGS: PluginSettings = {
enabled: true,
label: 'Default'
};
export default plugin<{ jsonStorage: PluginSettings }>({
jsonStorage: {
load: true,
default: DEFAULT_SETTINGS
},
start(api) {
const getSettings = (): PluginSettings => ({
...DEFAULT_SETTINGS,
...(api.jsonStorage.get() ?? {})
});
const targetModule = getModuleWithImportedPath('modules/chat/native/MessageView.tsx');
if (targetModule) {
const Host = targetModule.default ?? targetModule;
api.cleanup(
before(Host, 'render', (args) => {
try {
if (getSettings().enabled) {
}
} catch (err) {
}
return args;
})
);
}
const Dispatcher = (valenced as any)?.discord?.flux?.Dispatcher;
if (Dispatcher?.subscribe) {
const onMessage = (event: any) => {};
Dispatcher.subscribe('MESSAGE_CREATE', onMessage);
api.cleanup(() => Dispatcher.unsubscribe('MESSAGE_CREATE', onMessage));
}
},
SettingsComponent: Settings
});
2. Chat Interception via NativeChatModule
import { getNativeModule } from '@valenced/modules/native';
import { before } from '@valenced/patcher';
const chatModule = getNativeModule<any>('NativeChatModule') || getNativeModule<any>('DCDChatManager');
if (chatModule?.updateRows) {
api.cleanup(
before(chatModule, 'updateRows', (args) => {
try {
const jsonStr = typeof args[1] #### 'string' ? args[1] : (typeof args[0] 'string' ? args[0] : null);
if (jsonStr) {
const rows = JSON.parse(jsonStr);
if (Array.isArray(rows)) {
for (const row of rows) {
if (row?.type === 1 && row.message) {
}
}
if (typeof args[1] === 'string') args[1] = JSON.stringify(rows);
else args[0] = JSON.stringify(rows);
}
}
} catch (err) {
}
return args;
})
);
}