├── LICENSE ├── ThreatModal.js ├── index.js └── manifest.json /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Cynthia K. Rey, All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 2. Redistributions in binary form must reproduce the above copyright notice, 9 | this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | 3. Neither the name of the copyright holder nor the names of its contributors 12 | may be used to endorse or promote products derived from this software without 13 | specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | -------------------------------------------------------------------------------- /ThreatModal.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Cynthia K. Rey, All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. Neither the name of the copyright holder nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software without 14 | * specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | const { React, getModule, getModuleByDisplayName, modal } = require('powercord/webpack') 29 | const { AsyncComponent } = require('powercord/components') 30 | const { sleep } = require('powercord/util') 31 | 32 | module.exports = AsyncComponent.from((async () => { 33 | await sleep(1e3) 34 | 35 | const opener = await getModule((m) => m.show?.toString().includes('openModalLazy')) 36 | let promise; 37 | const ogOpenLazy = modal.openModalLazy; 38 | modal.openModalLazy = (a) => promise = a(); 39 | await opener.show() 40 | modal.openModalLazy = ogOpenLazy; 41 | await promise; 42 | 43 | const BlockedDomainModal = await getModuleByDisplayName('BlockedDomainModal') 44 | return React.memo( 45 | ({ user }) => { 46 | const vdom = BlockedDomainModal({ domain: '', transitionState: 1 }) 47 | vdom.props.children[1].props.children.props.children[0].props.children = 'Threat Mitigated' 48 | vdom.props.children[1].props.children.props.children[1].props.children = [ 'Userbot ', user, ' attempted to mass-add you to group DMs to clutter your Discord with hundreds of pings and spam groups in your DM list. The user has been blocked to stop the attack, and groups have been left. Stay safe, fren!' ] 49 | return vdom 50 | } 51 | ) 52 | })()) 53 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Cynthia K. Rey, All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * 1. Redistributions of source code must retain the above copyright notice, this 8 | * list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright notice, 10 | * this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 3. Neither the name of the copyright holder nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software without 14 | * specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | const { Plugin } = require('powercord/entities'); 29 | const { React, FluxDispatcher, getModule, constants: { RelationshipTypes } } = require('powercord/webpack'); 30 | const { open, close } = require('powercord/modal'); 31 | const ThreatModal = require('./ThreatModal'); 32 | 33 | const RelationshipManager = getModule([ 'addRelationship' ], false) 34 | const PrivateChannelsManager = getModule([ 'closePrivateChannel' ], false) 35 | 36 | class GroupDmNukeDefender extends Plugin { 37 | constructor () { 38 | super() 39 | 40 | this.recentAdds = new Map() 41 | this.messageQueued = new Set() 42 | this.handleChannelCreate = this.handleChannelCreate.bind(this) 43 | this.handleMessageCreate = this.handleMessageCreate.bind(this) 44 | } 45 | 46 | startPlugin () { 47 | FluxDispatcher.subscribe('CHANNEL_CREATE', this.handleChannelCreate) 48 | FluxDispatcher.subscribe('MESSAGE_CREATE', this.handleMessageCreate) 49 | } 50 | 51 | pluginWillUnload () { 52 | FluxDispatcher.unsubscribe('CHANNEL_CREATE', this.handleChannelCreate) 53 | FluxDispatcher.unsubscribe('MESSAGE_CREATE', this.handleMessageCreate) 54 | } 55 | 56 | handleChannelCreate ({ channel: { id, type } }) { 57 | if (type === 3) { 58 | this.messageQueued.add(id) 59 | } 60 | } 61 | 62 | handleMessageCreate ({ channelId, message: { type, author: { id, username, discriminator } } }) { 63 | if (type === 1 && this.messageQueued.has(channelId)) { 64 | this.messageQueued.delete(channelId) 65 | if (!this.recentAdds.has(id)) { 66 | this.recentAdds.set(id, new Set()) 67 | } 68 | 69 | const addedSet = this.recentAdds.get(id) 70 | addedSet.add(channelId) 71 | 72 | if (addedSet.size === 5) { // Strict equal, so if there are more groups we get added to we don't do it multiple times 73 | open(() => React.createElement(ThreatModal, { user: `${username}#${discriminator}`, onClose: () => close() })) 74 | RelationshipManager.addRelationship(id, { location: 'ContextMenu' }, RelationshipTypes.BLOCKED) 75 | .then(() => { 76 | // Leave groups 77 | const array = Array.from(addedSet) 78 | for (let i = 0; i < array.length; i++) { 79 | setTimeout(() => void PrivateChannelsManager.closePrivateChannel(array[i]), 1e3 + (1500 * i)) 80 | } 81 | 82 | // This is no longer necessary 83 | this.recentAdds.delete(id) 84 | }) 85 | } 86 | 87 | // Expire after 30 seconds 88 | setTimeout(() => { 89 | addedSet.delete(channelId) 90 | if (addedSet.size === 0) { 91 | this.recentAdds.delete(id) 92 | } 93 | }, 30e3) 94 | } 95 | } 96 | } 97 | 98 | module.exports = GroupDmNukeDefender 99 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Group DM Nuke Defender", 3 | "version": "1.0.0", 4 | "description": "Defends your account against the recent \"Group DM Nuke\" attack by actively blocking userbots adding you in many groups rapidly.", 5 | "author": "Cynthia", 6 | "license": "BSD-3-Clause" 7 | } 8 | --------------------------------------------------------------------------------