I only understood today the reason for the Object.assign
This commit is contained in:
parent
896b8970b6
commit
8de1ca86a9
|
@ -56,8 +56,7 @@ const PermissionUtil = findByProps("computePermissions", "canEveryoneRole") as {
|
||||||
computePermissions({ ...args }): bigint;
|
computePermissions({ ...args }): bigint;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Tag = findComponentByCode(".DISCORD_SYSTEM_MESSAGE_BOT_TAG_TOOLTIP,") as React.ComponentType<{ type?: number, className?: string, useRemSizes?: boolean; }>;
|
const Tag = findComponentByCode(".DISCORD_SYSTEM_MESSAGE_BOT_TAG_TOOLTIP,") as React.ComponentType<{ type?: number, className?: string, useRemSizes?: boolean; }> & { Types: Record<string, number>; };
|
||||||
const { BotTagTypes } = findByProps("BotTagTypes");
|
|
||||||
|
|
||||||
const isWebhook = (message: Message, user: User) => !!message?.webhookId && user.isNonUserBot();
|
const isWebhook = (message: Message, user: User) => !!message?.webhookId && user.isNonUserBot();
|
||||||
|
|
||||||
|
@ -123,7 +122,7 @@ function SettingsComponent(props: { setValue(v: any): void; }) {
|
||||||
onMouseEnter={onMouseEnter}
|
onMouseEnter={onMouseEnter}
|
||||||
onMouseLeave={onMouseLeave}
|
onMouseLeave={onMouseLeave}
|
||||||
>
|
>
|
||||||
{t.displayName} Tag <Tag type={BotTagTypes[t.name]} />
|
{t.displayName} Tag <Tag type={Tag.Types[t.name]} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
@ -303,7 +302,7 @@ export default definePlugin({
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
|
|
||||||
isOPTag: (tag: number) => tag === BotTagTypes.ORIGINAL_POSTER || tags.some(t => tag === BotTagTypes[`${t.name}-OP`]),
|
isOPTag: (tag: number) => tag === Tag.Types.ORIGINAL_POSTER || tags.some(t => tag === Tag.Types[`${t.name}-OP`]),
|
||||||
|
|
||||||
getTagText(passedTagName: string, strings: Record<string, string>) {
|
getTagText(passedTagName: string, strings: Record<string, string>) {
|
||||||
if (!passedTagName) return strings.APP_TAG;
|
if (!passedTagName) return strings.APP_TAG;
|
||||||
|
@ -336,9 +335,9 @@ export default definePlugin({
|
||||||
if (!user)
|
if (!user)
|
||||||
return null;
|
return null;
|
||||||
if (location === "chat" && user.id === "1")
|
if (location === "chat" && user.id === "1")
|
||||||
return BotTagTypes.OFFICIAL;
|
return Tag.Types.OFFICIAL;
|
||||||
if (user.isClyde())
|
if (user.isClyde())
|
||||||
return BotTagTypes.AI;
|
return Tag.Types.AI;
|
||||||
|
|
||||||
let type = typeof origType === "number" ? origType : null;
|
let type = typeof origType === "number" ? origType : null;
|
||||||
|
|
||||||
|
@ -366,11 +365,11 @@ export default definePlugin({
|
||||||
(tag.condition?.(message!, user, channel))
|
(tag.condition?.(message!, user, channel))
|
||||||
) {
|
) {
|
||||||
if (channel.isForumPost() && channel.ownerId === user.id)
|
if (channel.isForumPost() && channel.ownerId === user.id)
|
||||||
type = BotTagTypes[`${tag.name}-OP`];
|
type = Tag.Types[`${tag.name}-OP`];
|
||||||
else if (user.bot && !isWebhook(message!, user) && !settings.dontShowBotTag)
|
else if (user.bot && !isWebhook(message!, user) && !settings.dontShowBotTag)
|
||||||
type = BotTagTypes[`${tag.name}-BOT`];
|
type = Tag.Types[`${tag.name}-BOT`];
|
||||||
else
|
else
|
||||||
type = BotTagTypes[tag.name];
|
type = Tag.Types[tag.name];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,7 @@ const handler: ProxyHandler<any> = {
|
||||||
/**
|
/**
|
||||||
* Wraps the result of factory in a Proxy you can consume as if it wasn't lazy.
|
* Wraps the result of factory in a Proxy you can consume as if it wasn't lazy.
|
||||||
* On first property access, the factory is evaluated.
|
* On first property access, the factory is evaluated.
|
||||||
|
*
|
||||||
* @param factory Factory returning the result
|
* @param factory Factory returning the result
|
||||||
* @param attempts How many times to try to evaluate the factory before giving up
|
* @param attempts How many times to try to evaluate the factory before giving up
|
||||||
* @returns Result of factory function
|
* @returns Result of factory function
|
||||||
|
|
|
@ -9,13 +9,6 @@ import { makeLazy } from "./lazy";
|
||||||
/**
|
/**
|
||||||
* A lazy component. The factory method is called on first render.
|
* A lazy component. The factory method is called on first render.
|
||||||
*
|
*
|
||||||
* IMPORTANT: You cannot access properties set on the lazy component using this method.
|
|
||||||
*
|
|
||||||
* Example of how you cannot access the properties set on the component:
|
|
||||||
* ```
|
|
||||||
* const Component = LazyComponent(...);
|
|
||||||
* console.log(Component.Types); // This will not work
|
|
||||||
* ````
|
|
||||||
* @param factory Function returning a component
|
* @param factory Function returning a component
|
||||||
* @param attempts How many times to try to get the component before giving up
|
* @param attempts How many times to try to get the component before giving up
|
||||||
* @returns Result of factory function
|
* @returns Result of factory function
|
||||||
|
@ -31,6 +24,7 @@ export function LazyComponent<T extends object = any>(factory: () => React.Compo
|
||||||
const ResultComponent = get();
|
const ResultComponent = get();
|
||||||
if (ResultComponent != null) {
|
if (ResultComponent != null) {
|
||||||
InnerComponent = ResultComponent;
|
InnerComponent = ResultComponent;
|
||||||
|
Object.assign(LazyComponent, ResultComponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ const handler: ProxyHandler<any> = {
|
||||||
/**
|
/**
|
||||||
* A proxy which has an inner value that can be set later.
|
* A proxy which has an inner value that can be set later.
|
||||||
* When a property is accessed, the proxy looks for the property value in its inner value, and errors if it's not set.
|
* When a property is accessed, the proxy looks for the property value in its inner value, and errors if it's not set.
|
||||||
|
*
|
||||||
* @param err The error message to throw when the inner value is not set
|
* @param err The error message to throw when the inner value is not set
|
||||||
* @param primitiveErr The error message to throw when the inner value is a primitive
|
* @param primitiveErr The error message to throw when the inner value is a primitive
|
||||||
* @returns A proxy which will act like the inner value when accessed
|
* @returns A proxy which will act like the inner value when accessed
|
||||||
|
|
|
@ -122,6 +122,7 @@ function printFilter(filter: FilterFn) {
|
||||||
* then call the callback with the module as the first argument.
|
* then call the callback with the module as the first argument.
|
||||||
*
|
*
|
||||||
* If the module is already required, the callback will be called immediately.
|
* If the module is already required, the callback will be called immediately.
|
||||||
|
*
|
||||||
* @param filter A function that takes a module and returns a boolean
|
* @param filter A function that takes a module and returns a boolean
|
||||||
* @param callback A function that takes the found module as its first argument
|
* @param callback A function that takes the found module as its first argument
|
||||||
*/
|
*/
|
||||||
|
@ -165,6 +166,7 @@ export function waitFor(filter: FilterFn, callback: ModCallbackFn, { isIndirect
|
||||||
* The callback must return a value that will be used as the proxy inner value.
|
* The callback must return a value that will be used as the proxy inner value.
|
||||||
*
|
*
|
||||||
* If no callback is specified, the default callback will assign the proxy inner value to all the module.
|
* If no callback is specified, the default callback will assign the proxy inner value to all the module.
|
||||||
|
*
|
||||||
* @param filter A function that takes a module and returns a boolean
|
* @param filter A function that takes a module and returns a boolean
|
||||||
* @param callback A function that takes the found module as its first argument and returns something to use as the proxy inner value. Useful if you want to use a value from the module, instead of all of it. Defaults to the module itself
|
* @param callback A function that takes the found module as its first argument and returns something to use as the proxy inner value. Useful if you want to use a value from the module, instead of all of it. Defaults to the module itself
|
||||||
* @returns A proxy that has the callback return value as its true value, or the callback return value if the callback was called when the function was called
|
* @returns A proxy that has the callback return value as its true value, or the callback return value if the callback was called when the function was called
|
||||||
|
@ -190,13 +192,6 @@ export function find<T = AnyObject>(filter: FilterFn, callback: (mod: any) => an
|
||||||
/**
|
/**
|
||||||
* Find the first component that matches the filter.
|
* Find the first component that matches the filter.
|
||||||
*
|
*
|
||||||
* IMPORTANT: You cannot access properties set on the found component using this method. You should instead try to obtain the property using a non component find instead.
|
|
||||||
*
|
|
||||||
* Example of how you cannot access the properties set on the component:
|
|
||||||
* ```
|
|
||||||
* const Component = findComponent(...);
|
|
||||||
* console.log(Component.Types); // This will not work
|
|
||||||
* ````
|
|
||||||
* @param filter A function that takes a module and returns a boolean
|
* @param filter A function that takes a module and returns a boolean
|
||||||
* @param parse A function that takes the found component as its first argument and returns a component. Useful if you want to wrap the found component in something. Defaults to the original component
|
* @param parse A function that takes the found component as its first argument and returns a component. Useful if you want to wrap the found component in something. Defaults to the original component
|
||||||
* @returns The component if found, or a noop component
|
* @returns The component if found, or a noop component
|
||||||
|
@ -222,7 +217,7 @@ export function findComponent<T extends object = any>(filter: FilterFn, parse: (
|
||||||
waitFor(filter, (v: any) => {
|
waitFor(filter, (v: any) => {
|
||||||
const parsedComponent = parse(v);
|
const parsedComponent = parse(v);
|
||||||
InnerComponent = parsedComponent;
|
InnerComponent = parsedComponent;
|
||||||
Object.assign(InnerComponent, parsedComponent);
|
Object.assign(WrapperComponent, parsedComponent);
|
||||||
}, { isIndirect: true });
|
}, { isIndirect: true });
|
||||||
|
|
||||||
if (IS_DEV) {
|
if (IS_DEV) {
|
||||||
|
@ -241,13 +236,6 @@ export function findComponent<T extends object = any>(filter: FilterFn, parse: (
|
||||||
/**
|
/**
|
||||||
* Find the first component that is exported by the first prop name.
|
* Find the first component that is exported by the first prop name.
|
||||||
*
|
*
|
||||||
* IMPORTANT: You cannot access properties set on the found component using this method. You should instead try to obtain the property using a non component find instead.
|
|
||||||
*
|
|
||||||
* Example of how you cannot access the properties set on the component:
|
|
||||||
* ```
|
|
||||||
* const Component = findExportedComponent(...);
|
|
||||||
* console.log(Component.Types); // This will not work
|
|
||||||
* ````
|
|
||||||
* @example findExportedComponent("FriendRow")
|
* @example findExportedComponent("FriendRow")
|
||||||
* @example findExportedComponent("FriendRow", "Friend", FriendRow => React.memo(FriendRow))
|
* @example findExportedComponent("FriendRow", "Friend", FriendRow => React.memo(FriendRow))
|
||||||
*
|
*
|
||||||
|
@ -277,7 +265,7 @@ export function findExportedComponent<T extends object = any>(...props: string[]
|
||||||
waitFor(filter, (v: any) => {
|
waitFor(filter, (v: any) => {
|
||||||
const parsedComponent = parse(v[newProps[0]]);
|
const parsedComponent = parse(v[newProps[0]]);
|
||||||
InnerComponent = parsedComponent;
|
InnerComponent = parsedComponent;
|
||||||
Object.assign(InnerComponent, parsedComponent);
|
Object.assign(WrapperComponent, parsedComponent);
|
||||||
}, { isIndirect: true });
|
}, { isIndirect: true });
|
||||||
|
|
||||||
if (IS_DEV) {
|
if (IS_DEV) {
|
||||||
|
@ -293,13 +281,6 @@ export function findExportedComponent<T extends object = any>(...props: string[]
|
||||||
/**
|
/**
|
||||||
* Find the first component in a default export that includes all the given code.
|
* Find the first component in a default export that includes all the given code.
|
||||||
*
|
*
|
||||||
* IMPORTANT: You cannot access properties set on the found component using this method. You should instead try to obtain the property using a non component find instead.
|
|
||||||
*
|
|
||||||
* Example of how you cannot access the properties set on the component:
|
|
||||||
* ```
|
|
||||||
* const Component = findComponentByCode(...);
|
|
||||||
* console.log(Component.Types); // This will not work
|
|
||||||
* ````
|
|
||||||
* @example findComponentByCode(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR")
|
* @example findComponentByCode(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR")
|
||||||
* @example findComponentByCode(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR", ".BACKGROUND_PRIMARY)", ColorPicker => React.memo(ColorPicker))
|
* @example findComponentByCode(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR", ".BACKGROUND_PRIMARY)", ColorPicker => React.memo(ColorPicker))
|
||||||
*
|
*
|
||||||
|
@ -367,6 +348,7 @@ export function findStore<T = GenericStore>(name: string) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the first already required module that matches the filter.
|
* Find the first already required module that matches the filter.
|
||||||
|
*
|
||||||
* @param filter A function that takes a module and returns a boolean
|
* @param filter A function that takes a module and returns a boolean
|
||||||
* @returns The found module or null
|
* @returns The found module or null
|
||||||
*/
|
*/
|
||||||
|
@ -414,6 +396,7 @@ export function cacheFindAll(filter: FilterFn) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as {@link cacheFind} but in bulk.
|
* Same as {@link cacheFind} but in bulk.
|
||||||
|
*
|
||||||
* @param filterFns Array of filters. Please note that this array will be modified in place, so if you still
|
* @param filterFns Array of filters. Please note that this array will be modified in place, so if you still
|
||||||
* need it afterwards, pass a copy.
|
* need it afterwards, pass a copy.
|
||||||
* @returns Array of results in the same order as the passed filters
|
* @returns Array of results in the same order as the passed filters
|
||||||
|
@ -520,6 +503,7 @@ export function findModuleFactory(...code: string[]) {
|
||||||
*
|
*
|
||||||
* Wraps the result of factory in a Proxy you can consume as if it wasn't lazy.
|
* Wraps the result of factory in a Proxy you can consume as if it wasn't lazy.
|
||||||
* On first property access, the factory is evaluated.
|
* On first property access, the factory is evaluated.
|
||||||
|
*
|
||||||
* @param factory Factory returning the result
|
* @param factory Factory returning the result
|
||||||
* @param attempts How many times to try to evaluate the factory before giving up
|
* @param attempts How many times to try to evaluate the factory before giving up
|
||||||
* @returns Result of factory function
|
* @returns Result of factory function
|
||||||
|
@ -535,13 +519,6 @@ export function webpackDependantLazy<T = AnyObject>(factory: () => T, attempts?:
|
||||||
*
|
*
|
||||||
* A lazy component. The factory method is called on first render.
|
* A lazy component. The factory method is called on first render.
|
||||||
*
|
*
|
||||||
* IMPORTANT: You cannot access properties set on the lazy component using this method.
|
|
||||||
*
|
|
||||||
* Example of how you cannot access the properties set on the component:
|
|
||||||
* ```
|
|
||||||
* const Component = webpackDependantLazyComponent(...);
|
|
||||||
* console.log(Component.Types); // This will not work
|
|
||||||
* ````
|
|
||||||
* @param factory Function returning a Component
|
* @param factory Function returning a Component
|
||||||
* @param attempts How many times to try to get the component before giving up
|
* @param attempts How many times to try to get the component before giving up
|
||||||
* @returns Result of factory function
|
* @returns Result of factory function
|
||||||
|
@ -566,6 +543,7 @@ function deprecatedRedirect<T extends (...args: any[]) => any>(oldMethod: string
|
||||||
*
|
*
|
||||||
* Wraps the result of factory in a Proxy you can consume as if it wasn't lazy.
|
* Wraps the result of factory in a Proxy you can consume as if it wasn't lazy.
|
||||||
* On first property access, the factory is evaluated.
|
* On first property access, the factory is evaluated.
|
||||||
|
*
|
||||||
* @param factory Factory returning the result
|
* @param factory Factory returning the result
|
||||||
* @param attempts How many times to try to evaluate the factory before giving up
|
* @param attempts How many times to try to evaluate the factory before giving up
|
||||||
* @returns Result of factory function
|
* @returns Result of factory function
|
||||||
|
@ -579,13 +557,6 @@ export const proxyLazyWebpack = deprecatedRedirect("proxyLazyWebpack", "webpackD
|
||||||
*
|
*
|
||||||
* A lazy component. The factory method is called on first render.
|
* A lazy component. The factory method is called on first render.
|
||||||
*
|
*
|
||||||
* IMPORTANT: You cannot access properties set on the lazy component using this method.
|
|
||||||
*
|
|
||||||
* Example of how you cannot access the properties set on the component:
|
|
||||||
* ```
|
|
||||||
* const Component = LazyComponentWebpack(...);
|
|
||||||
* console.log(Component.Types); // This will not work
|
|
||||||
* ````
|
|
||||||
* @param factory Function returning a Component
|
* @param factory Function returning a Component
|
||||||
* @param attempts How many times to try to get the component before giving up
|
* @param attempts How many times to try to get the component before giving up
|
||||||
* @returns Result of factory function
|
* @returns Result of factory function
|
||||||
|
@ -651,6 +622,7 @@ export const findAll = deprecatedRedirect("findAll", "cacheFindAll", cacheFindAl
|
||||||
* @deprecated Use {@link cacheFindBulk} instead
|
* @deprecated Use {@link cacheFindBulk} instead
|
||||||
*
|
*
|
||||||
* Same as {@link cacheFind} but in bulk
|
* Same as {@link cacheFind} but in bulk
|
||||||
|
*
|
||||||
* @param filterFns Array of filters. Please note that this array will be modified in place, so if you still
|
* @param filterFns Array of filters. Please note that this array will be modified in place, so if you still
|
||||||
* need it afterwards, pass a copy.
|
* need it afterwards, pass a copy.
|
||||||
* @returns Array of results in the same order as the passed filters
|
* @returns Array of results in the same order as the passed filters
|
||||||
|
@ -662,6 +634,7 @@ export const ChunkIdsRegex = /\("(.+?)"\)/g;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract and load chunks using their entry point.
|
* Extract and load chunks using their entry point.
|
||||||
|
*
|
||||||
* @param code An array of all the code the module factory containing the lazy chunk loading must include
|
* @param code An array of all the code the module factory containing the lazy chunk loading must include
|
||||||
* @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the lazy chunk loading found in the module factory
|
* @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the lazy chunk loading found in the module factory
|
||||||
* @returns A promise that resolves when the chunks were loaded
|
* @returns A promise that resolves when the chunks were loaded
|
||||||
|
@ -712,6 +685,7 @@ export async function extractAndLoadChunks(code: string[], matcher: RegExp = Def
|
||||||
* This is just a wrapper around {@link extractAndLoadChunks} to make our reporter test for your webpack finds.
|
* This is just a wrapper around {@link extractAndLoadChunks} to make our reporter test for your webpack finds.
|
||||||
*
|
*
|
||||||
* Extract and load chunks using their entry point.
|
* Extract and load chunks using their entry point.
|
||||||
|
*
|
||||||
* @param code An array of all the code the module factory containing the lazy chunk loading must include
|
* @param code An array of all the code the module factory containing the lazy chunk loading must include
|
||||||
* @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the lazy chunk loading found in the module factory
|
* @param matcher A RegExp that returns the chunk ids array as the first capture group and the entry point id as the second. Defaults to a matcher that captures the lazy chunk loading found in the module factory
|
||||||
* @returns A function that returns a promise that resolves when the chunks were loaded, on first call
|
* @returns A function that returns a promise that resolves when the chunks were loaded, on first call
|
||||||
|
@ -724,7 +698,8 @@ export function extractAndLoadChunksLazy(code: string[], matcher = DefaultExtrac
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search modules by keyword. This searches the factory methods,
|
* Search modules by keyword. This searches the factory methods,
|
||||||
* meaning you can search all sorts of things, displayName, methodName, strings somewhere in the code, etc
|
* meaning you can search all sorts of things, methodName, strings somewhere in the code, etc.
|
||||||
|
*
|
||||||
* @param filters One or more strings or regexes
|
* @param filters One or more strings or regexes
|
||||||
* @returns Mapping of found modules
|
* @returns Mapping of found modules
|
||||||
*/
|
*/
|
||||||
|
@ -751,6 +726,7 @@ export function search(...filters: Array<string | RegExp>) {
|
||||||
* to view a massive file. extract then returns the extracted module so you can jump to it.
|
* to view a massive file. extract then returns the extracted module so you can jump to it.
|
||||||
* As mentioned above, note that this extracted module is not actually used,
|
* As mentioned above, note that this extracted module is not actually used,
|
||||||
* so putting breakpoints or similar will have no effect.
|
* so putting breakpoints or similar will have no effect.
|
||||||
|
*
|
||||||
* @param id The id of the module to extract
|
* @param id The id of the module to extract
|
||||||
*/
|
*/
|
||||||
export function extract(id: string | number) {
|
export function extract(id: string | number) {
|
||||||
|
|
Loading…
Reference in a new issue