This commit is contained in:
Mirco Wittrien 2020-03-05 20:37:34 +01:00
parent 90ffe1ec9a
commit 108bedf390
3 changed files with 22 additions and 19 deletions

View File

@ -1043,8 +1043,8 @@
}; };
var WebModulesData = {}; var WebModulesData = {};
WebModulesData.Patchtypes = ["before", "instead", "after"]; WebModulesData.PatchTypes = ["before", "instead", "after"];
WebModulesData.Patchmap = { WebModulesData.PatchMap = {
BannedCard: "BannedUser", BannedCard: "BannedUser",
ChannelWindow: "Channel", ChannelWindow: "Channel",
InvitationCard: "InviteRow", InvitationCard: "InviteRow",
@ -1073,17 +1073,10 @@
"SimpleMessageAccessories", "SimpleMessageAccessories",
"UserInfo" "UserInfo"
]; ];
WebModulesData.PropsFind = {
MessageHeader: "MessageTimestamp",
UnavailableGuildsButton: "UnavailableGuildsButton"
};
WebModulesData.MemoComponent = [ WebModulesData.MemoComponent = [
"MessageContent", "MessageContent",
"NowPlayingHeader" "NowPlayingHeader"
]; ];
WebModulesData.NonPrototype = [].concat(WebModulesData.NonRender, Object.keys(WebModulesData.PropsFind), WebModulesData.MemoComponent, [
"ChannelTextAreaContainer"
]);
WebModulesData.LoadedInComponents = { WebModulesData.LoadedInComponents = {
AutocompleteChannelResult: "LibraryComponents.AutocompleteItems.Channel", AutocompleteChannelResult: "LibraryComponents.AutocompleteItems.Channel",
AutocompleteUserResult: "LibraryComponents.AutocompleteItems.User", AutocompleteUserResult: "LibraryComponents.AutocompleteItems.User",
@ -1144,6 +1137,13 @@
V2C_PluginCard: "_repoheader", V2C_PluginCard: "_repoheader",
V2C_ThemeCard: "_repoheader" V2C_ThemeCard: "_repoheader"
}; };
WebModulesData.PropsFinder = {
MessageHeader: "MessageTimestamp",
UnavailableGuildsButton: "UnavailableGuildsButton"
};
WebModulesData.NonPrototype = [].concat(WebModulesData.NonRender, Object.keys(WebModulesData.PropsFinder), WebModulesData.MemoComponent, [
"ChannelTextAreaContainer"
]);
WebModulesData.GlobalModules = {}; WebModulesData.GlobalModules = {};
try {WebModulesData.GlobalModules["V2C_ContentColumn"] = V2C_ContentColumn;} catch(err) {BDFDB.LogUtils.warn(`Could not find global Module "V2C_ContentColumn"`);} try {WebModulesData.GlobalModules["V2C_ContentColumn"] = V2C_ContentColumn;} catch(err) {BDFDB.LogUtils.warn(`Could not find global Module "V2C_ContentColumn"`);}
try {WebModulesData.GlobalModules["V2C_List"] = V2C_List;} catch(err) {BDFDB.LogUtils.warn(`Could not find global Module "V2C_List"`);} try {WebModulesData.GlobalModules["V2C_List"] = V2C_List;} catch(err) {BDFDB.LogUtils.warn(`Could not find global Module "V2C_List"`);}
@ -1157,7 +1157,7 @@
}; };
BDFDB.ModuleUtils.patch = function (plugin, module, methodNames, patchMethods, forceRepatch = false) { BDFDB.ModuleUtils.patch = function (plugin, module, methodNames, patchMethods, forceRepatch = false) {
if (!plugin || !BDFDB.ObjectUtils.is(module) || !methodNames || !BDFDB.ObjectUtils.is(patchMethods)) return null; if (!plugin || !BDFDB.ObjectUtils.is(module) || !methodNames || !BDFDB.ObjectUtils.is(patchMethods)) return null;
patchMethods = BDFDB.ObjectUtils.filter(patchMethods, type => WebModulesData.Patchtypes.includes(type), true); patchMethods = BDFDB.ObjectUtils.filter(patchMethods, type => WebModulesData.PatchTypes.includes(type), true);
if (BDFDB.ObjectUtils.isEmpty(patchMethods)) return null; if (BDFDB.ObjectUtils.isEmpty(patchMethods)) return null;
const pluginName = typeof plugin === "string" ? plugin : plugin.name; const pluginName = typeof plugin === "string" ? plugin : plugin.name;
const pluginId = pluginName.toLowerCase(); const pluginId = pluginName.toLowerCase();
@ -1169,7 +1169,7 @@
if (!module.BDFDBpatch[methodName] || forceRepatch && (!module[methodName] || !module[methodName].__isBDFDBpatched)) { if (!module.BDFDBpatch[methodName] || forceRepatch && (!module[methodName] || !module[methodName].__isBDFDBpatched)) {
if (!module.BDFDBpatch[methodName]) { if (!module.BDFDBpatch[methodName]) {
module.BDFDBpatch[methodName] = {}; module.BDFDBpatch[methodName] = {};
for (let type of WebModulesData.Patchtypes) module.BDFDBpatch[methodName][type] = {}; for (let type of WebModulesData.PatchTypes) module.BDFDBpatch[methodName][type] = {};
} }
if (!module[methodName]) module[methodName] = (_ => {}); if (!module[methodName]) module[methodName] = (_ => {});
const originalMethod = module[methodName]; const originalMethod = module[methodName];
@ -1237,14 +1237,14 @@
else for (let patchedMethod of module.BDFDBpatch) unpatch(patchedMethod, pluginId); else for (let patchedMethod of module.BDFDBpatch) unpatch(patchedMethod, pluginId);
} }
function unpatch (funcName, pluginId) { function unpatch (funcName, pluginId) {
for (let type of WebModulesData.Patchtypes) { for (let type of WebModulesData.PatchTypes) {
if (pluginId) for (let priority in module.BDFDBpatch[funcName][type]) { if (pluginId) for (let priority in module.BDFDBpatch[funcName][type]) {
delete module.BDFDBpatch[funcName][type][priority][pluginId]; delete module.BDFDBpatch[funcName][type][priority][pluginId];
if (BDFDB.ObjectUtils.isEmpty(module.BDFDBpatch[funcName][type][priority])) delete module.BDFDBpatch[funcName][type][priority]; if (BDFDB.ObjectUtils.isEmpty(module.BDFDBpatch[funcName][type][priority])) delete module.BDFDBpatch[funcName][type][priority];
} }
else delete module.BDFDBpatch[funcName][type]; else delete module.BDFDBpatch[funcName][type];
} }
if (BDFDB.ObjectUtils.isEmpty(BDFDB.ObjectUtils.filter(module.BDFDBpatch[funcName], key => WebModulesData.Patchtypes.includes(key) && !BDFDB.ObjectUtils.isEmpty(module.BDFDBpatch[funcName][key]), true))) { if (BDFDB.ObjectUtils.isEmpty(BDFDB.ObjectUtils.filter(module.BDFDBpatch[funcName], key => WebModulesData.PatchTypes.includes(key) && !BDFDB.ObjectUtils.isEmpty(module.BDFDBpatch[funcName][key]), true))) {
module[funcName] = module.BDFDBpatch[funcName].originalMethod; module[funcName] = module.BDFDBpatch[funcName].originalMethod;
delete module.BDFDBpatch[funcName]; delete module.BDFDBpatch[funcName];
if (BDFDB.ObjectUtils.isEmpty(module.BDFDBpatch)) delete module.BDFDBpatch; if (BDFDB.ObjectUtils.isEmpty(module.BDFDBpatch)) delete module.BDFDBpatch;
@ -1268,7 +1268,7 @@
} }
selectedtypes = [selectedtypes].flat(10).filter(n => n); selectedtypes = [selectedtypes].flat(10).filter(n => n);
if (selectedtypes.length) { if (selectedtypes.length) {
selectedtypes = selectedtypes.map(type => type && WebModulesData.Patchmap[type] ? WebModulesData.Patchmap[type] + " _ _ " + type : type); selectedtypes = selectedtypes.map(type => type && WebModulesData.PatchMap[type] ? WebModulesData.PatchMap[type] + " _ _ " + type : type);
filteredmodules = filteredmodules.filter(type => selectedtypes.indexOf(type) > -1); filteredmodules = filteredmodules.filter(type => selectedtypes.indexOf(type) > -1);
} }
filteredmodules = BDFDB.ArrayUtils.removeCopies(filteredmodules); filteredmodules = BDFDB.ArrayUtils.removeCopies(filteredmodules);
@ -1327,8 +1327,8 @@
if (component) patchInstance(WebModulesData.NonRender.includes(unmappedType) ? (BDFDB.ModuleUtils.find(m => m == component, false) || {}).exports : component, type, patchType); if (component) patchInstance(WebModulesData.NonRender.includes(unmappedType) ? (BDFDB.ModuleUtils.find(m => m == component, false) || {}).exports : component, type, patchType);
else { else {
let className = WebModulesData.PatchFinder[unmappedType]; let className = WebModulesData.PatchFinder[unmappedType];
let propertyFind = WebModulesData.PropsFind[unmappedType]; let propertyFind = WebModulesData.PropsFinder[unmappedType];
let mapped = WebModulesData.Patchmap[type]; let mapped = WebModulesData.PatchMap[type];
let mappedType = mapped ? mapped + " _ _ " + type : type; let mappedType = mapped ? mapped + " _ _ " + type : type;
let name = mappedType.split(" _ _ ")[0]; let name = mappedType.split(" _ _ ")[0];
if (mapped) { if (mapped) {

File diff suppressed because one or more lines are too long

View File

@ -9,6 +9,7 @@ var CustomQuoter = (_ => {
name: "Test Channel" name: "Test Channel"
}); });
let spoofQuotedMessage = new BDFDB.DiscordObjects.Message({ let spoofQuotedMessage = new BDFDB.DiscordObjects.Message({
id: "562432230424221059",
author: new BDFDB.DiscordObjects.User({ author: new BDFDB.DiscordObjects.User({
id: "230422432565221049", id: "230422432565221049",
username: "Quoted User" username: "Quoted User"
@ -35,7 +36,7 @@ var CustomQuoter = (_ => {
return class CustomQuoter { return class CustomQuoter {
getName () {return "CustomQuoter";} getName () {return "CustomQuoter";}
getVersion () {return "1.0.3";} getVersion () {return "1.0.4";}
getAuthor () {return "DevilBro";} getAuthor () {return "DevilBro";}
@ -43,7 +44,7 @@ var CustomQuoter = (_ => {
constructor () { constructor () {
this.changelog = { this.changelog = {
"improved":[["Message Preview","Added a message preview that let's you check your quote settings in real time"]] "added":[["Link Option","Added a link placeholder that will be replaced with the direct message link that jumps to the quoted message if clicked"]]
}; };
} }
@ -122,6 +123,7 @@ var CustomQuoter = (_ => {
children: [ children: [
"$quote will be replaced with the quoted message content", "$quote will be replaced with the quoted message content",
"$mention will be replaced with a mention of the message author", "$mention will be replaced with a mention of the message author",
"$link will be replaced with a discord direct link pointing to the message",
"$authorId will be replaced with the ID of the message author", "$authorId will be replaced with the ID of the message author",
"$authorName will be replaced with the name of the message author", "$authorName will be replaced with the name of the message author",
"$channel will be replaced with a mention of the channel (ignored for DMs)", "$channel will be replaced with a mention of the channel (ignored for DMs)",
@ -227,6 +229,7 @@ var CustomQuoter = (_ => {
return BDFDB.StringUtils.insertNRST(customQuote) return BDFDB.StringUtils.insertNRST(customQuote)
.replace("$mention", settings.ignoreMentionInDM && channel.isDM() ? "" : `<@!${message.author.id}>`) .replace("$mention", settings.ignoreMentionInDM && channel.isDM() ? "" : `<@!${message.author.id}>`)
.replace("$link", `https://discordapp.com/channels/${guild.id}/${channel.id}/${message.id}`)
.replace("$authorName", message.author.username || "") .replace("$authorName", message.author.username || "")
.replace("$authorId", message.author.id || "") .replace("$authorId", message.author.id || "")
.replace("$channelName", channel.name || "") .replace("$channelName", channel.name || "")