diff --git a/client/src/builtin/24Hour.js b/client/src/builtin/24Hour.js index 49aec6f2..1fc794c1 100644 --- a/client/src/builtin/24Hour.js +++ b/client/src/builtin/24Hour.js @@ -9,7 +9,7 @@ */ import BuiltinModule from './BuiltinModule'; -import { Patcher, MonkeyPatch, WebpackModules, ReactComponents } from 'modules'; +import { Patcher, MonkeyPatch, Reflection, ReactComponents } from 'modules'; const twelveHour = new RegExp(`([0-9]{1,2}):([0-9]{1,2})\\s(AM|PM)`); @@ -21,7 +21,7 @@ export default new class TwentyFourHour extends BuiltinModule { async enabled(e) { if (Patcher.getPatchesByCaller('BD:TwentyFourHour').length) return; - const TimeFormatter = WebpackModules.getModuleByName('TimeFormatter'); + const { TimeFormatter } = Reflection.modules; MonkeyPatch('BD:TwentyFourHour', TimeFormatter).after('calendarFormat', (thisObject, args, returnValue) => { const matched = returnValue.match(twelveHour); if (!matched || matched.length != 4) return; diff --git a/client/src/builtin/BlockedMessages.js b/client/src/builtin/BlockedMessages.js index 961790fb..4431119e 100644 --- a/client/src/builtin/BlockedMessages.js +++ b/client/src/builtin/BlockedMessages.js @@ -9,7 +9,7 @@ */ import BuiltinModule from './BuiltinModule'; -import { Patcher, MonkeyPatch, WebpackModules, ReactComponents } from 'modules'; +import { Patcher, MonkeyPatch, Reflection, ReactComponents } from 'modules'; export default new class BlockedMessages extends BuiltinModule { @@ -18,16 +18,16 @@ export default new class BlockedMessages extends BuiltinModule { } static isBlocked(id) { - const RelationshipStore = WebpackModules.getModuleByName('RelationshipStore'); + const { RelationshipStore } = Reflection.modules; return RelationshipStore.isBlocked(id); } async enabled(e) { if (Patcher.getPatchesByCaller('BD:BlockedMessages').length) return; - const MessageActions = WebpackModules.getModuleByName('MessageActions'); + const { MessageActions } = Reflection.modules; MonkeyPatch('BD:BlockedMessages', MessageActions).instead('receiveMessage', this.processMessage); - const MessageListComponents = WebpackModules.getModuleByProps(['BlockedMessageGroup']); + const MessageListComponents = Reflection.module.byProps('BlockedMessageGroup'); MessageListComponents.OriginalBlockedMessageGroup = MessageListComponents.BlockedMessageGroup; MessageListComponents.BlockedMessageGroup = () => {return null;}; this.cancelBlockedMessages = () => { diff --git a/client/src/builtin/ColoredText.js b/client/src/builtin/ColoredText.js index ff1e8aa0..4c315cd3 100644 --- a/client/src/builtin/ColoredText.js +++ b/client/src/builtin/ColoredText.js @@ -11,7 +11,7 @@ import BuiltinModule from './BuiltinModule'; import { Utils } from 'common'; -import { Settings, Patcher, MonkeyPatch, WebpackModules, ReactComponents, DiscordApi } from 'modules'; +import { Settings, Patcher, MonkeyPatch, Reflection, ReactComponents, DiscordApi } from 'modules'; export default new class ColoredText extends BuiltinModule { @@ -44,13 +44,13 @@ export default new class ColoredText extends BuiltinModule { async enabled(e) { if (Patcher.getPatchesByCaller('BD:ColoredText').length) return; this.intensitySetting.on('setting-updated', this._intensityUpdated); - this.MessageContent = await ReactComponents.getComponent('MessageContent', { selector: WebpackModules.getSelector('container', 'containerCozy', 'containerCompact', 'edited') }); + this.MessageContent = await ReactComponents.getComponent('MessageContent', { selector: Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited').selector }); MonkeyPatch('BD:ColoredText', this.MessageContent.component.prototype).after('render', this.injectColoredText); this.MessageContent.forceUpdateAll(); } injectColoredText(thisObject, args, returnValue) { - const TinyColor = WebpackModules.getModuleByName('TinyColor'); + const { TinyColor } = Reflection.modules; const markup = Utils.findInReactTree(returnValue, m => m && m.props && m.props.className && m.props.className.includes('da-markup')); const roleColor = thisObject.props.message.colorString; if (markup && roleColor) markup.props.style = {color: TinyColor.mix(roleColor, this.defaultColor, this.intensity)}; diff --git a/client/src/builtin/E2EE.js b/client/src/builtin/E2EE.js index 34b184f8..07f426c6 100644 --- a/client/src/builtin/E2EE.js +++ b/client/src/builtin/E2EE.js @@ -10,8 +10,8 @@ import { Settings, Cache, Events } from 'modules'; import BuiltinModule from './BuiltinModule'; -import { WebpackModules, ReactComponents, MonkeyPatch, Patcher, DiscordApi, Security } from 'modules'; -import { VueInjector, Reflection, Modals, Toasts } from 'ui'; +import { Reflection, ReactComponents, MonkeyPatch, Patcher, DiscordApi, Security } from 'modules'; +import { VueInjector, Modals, Toasts } from 'ui'; import { ClientLogger as Logger, ClientIPC } from 'common'; import { request } from 'vendor'; import { Utils } from 'common'; @@ -45,8 +45,7 @@ export default new class E2EE extends BuiltinModule { Events.on('discord:MESSAGE_CREATE', this.handlePublicKey); this.patchDispatcher(); this.patchMessageContent(); - const selector = `.${WebpackModules.getClassName('channelTextArea', 'emojiButton')}`; - const cta = await ReactComponents.getComponent('ChannelTextArea', { selector }); + const cta = await ReactComponents.getComponent('ChannelTextArea', { selector: Reflection.resolve('channelTextArea', 'emojiButton').selector }); this.patchChannelTextArea(cta); this.patchChannelTextAreaSubmit(cta); cta.forceUpdateAll(); @@ -188,7 +187,7 @@ export default new class E2EE extends BuiltinModule { if (!ECDH_STORAGE.hasOwnProperty(channelId)) { const publicKeyMessage = `\`\`\`\n-----BEGIN PUBLIC KEY-----\n${this.createKeyExchange(channelId)}\n-----END PUBLIC KEY-----\n\`\`\``; if (this.encryptNewMessages) this.encryptNewMessages = false; - WebpackModules.getModuleByName('DraftActions').saveDraft(channelId, publicKeyMessage); + Reflection.modules.DraftActions.saveDraft(channelId, publicKeyMessage); } const secret = this.computeSecret(channelId, key); this.setKey(channelId, secret); @@ -202,7 +201,7 @@ export default new class E2EE extends BuiltinModule { } patchDispatcher() { - const Dispatcher = WebpackModules.getModuleByName('Dispatcher'); + const { Dispatcher } = Reflection.modules; MonkeyPatch('BD:E2EE', Dispatcher).before('dispatch', (_, [event]) => { if (event.type !== 'MESSAGE_CREATE') return; @@ -216,9 +215,8 @@ export default new class E2EE extends BuiltinModule { decrypt = this.decrypt(this.decrypt(this.decrypt(seed, this.master), key), event.message.content); } catch (err) { return } // Ignore errors such as non empty - const MessageParser = WebpackModules.getModuleByName('MessageParser'); - const Permissions = WebpackModules.getModuleByName('GuildPermissions'); - const DiscordConstants = WebpackModules.getModuleByName('DiscordConstants'); + const { MessageParser, Permissions, DiscordConstants } = Reflection.modules; + const currentChannel = DiscordApi.Channel.fromId(event.message.channel_id).discordObject; // Create a generic message object to parse mentions with @@ -234,11 +232,10 @@ export default new class E2EE extends BuiltinModule { } async patchMessageContent() { - const selector = `.${WebpackModules.getClassName('container', 'containerCozy', 'containerCompact', 'edited')}`; - const MessageContent = await ReactComponents.getComponent('MessageContent', { selector }); + const MessageContent = await ReactComponents.getComponent('MessageContent', { selector: Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited').selector }); MonkeyPatch('BD:E2EE', MessageContent.component.prototype).before('render', this.beforeRenderMessageContent.bind(this)); MonkeyPatch('BD:E2EE', MessageContent.component.prototype).after('render', this.renderMessageContent.bind(this)); - const ImageWrapper = await ReactComponents.getComponent('ImageWrapper', { selector: `.${WebpackModules.getClassName('imageWrapper')}` }); + const ImageWrapper = await ReactComponents.getComponent('ImageWrapper', { selector: Reflection.resolve('imageWrapper').selector }); MonkeyPatch('BD:E2EE', ImageWrapper.component.prototype).before('render', this.beforeRenderImageWrapper.bind(this)); } @@ -248,10 +245,7 @@ export default new class E2EE extends BuiltinModule { const key = this.getKey(component.props.message.channel_id); if (!key) return; // We don't have a key for this channel - const Message = WebpackModules.getModuleByPrototypes(['isMentioned']); - const MessageParser = WebpackModules.getModuleByName('MessageParser'); - const Permissions = WebpackModules.getModuleByName('GuildPermissions'); - const DiscordConstants = WebpackModules.getModuleByName('DiscordConstants'); + const { Message, MessageParser, Permissions, DiscordConstants } = Reflection.modules; const currentChannel = DiscordApi.Channel.fromId(component.props.message.channel_id).discordObject; if (typeof component.props.message.content !== 'string') return; // Ignore any non string content diff --git a/client/src/builtin/E2EEComponent.vue b/client/src/builtin/E2EEComponent.vue index c4bf7a26..fb160b6a 100644 --- a/client/src/builtin/E2EEComponent.vue +++ b/client/src/builtin/E2EEComponent.vue @@ -39,7 +39,7 @@