Fix public servers

This commit is contained in:
Zack Rauen 2022-10-09 13:49:29 -04:00
parent a13422df11
commit a9220996b5
5 changed files with 80 additions and 88 deletions

View File

@ -44,36 +44,32 @@ export default new class PublicServers extends Builtin {
get id() {return "publicServers";}
enabled() {
// let target = null;
// WebpackModules.getModule((_, m) => {
// if (m.exports?.toString().includes("privateChannelIds")) {
// target = m.exports;
// }
// });
// if (!target || !target.Z) return;
// const PrivateChannelListComponents = WebpackModules.getByProps("LinkButton");
// this.after(target, "Z", (_, __, returnValue) => {
// const destination = returnValue?.props?.children?.props?.children;
// if (!destination || !Array.isArray(destination)) return;
// if (destination.find(b => b?.props?.children?.props?.id === "public-server-button")) return;
const PrivateChannelList = WebpackModules.getModule(m => m?.toString().includes("privateChannelIds"), {defaultExport: false});
if (!PrivateChannelList || !PrivateChannelList.Z) return this.warn("Could not find PrivateChannelList", PrivateChannelList);
const PrivateChannelButton = WebpackModules.getModule(m => m?.prototype?.render?.toString().includes("linkButton"), {searchExports: true});
if (!PrivateChannelButton) return this.warn("Could not find PrivateChannelButton", PrivateChannelButton);
this.after(PrivateChannelList, "Z", (_, __, returnValue) => {
const destination = returnValue?.props?.children?.props?.children;
if (!destination || !Array.isArray(destination)) return;
if (destination.find(b => b?.props?.children?.props?.id === "public-server-button")) return;
// destination.push(
// React.createElement(ErrorBoundary, null,
// React.createElement(PrivateChannelListComponents.LinkButton,
// {
// id: "public-server-button",
// onClick: () => this.openPublicServers(),
// text: "Public Servers",
// icon: () => React.createElement(Globe, {color: "currentColor"})
// }
// )
// )
// );
// });
destination.push(
React.createElement(ErrorBoundary, null,
React.createElement(PrivateChannelButton,
{
id: "public-server-button",
onClick: () => this.openPublicServers(),
text: "Public Servers",
icon: () => React.createElement(Globe, {color: "currentColor"})
}
)
)
);
});
}
disabled() {
// this.unpatchAll();
this.unpatchAll();
// DOM.query("#bd-pub-li").remove();
}

View File

@ -79,14 +79,7 @@ export default new class Core {
const previousVersion = DataStore.getBDData("version");
if (Config.version > previousVersion) {
const md = [Changelog.description];
for (const type of Changelog.changes) {
md.push(`**${type.title}**`);
for (const entry of type.items) {
md.push(` - ${entry}`);
}
}
Modals.showConfirmationModal(`BetterDiscord v${Config.version}`, md, {cancelText: ""});
Modals.showChangelogModal(Changelog);
DataStore.setBDData("version", Config.version);
}
}

View File

@ -79,9 +79,11 @@ export class Filters {
*/
static byStrings(...strings) {
return module => {
if (!module?.toString || typeof(module?.toString) !== "function") return; // Not stringable
let moduleString = "";
try {moduleString = module.toString([]);}
catch (err) {moduleString = module.toString();}
try {moduleString = module?.toString([]);}
catch (err) {moduleString = module?.toString();}
if (!moduleString) return false; // Could not create string
for (const s of strings) {
if (!moduleString.includes(s)) return false;
}
@ -133,7 +135,6 @@ const wrapFilter = filter => (exports, module, moduleId) => {
export default class WebpackModules {
static times = [];
static find(filter, first = true) {return this.getModule(filter, {first});}
static findAll(filter) {return this.getModule(filter, {first: false});}
static findByUniqueProperties(props, first = true) {return first ? this.getByProps(...props) : this.getAllByProps(...props);}
@ -149,56 +150,48 @@ export default class WebpackModules {
* @return {Any}
*/
static getModule(filter, options = {}) {
const start = Date.now();
try {
const {first = true, defaultExport = true, searchExports = false} = options;
const wrappedFilter = wrapFilter(filter);
const {first = true, defaultExport = true, searchExports = false} = options;
const wrappedFilter = wrapFilter(filter);
const modules = this.getAllModules();
const rm = [];
const indices = Object.keys(modules);
for (let i = 0; i < indices.length; i++) {
const index = indices[i];
if (!modules.hasOwnProperty(index)) continue;
const module = modules[index];
const {exports} = module;
if (!exports || exports === window) continue;
if (typeof(exports) === "object" && searchExports) {
for (const key in exports) {
let foundModule = null;
const wrappedExport = exports[key];
if (!wrappedExport) continue;
if (wrappedExport.Z && wrappedFilter(wrappedExport.Z, module, index)) foundModule = defaultExport ? wrappedExport.Z : wrappedExport;
if (wrappedExport.ZP && wrappedFilter(wrappedExport.ZP, module, index)) foundModule = defaultExport ? wrappedExport.ZP : wrappedExport;
if (wrappedExport.__esModule && wrappedExport.default && wrappedFilter(wrappedExport.default, module, index)) foundModule = defaultExport ? wrappedExport.default : wrappedExport;
if (wrappedFilter(wrappedExport, module, index)) foundModule = wrappedExport;
if (!foundModule) continue;
if (first) return foundModule;
rm.push(foundModule);
}
}
else {
const modules = this.getAllModules();
const rm = [];
const indices = Object.keys(modules);
for (let i = 0; i < indices.length; i++) {
const index = indices[i];
if (!modules.hasOwnProperty(index)) continue;
const module = modules[index];
const {exports} = module;
if (!exports || exports === window) continue;
if (typeof(exports) === "object" && searchExports) {
for (const key in exports) {
let foundModule = null;
if (exports.Z && wrappedFilter(exports.Z, module, index)) foundModule = defaultExport ? exports.Z : exports;
if (exports.ZP && wrappedFilter(exports.ZP, module, index)) foundModule = defaultExport ? exports.ZP : exports;
if (exports.__esModule && exports.default && wrappedFilter(exports.default, module, index)) foundModule = defaultExport ? exports.default : exports;
if (wrappedFilter(exports, module, index)) foundModule = exports;
const wrappedExport = exports[key];
if (!wrappedExport) continue;
if (wrappedExport.Z && wrappedFilter(wrappedExport.Z, module, index)) foundModule = defaultExport ? wrappedExport.Z : wrappedExport;
if (wrappedExport.ZP && wrappedFilter(wrappedExport.ZP, module, index)) foundModule = defaultExport ? wrappedExport.ZP : wrappedExport;
if (wrappedExport.__esModule && wrappedExport.default && wrappedFilter(wrappedExport.default, module, index)) foundModule = defaultExport ? wrappedExport.default : wrappedExport;
if (wrappedFilter(wrappedExport, module, index)) foundModule = wrappedExport;
if (!foundModule) continue;
if (first) return foundModule;
rm.push(foundModule);
}
}
return first || rm.length == 0 ? undefined : rm;
}
finally {
const diff = Date.now() - start;
this.times.push(diff);
Logger.info("WebpackModules", new Error(`Search took ${(diff).toFixed(0)}ms`));
else {
let foundModule = null;
if (exports.Z && wrappedFilter(exports.Z, module, index)) foundModule = defaultExport ? exports.Z : exports;
if (exports.ZP && wrappedFilter(exports.ZP, module, index)) foundModule = defaultExport ? exports.ZP : exports;
if (exports.__esModule && exports.default && wrappedFilter(exports.default, module, index)) foundModule = defaultExport ? exports.default : exports;
if (wrappedFilter(exports, module, index)) foundModule = exports;
if (!foundModule) continue;
if (first) return foundModule;
rm.push(foundModule);
}
}
return first || rm.length == 0 ? undefined : rm;
}
/**
@ -497,5 +490,4 @@ export default class WebpackModules {
}
}
WebpackModules.initialize();
window.debugwm = WebpackModules;
WebpackModules.initialize();

View File

@ -9,7 +9,7 @@ const InviteActions = WebpackModules.getByProps("acceptInvite");
const betterDiscordServer = {
name: "BetterDiscord",
members: 55000,
members: 110000,
categories: ["community", "programming", "support"],
description: "Official BetterDiscord server for plugins, themes, support, etc",
identifier: "86004744966914048",

View File

@ -12,20 +12,20 @@ export default class Modals {
static get ModalActions() {
return this._ModalActions ??= {
openModal: WebpackModules.getModule(m => m?.toString().includes("onCloseCallback") && m?.toString().includes("Layer")),
closeModal: WebpackModules.getModule(m => m?.toString().includes("onCloseCallback()"))
openModal: WebpackModules.getModule(m => m?.toString().includes("onCloseCallback") && m?.toString().includes("Layer"), {searchExports: true}),
closeModal: WebpackModules.getModule(m => m?.toString().includes("onCloseCallback()"), {searchExports: true})
};
}
static get ModalStack() {return this._ModalStack ??= WebpackModules.getByProps("push", "update", "pop", "popWithKey");}
static get ModalComponents() {return this._ModalComponents ??= WebpackModules.getByProps("Header", "Footer");}
static get ModalRoot() {return this._ModalRoot ??= WebpackModules.getModule(m => m?.toString().includes("ENTERING"));}
static get ModalRoot() {return this._ModalRoot ??= WebpackModules.getModule(m => m?.toString?.()?.includes("ENTERING"), {searchExports: true});}
static get ModalClasses() {return this._ModalClasses ??= WebpackModules.getByProps("modal", "content");}
static get FlexElements() {return this._FlexElements ??= WebpackModules.getByProps("Child", "Align");}
static get FormTitle() {return this._FormTitle ??= WebpackModules.getByProps("Tags", "Sizes");}
static get TextElement() {return this._TextElement ??= WebpackModules.getModule(m => m?.Sizes?.SIZE_32 && m.Colors);}
static get ConfirmationModal() {return this._ConfirmationModal ??= WebpackModules.getModule(m => m?.toString()?.includes(".confirmButtonColor"));}
static get ConfirmationModal() {return this._ConfirmationModal ??= WebpackModules.getModule(m => m?.toString?.()?.includes(".confirmButtonColor"));}
static get Markdown() {return this._Markdown ??= WebpackModules.find(m => m?.prototype?.render && m.rules);}
static get Buttons() {return this._Buttons ??= WebpackModules.getByProps("BorderColors");}
static get Buttons() {return this._Buttons ??= WebpackModules.getModule(m => m.BorderColors, {searchExports: true});}
static get ModalQueue() {return this._ModalQueue ??= [];}
static get hasModalOpen() {return !!document.getElementsByClassName("bd-modal").length;}
@ -212,7 +212,18 @@ export default class Modals {
}))));
}
static showChangelogModal(options = {}) {
static showChangelogModal(changelog) {
const md = [changelog.description];
for (const type of changelog.changes) {
md.push(`**${type.title}**`);
for (const entry of type.items) {
md.push(` - ${entry}`);
}
}
Modals.showConfirmationModal(`BetterDiscord v${Config.version}`, md, {cancelText: ""});
}
static BROKEN_showChangelogModal(options = {}) {
const ModalStack = WebpackModules.getByProps("push", "update", "pop", "popWithKey");
const ChangelogClasses = WebpackModules.getByProps("fixed", "improved");
const TextElement = WebpackModules.getByDisplayName("LegacyText");