Ad Block for Lightcord

This commit is contained in:
Jean Ouina 2020-05-23 19:22:51 +02:00
parent db57f94c27
commit 5ee0222762
4 changed files with 94 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -57,6 +57,7 @@ export const settings = {
"Disable BetterDiscord": {id: "bd-disable", info: "Disable Betterdiscord (plugins, themes, etc).", implemented: false, hidden: false, cat: "lightcord", category: "Lightcord"},
"Calling Ring Beat": {id: "lightcord-2", info: "Enable Discord's special calling beat.", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord"},
"Developer Options": {id: "lightcord-1", info: "Enable Discord's Internal Developer Options. This allow the \"Experiments\" tab and the \"Developer Options\" tab. (must close and reopen settings)", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord"},
"Ad Block": {id: "lightcord-4", info: "Block any BOT that dm you with an invite link. Even in an embed.", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord"},
/** Lightcord Window */
"Always-on-Top": {id: "lightcord-3", info: "Enable window's Always-on-Top mode, where Lightcord stays on top of other applications.", implemented: true, hidden: false, cat: "lightcord", category: "Window"},
@ -102,7 +103,7 @@ export const defaultCookie = {
"lightcord-2": true,
"lightcord-presence-1": false,
"lightcord-3": false,
"lightcord-4": true
"lightcord-4": false
};

View File

@ -0,0 +1,69 @@
import Utils from "./utils"
const dispatcher = window.Lightcord.DiscordModules.dispatcher
const ChannelModule = BDModules.get(e => e.default && e.default.getChannel && e.default.hasChannel)[0].default
const relationShipModule = BDModules.get(e => e.default && e.default.addRelationship)[0].default
const blocked = {}
export default new class AntiBotDM {
constructor(){
this.antiDM = this.antiDM.bind(this)
this.enabled = false
}
enable(){
if(this.enabled)return
this.enabled = true
dispatcher.subscribe("MESSAGE_CREATE", this.antiDM)
}
disable(){
if(!this.enabled)return
this.enabled = false
dispatcher.unsubscribe("MESSAGE_CREATE", this.antiDM)
}
antiDM(ev){
if(!ev.message.author.bot)return
if(ev.message.guild_id)return
const channel = ChannelModule.getChannel(ev.message.channel_id)
if(!channel)return // might be broken
if(channel.type !== 1)return
if(scanMessage(ev.message)){
Utils.showToast(`[AdBlock]: Blocked ${ev.message.author.username}#${ev.message.author.discriminator}`, {
"type": "warning"
})
relationShipModule.addRelationship(ev.message.author.id, {
location: "ContextMenu"
}, 2)
}
}
}
function scanMessage(message){
if(/(discord\.gg|discord\.com\/invite\/|discordapp\.com\/invite\/)/g.test(message.content))return true
if(EmbedsContains(message, "discord.gg/") || EmbedsContains(message, "discord.com/invite/") || EmbedsContains(message, "discordapp.com/invite/"))return true
return false
}
function EmbedsContains(message, search){
let embeds = message.embeds
if(embeds.length === 0)return false
return embeds.map(embed => {
if(embed.type !== "rich")return false
if(embed.title.includes(search))return true
if(embed.description.includes(search))return true
if(embed.footer.text.includes(search))return true
if(embed.fields.map(e => {
return e.value.includes(search) || e.name.includes(search)
}).includes(true))return true
return false
}).includes(true)
}

View File

@ -25,6 +25,7 @@ import V2C_PresenceSettings from "../ui/presenceSettings";
import CustomRichPresence from "./CustomRichPresence";
import V2C_AccountInfos from "../ui/AccountInfos";
import { remote } from "electron";
import AntiAdDM from "./AntiAdDM";
export default new class V2_SettingsPanel {
@ -220,6 +221,13 @@ export default new class V2_SettingsPanel {
if (enabled) remote.getCurrentWindow().setAlwaysOnTop(true)
else remote.getCurrentWindow().setAlwaysOnTop(false)
}
if (id === "lightcord-4") {
if(enabled){
AntiAdDM.enable()
}else{
AntiAdDM.disable()
}
}
this.saveSettings();
}
@ -238,6 +246,7 @@ export default new class V2_SettingsPanel {
if (settingsCookie["lightcord-2"]) window.Lightcord.Settings.callRingingBeat = true
if (settingsCookie["lightcord-presence-1"]) CustomRichPresence.enable()
if (settingsCookie["lightcord-3"]) remote.getCurrentWindow().setAlwaysOnTop(true)
if (settingsCookie["lightcord-4"]) AntiAdDM.enable()
if (settingsCookie["fork-ps-5"]) {
ContentManager.watchContent("plugin");