2020-05-23 19:22:51 +02:00
|
|
|
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
|
2020-05-30 15:12:10 +02:00
|
|
|
let relationShipModule = BDModules.get(e => e.default && e.default.addRelationship)[0]
|
|
|
|
let DMModule = BDModules.get(e => e.default && e.default.closePrivateChannel)[0]
|
2020-05-23 19:22:51 +02:00
|
|
|
|
|
|
|
const blocked = {}
|
|
|
|
|
2020-06-06 21:10:14 +02:00
|
|
|
let userModule = BDModules.get(e => e.default && e.default.getCurrentUser)[0]
|
|
|
|
function getCurrentUser(){
|
|
|
|
if(userModule)return userModule.default.getCurrentUser()
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2020-05-23 19:22:51 +02:00
|
|
|
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
|
2020-06-06 21:10:14 +02:00
|
|
|
if(ev.message.author.id === getCurrentUser().id)
|
2020-05-23 19:22:51 +02:00
|
|
|
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
|
|
|
|
|
2020-05-23 22:48:42 +02:00
|
|
|
if(blocked[ev.message.author.id])return // If the user unblock the bot, Don't block it again.
|
|
|
|
|
2020-05-23 19:22:51 +02:00
|
|
|
if(scanMessage(ev.message)){
|
2020-05-23 22:48:42 +02:00
|
|
|
blocked[ev.message.author.id] = true
|
2020-05-23 19:22:51 +02:00
|
|
|
Utils.showToast(`[AdBlock]: Blocked ${ev.message.author.username}#${ev.message.author.discriminator}`, {
|
|
|
|
"type": "warning"
|
|
|
|
})
|
2020-05-30 15:12:10 +02:00
|
|
|
if(!relationShipModule)relationShipModule = BDModules.get(e => e.default && e.default.addRelationship)[0]
|
|
|
|
relationShipModule.default.addRelationship(ev.message.author.id, {
|
2020-05-23 19:22:51 +02:00
|
|
|
location: "ContextMenu"
|
|
|
|
}, 2)
|
2020-05-30 15:12:10 +02:00
|
|
|
if(!DMModule)DMModule = BDModules.get(e => e.default && e.default.closePrivateChannel)[0]
|
|
|
|
DMModule.default.closePrivateChannel(channel.id, false)
|
2020-05-23 19:22:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-05-23 22:48:42 +02:00
|
|
|
if((embed.title || "").includes(search))return true
|
|
|
|
if((embed.description || "").includes(search))return true
|
|
|
|
if(((embed.footer || "") && embed.footer.text || "").includes(search))return true
|
2020-05-23 19:22:51 +02:00
|
|
|
if(embed.fields.map(e => {
|
|
|
|
return e.value.includes(search) || e.name.includes(search)
|
|
|
|
}).includes(true))return true
|
|
|
|
return false
|
|
|
|
|
|
|
|
}).includes(true)
|
|
|
|
}
|