Update RemoveBlockedMessages.plugin.js

This commit is contained in:
Mirco Wittrien 2021-05-04 19:33:36 +02:00
parent dae157b886
commit b50b4561ef
1 changed files with 79 additions and 55 deletions

View File

@ -2,7 +2,7 @@
* @name RemoveBlockedMessages * @name RemoveBlockedMessages
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 1.2.4 * @version 1.2.5
* @description Removes blocked Messages/Users * @description Removes blocked Messages/Users
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -17,12 +17,12 @@ module.exports = (_ => {
"info": { "info": {
"name": "RemoveBlockedMessages", "name": "RemoveBlockedMessages",
"author": "DevilBro", "author": "DevilBro",
"version": "1.2.4", "version": "1.2.5",
"description": "Removes blocked Messages/Users" "description": "Removes blocked Messages/Users"
}, },
"changeLog": { "changeLog": {
"fixed": { "fixed": {
"Mentions": "" "New Messages Bar": "No longer shows on newly added blocked Messages"
} }
} }
}; };
@ -66,24 +66,25 @@ module.exports = (_ => {
} }
} : (([Plugin, BDFDB]) => { } : (([Plugin, BDFDB]) => {
var cachedChannelId, cachedReactions; var cachedChannelId, cachedReactions;
var settings = {};
return class RemoveBlockedMessages extends Plugin { return class RemoveBlockedMessages extends Plugin {
onLoad () { onLoad () {
this.defaults = { this.defaults = {
settings: { notifcations: {
disableNotifications: {value: true, description: "Messages Notifications"}, messages: {value: true, description: "Messages Notifications"},
disableVoiceNotifications: {value: true, description: "Voice Chat Notifications"}, voiceChat: {value: true, description: "Voice Chat Notifications"},
removeMessages: {value: true, description: "Messages"}, },
removePinnedMessages: {value: true, description: "Pinned Messages"}, places: {
removeInbox: {value: true, description: "Inbox Messages"}, messages: {value: true, description: "Messages"},
removeReplies: {value: true, description: "Replies"}, pins: {value: true, description: "Pinned Messages"},
removeMentions: {value: true, description: "Mentions"}, inbox: {value: true, description: "Inbox Messages"},
removeReactions: {value: true, description: "Reactions"}, replies: {value: true, description: "Replies"},
removeAutocomplete: {value: true, description: "Autocomplete Entries"}, mentions: {value: true, description: "Mentions"},
removeUsers: {value: true, description: "Members in List"}, reactions: {value: true, description: "Reactions"},
removeVoiceUser: {value: true, description: "Members in Voice List"}, autocompletes: {value: true, description: "Autocomplete Entries"},
removeVoiceChats: {value: true, description: "Members in Voice Chat"} memberList: {value: true, description: "Members in List"},
voiceList: {value: true, description: "Members in Voice List"},
voiceChat: {value: true, description: "Members in Voice Chat"}
} }
}; };
@ -120,8 +121,16 @@ module.exports = (_ => {
}}); }});
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.RelationshipUtils, "removeRelationship", {after: e => this.forceUpdateAll()}); BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.RelationshipUtils, "removeRelationship", {after: e => this.forceUpdateAll()});
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.UnreadChannelUtils, "getUnreadCount", {after: e => {
if (e.returnValue && this.settings.notifcations.messages && e.returnValue < BDFDB.DiscordConstants.MAX_MESSAGES_PER_CHANNEL) {
let sub = 0, messages = [].concat(BDFDB.LibraryModules.MessageStore.getMessages(e.methodArguments[0])._array).reverse();
for (let i = 0; i < e.returnValue; i++) if (messages[i] && messages[i].blocked) sub++;
e.returnValue -= sub;
}
}});
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.UnreadChannelUtils, "hasUnread", {after: e => { BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.UnreadChannelUtils, "hasUnread", {after: e => {
if (e.returnValue && settings.disableNotifications) { if (e.returnValue && this.settings.notifcations.messages) {
let count = BDFDB.LibraryModules.UnreadChannelUtils.getUnreadCount(e.methodArguments[0]); let count = BDFDB.LibraryModules.UnreadChannelUtils.getUnreadCount(e.methodArguments[0]);
if (count < BDFDB.DiscordConstants.MAX_MESSAGES_PER_CHANNEL) { if (count < BDFDB.DiscordConstants.MAX_MESSAGES_PER_CHANNEL) {
let id = BDFDB.LibraryModules.UnreadChannelUtils.lastMessageId(e.methodArguments[0]); let id = BDFDB.LibraryModules.UnreadChannelUtils.lastMessageId(e.methodArguments[0]);
@ -139,13 +148,13 @@ module.exports = (_ => {
}}); }});
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.UnreadGuildUtils, "hasUnread", {after: e => { BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.UnreadGuildUtils, "hasUnread", {after: e => {
if (e.returnValue && settings.disableNotifications) { if (e.returnValue && this.settings.notifcations.messages) {
return BDFDB.LibraryModules.GuildChannelStore.getChannels(e.methodArguments[0]).SELECTABLE.map(n => n.channel && n.channel.id).filter(n => n && n != "null").some(BDFDB.LibraryModules.UnreadChannelUtils.hasUnread); return BDFDB.LibraryModules.GuildChannelStore.getChannels(e.methodArguments[0]).SELECTABLE.map(n => n.channel && n.channel.id).filter(n => n && n != "null").some(BDFDB.LibraryModules.UnreadChannelUtils.hasUnread);
} }
}}); }});
if (BDFDB.LibraryModules.AutocompleteOptions && BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS) BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS.MENTIONS, "queryResults", {after: e => { if (BDFDB.LibraryModules.AutocompleteOptions && BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS) BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS.MENTIONS, "queryResults", {after: e => {
if (settings.removeAutocomplete) e.returnValue.users = e.returnValue.users.filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id)); if (this.settings.places.autocompletes) e.returnValue.users = e.returnValue.users.filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id));
}}); }});
let muteTimeout; let muteTimeout;
@ -153,7 +162,7 @@ module.exports = (_ => {
let connectedUsers = BDFDB.ObjectUtils.filter(BDFDB.LibraryModules.VoiceUtils.getVoiceStates(BDFDB.LibraryModules.CurrentVoiceUtils.getGuildId()), n => n && n.channelId == channelId && !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.userId)); let connectedUsers = BDFDB.ObjectUtils.filter(BDFDB.LibraryModules.VoiceUtils.getVoiceStates(BDFDB.LibraryModules.CurrentVoiceUtils.getGuildId()), n => n && n.channelId == channelId && !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.userId));
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.SoundUtils, "playSound", {instead: e => { BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.SoundUtils, "playSound", {instead: e => {
let type = e.methodArguments[0]; let type = e.methodArguments[0];
if (settings.disableVoiceNotifications && type == "user_join" || type == "user_leave" || type == "user_moved") { if (this.settings.notifcations.voiceChat && type == "user_join" || type == "user_leave" || type == "user_moved") {
channelId = BDFDB.LibraryModules.CurrentVoiceUtils.getChannelId(); channelId = BDFDB.LibraryModules.CurrentVoiceUtils.getChannelId();
if (channelId) { if (channelId) {
let allConnectedUsers = BDFDB.ObjectUtils.filter(BDFDB.LibraryModules.VoiceUtils.getVoiceStates(BDFDB.LibraryModules.CurrentVoiceUtils.getGuildId()), n => n && n.channelId == channelId); let allConnectedUsers = BDFDB.ObjectUtils.filter(BDFDB.LibraryModules.VoiceUtils.getVoiceStates(BDFDB.LibraryModules.CurrentVoiceUtils.getGuildId()), n => n && n.channelId == channelId);
@ -185,20 +194,37 @@ module.exports = (_ => {
} }
getSettingsPanel (collapseStates = {}) { getSettingsPanel (collapseStates = {}) {
let settingsPanel, settingsItems = []; let settingsPanel;
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, {
collapseStates: collapseStates,
children: _ => {
let settingsItems = [];
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, { settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, {
title: "Remove Elements:", title: "Disable",
children: Object.keys(settings).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { children: Object.keys(this.defaults.notifcations).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch", type: "Switch",
plugin: this, plugin: this,
keys: ["settings", key], keys: ["notifcations", key],
label: this.defaults.settings[key].description, label: this.defaults.notifcations[key].description,
value: settings[key] value: this.settings.notifcations[key]
})) }))
})); }));
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems); settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, {
title: "Remove",
children: Object.keys(this.defaults.places).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
plugin: this,
keys: ["places", key],
label: this.defaults.places[key].description,
value: this.settings.places[key]
}))
}));
return settingsItems;
}
});
} }
onSettingsClosed () { onSettingsClosed () {
@ -209,14 +235,12 @@ module.exports = (_ => {
} }
forceUpdateAll () { forceUpdateAll () {
settings = BDFDB.DataUtils.get(this, "settings");
BDFDB.PatchUtils.forceAllUpdates(this); BDFDB.PatchUtils.forceAllUpdates(this);
BDFDB.MessageUtils.rerenderAll(); BDFDB.MessageUtils.rerenderAll();
} }
processMessages (e) { processMessages (e) {
if (settings.removeMessages) { if (this.settings.places.messages) {
let messagesIns = e.returnvalue.props.children; let messagesIns = e.returnvalue.props.children;
if (BDFDB.ArrayUtils.is(messagesIns.props.channelStream)) { if (BDFDB.ArrayUtils.is(messagesIns.props.channelStream)) {
let oldStream = messagesIns.props.channelStream.filter(n => n.type != "MESSAGE_GROUP_BLOCKED"), newStream = []; let oldStream = messagesIns.props.channelStream.filter(n => n.type != "MESSAGE_GROUP_BLOCKED"), newStream = [];
@ -246,7 +270,7 @@ module.exports = (_ => {
} }
processMessage (e) { processMessage (e) {
if (settings.removeReplies) { if (this.settings.places.replies) {
let repliedMessage = e.instance.props.childrenRepliedMessage; let repliedMessage = e.instance.props.childrenRepliedMessage;
if (repliedMessage && repliedMessage.props && repliedMessage.props.children && repliedMessage.props.children.props && repliedMessage.props.children.props.referencedMessage && repliedMessage.props.children.props.referencedMessage.message && repliedMessage.props.children.props.referencedMessage.message.author && BDFDB.LibraryModules.RelationshipStore.isBlocked(repliedMessage.props.children.props.referencedMessage.message.author.id)) { if (repliedMessage && repliedMessage.props && repliedMessage.props.children && repliedMessage.props.children.props && repliedMessage.props.children.props.referencedMessage && repliedMessage.props.children.props.referencedMessage.message && repliedMessage.props.children.props.referencedMessage.message.author && BDFDB.LibraryModules.RelationshipStore.isBlocked(repliedMessage.props.children.props.referencedMessage.message.author.id)) {
delete e.instance.props.childrenRepliedMessage; delete e.instance.props.childrenRepliedMessage;
@ -262,15 +286,15 @@ module.exports = (_ => {
} }
processChannelPins (e) { processChannelPins (e) {
if (settings.removePinnedMessages && e.returnvalue.props && e.returnvalue.props.children && e.returnvalue.props.children.props && BDFDB.ArrayUtils.is(e.returnvalue.props.children.props.messages)) e.returnvalue.props.children.props.messages = e.returnvalue.props.children.props.messages.filter(n => !n || !n.author || !n.author.id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.author.id)); if (this.settings.places.pins && e.returnvalue.props && e.returnvalue.props.children && e.returnvalue.props.children.props && BDFDB.ArrayUtils.is(e.returnvalue.props.children.props.messages)) e.returnvalue.props.children.props.messages = e.returnvalue.props.children.props.messages.filter(n => !n || !n.author || !n.author.id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.author.id));
} }
processRecentMentions (e) { processRecentMentions (e) {
if (settings.removeInbox && BDFDB.ArrayUtils.is(e.returnvalue.props.messages)) e.returnvalue.props.messages = e.returnvalue.props.messages.filter(n => !n || !n.author || !n.author.id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.author.id)); if (this.settings.places.inbox && BDFDB.ArrayUtils.is(e.returnvalue.props.messages)) e.returnvalue.props.messages = e.returnvalue.props.messages.filter(n => !n || !n.author || !n.author.id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.author.id));
} }
processReactions (e) { processReactions (e) {
if (settings.removeReactions && e.returnvalue.props.children && BDFDB.ArrayUtils.is(e.returnvalue.props.children[0])) { if (this.settings.places.reactions && e.returnvalue.props.children && BDFDB.ArrayUtils.is(e.returnvalue.props.children[0])) {
let updateTimeout, relationshipCount = BDFDB.LibraryModules.RelationshipStore.getRelationshipCount(); let updateTimeout, relationshipCount = BDFDB.LibraryModules.RelationshipStore.getRelationshipCount();
if (cachedChannelId != e.instance.props.message.channel_id) { if (cachedChannelId != e.instance.props.message.channel_id) {
cachedReactions = {}; cachedReactions = {};
@ -313,11 +337,11 @@ module.exports = (_ => {
} }
processReactorsComponent (e) { processReactorsComponent (e) {
if (settings.removeReactions && BDFDB.ArrayUtils.is(e.instance.props.reactors)) e.instance.props.reactors = e.instance.props.reactors.filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id)); if (this.settings.places.reactions && BDFDB.ArrayUtils.is(e.instance.props.reactors)) e.instance.props.reactors = e.instance.props.reactors.filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id));
} }
processChannelMembers (e) { processChannelMembers (e) {
if (settings.removeUsers) { if (this.settings.places.members) {
e.instance.props.groups = [].concat(e.instance.props.groups); e.instance.props.groups = [].concat(e.instance.props.groups);
e.instance.props.rows = [].concat(e.instance.props.rows); e.instance.props.rows = [].concat(e.instance.props.rows);
let newRows = [], newGroups = []; let newRows = [], newGroups = [];
@ -351,46 +375,46 @@ module.exports = (_ => {
} }
processPrivateChannelRecipients (e) { processPrivateChannelRecipients (e) {
if (settings.removeVoiceChats && e.instance.props.channel && e.instance.props.channel.isGroupDM()) e.instance.props.channel = new BDFDB.DiscordObjects.Channel(Object.assign({}, e.instance.props.channel, {rawRecipients: e.instance.props.channel.rawRecipients.filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id)), recipients: e.instance.props.channel.recipients.filter(id => !id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(id))})); if (this.settings.places.voiceChat && e.instance.props.channel && e.instance.props.channel.isGroupDM()) e.instance.props.channel = new BDFDB.DiscordObjects.Channel(Object.assign({}, e.instance.props.channel, {rawRecipients: e.instance.props.channel.rawRecipients.filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id)), recipients: e.instance.props.channel.recipients.filter(id => !id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(id))}));
} }
processMemberListItem (e) { processMemberListItem (e) {
if (settings.removeUsers && e.instance.props.user && BDFDB.LibraryModules.RelationshipStore.isBlocked(e.instance.props.user.id)) return null; if (this.settings.places.members && e.instance.props.user && BDFDB.LibraryModules.RelationshipStore.isBlocked(e.instance.props.user.id)) return null;
} }
processVoiceUsers (e) { processVoiceUsers (e) {
if (settings.removeVoiceUser && BDFDB.ArrayUtils.is(e.instance.props.voiceStates)) e.instance.props.voiceStates = [].concat(e.instance.props.voiceStates).filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id)); if (this.settings.places.voiceList && BDFDB.ArrayUtils.is(e.instance.props.voiceStates)) e.instance.props.voiceStates = [].concat(e.instance.props.voiceStates).filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id));
} }
processVoiceUser (e) { processVoiceUser (e) {
if (settings.removeVoiceUser && e.instance.props.user && BDFDB.LibraryModules.RelationshipStore.isBlocked(e.instance.props.user.id)) return null; if (this.settings.places.voiceList && e.instance.props.user && BDFDB.LibraryModules.RelationshipStore.isBlocked(e.instance.props.user.id)) return null;
} }
processPrivateChannel (e) { processPrivateChannel (e) {
if (settings.removeUsers && e.instance.props.channel && e.instance.props.channel.isGroupDM()) e.instance.props.channel = new BDFDB.DiscordObjects.Channel(Object.assign({}, e.instance.props.channel, {rawRecipients: e.instance.props.channel.rawRecipients.filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id)), recipients: e.instance.props.channel.recipients.filter(id => !id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(id))})); if (this.settings.places.members && e.instance.props.channel && e.instance.props.channel.isGroupDM()) e.instance.props.channel = new BDFDB.DiscordObjects.Channel(Object.assign({}, e.instance.props.channel, {rawRecipients: e.instance.props.channel.rawRecipients.filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id)), recipients: e.instance.props.channel.recipients.filter(id => !id || !BDFDB.LibraryModules.RelationshipStore.isBlocked(id))}));
} }
processPrivateChannelCallParticipants (e) { processPrivateChannelCallParticipants (e) {
if (settings.removeVoiceChats && BDFDB.ArrayUtils.is(e.instance.props.participants)) e.instance.props.participants = [].concat(e.instance.props.participants).filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id)); if (this.settings.places.voiceChat && BDFDB.ArrayUtils.is(e.instance.props.participants)) e.instance.props.participants = [].concat(e.instance.props.participants).filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id));
} }
processChannelCall (e) { processChannelCall (e) {
if (settings.removeVoiceChats && BDFDB.ArrayUtils.is(e.instance.props.participants)) e.instance.props.participants = [].concat(e.instance.props.participants).filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id)); if (this.settings.places.voiceChat && BDFDB.ArrayUtils.is(e.instance.props.participants)) e.instance.props.participants = [].concat(e.instance.props.participants).filter(n => !n.user || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.user.id));
} }
processUserSummaryItem (e) { processUserSummaryItem (e) {
if (settings.removeUsers && BDFDB.ArrayUtils.is(e.instance.props.users)) e.instance.props.users = [].concat(e.instance.props.users).filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id)); if (this.settings.places.members && BDFDB.ArrayUtils.is(e.instance.props.users)) e.instance.props.users = [].concat(e.instance.props.users).filter(n => !n || !BDFDB.LibraryModules.RelationshipStore.isBlocked(n.id));
} }
processUserMention (e) { processUserMention (e) {
if (e.instance.props.userId && settings.removeMentions && BDFDB.LibraryModules.RelationshipStore.isBlocked(e.instance.props.userId)) return BDFDB.ReactUtils.createElement("span", { if (e.instance.props.userId && this.settings.places.mentions && BDFDB.LibraryModules.RelationshipStore.isBlocked(e.instance.props.userId)) return BDFDB.ReactUtils.createElement("span", {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.mention, BDFDB.disCN.mentionwrapper, e.instance.props.className), className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.mention, BDFDB.disCN.mentionwrapper, e.instance.props.className),
children: ["@" + BDFDB.LanguageUtils.LanguageStrings.UNKNOWN_USER] children: ["@" + BDFDB.LanguageUtils.LanguageStrings.UNKNOWN_USER]
}); });
} }
processRichUserMention (e) { processRichUserMention (e) {
if (e.instance.props.id && settings.removeMentions && BDFDB.LibraryModules.RelationshipStore.isBlocked(e.instance.props.id)) return BDFDB.ReactUtils.createElement("span", { if (e.instance.props.id && this.settings.places.mentions && BDFDB.LibraryModules.RelationshipStore.isBlocked(e.instance.props.id)) return BDFDB.ReactUtils.createElement("span", {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.mention, BDFDB.disCN.mentionwrapper, e.instance.props.className), className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.mention, BDFDB.disCN.mentionwrapper, e.instance.props.className),
children: ["@" + BDFDB.LanguageUtils.LanguageStrings.UNKNOWN_USER] children: ["@" + BDFDB.LanguageUtils.LanguageStrings.UNKNOWN_USER]
}); });