Skip to content

Commit

Permalink
Added profanity filter system
Browse files Browse the repository at this point in the history
System enforced on gi command due to some uh incidents
  • Loading branch information
Prakhar896 committed Jun 9, 2021
1 parent efb0cb1 commit f4437cd
Show file tree
Hide file tree
Showing 48 changed files with 8,951 additions and 4,431 deletions.
48 changes: 33 additions & 15 deletions commands/gi.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ const fortniteAPI = require('fortnite-api-com');
const triviaDB = require('triviadb')
const fs = require('fs')
var Scraper = require('images-scraper');
const Filter = require('bad-words');
var filter = new Filter()

const google = new Scraper({
puppeteer: {
headless: true
}
})

filter.removeWords('shit', 'bitch');

module.exports = {
name: 'gi',
description: 'Provides a random Google Image from the internet on a given subject.',
Expand All @@ -26,26 +30,40 @@ module.exports = {
image_query = 'memes'
} else if (image_query == 'help') {
let giEmbed = new Discord.MessageEmbed()
.setTitle('Google Images Command Help')
.addField('Command Format', 'pr!gi <query, e.g food (this is optional)>')
.setFooter('Default query is memes')
.setColor('AQUA')
.setThumbnail('https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2F7%2F77%2FGoogle_Images_2015_logo.svg%2F1200px-Google_Images_2015_logo.svg.png&f=1&nofb=1');
msg.channel.send(giEmbed)
.setTitle('Google Images Command Help')
.addField('Command Format', 'pr!gi <query, e.g food (this is optional)>')
.setFooter('Default query is memes')
.setColor('AQUA')
.setThumbnail('https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2F7%2F77%2FGoogle_Images_2015_logo.svg%2F1200px-Google_Images_2015_logo.svg.png&f=1&nofb=1');
msg.channel.send(giEmbed)
return
}
msg.reply(`Please wait a second while I get a random image from online, with the subject **${image_query}**`)

const image_results = await google.scrape(image_query, 200);
var img = image_results[Math.floor((Math.random() * image_results.length) + 1)]
if (img) {
msg.channel.send(img.url)
//profanity check
if (guildData.giProfanityFilterEnabled) {
if (filter.isProfane(image_query)) {
await msg.channel.send(':negative_squared_cross_mark: Profanity filter on this server is enabled. Please remove profane words from your query.')
return
} else {
sendImage(image_query, msg)
}
} else {
sendImage(image_query, msg)
}
}
}
async function sendImage(image_query, msg) {
msg.reply(`Please wait a second while I get a random image from online, with the subject **${image_query}**`)

const image_results = await google.scrape(image_query, 200);
var img = image_results[Math.floor((Math.random() * image_results.length) + 1)]
if (img) {
msg.channel.send(img.url)
.catch(err => {
console.log('Error in sending URL of image: ' + err)
})
} else {
msg.channel.send('Sorry, could not find an image on that query.')
}
return
} else {
msg.channel.send('Sorry, could not find an image on that query.')
}
return
}
17 changes: 17 additions & 0 deletions commands/ss.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = {
.addField('Main Role', `${mainRoleStatus}`)
.addField('Mute Role', `${muteRoleStatus}`)
.addField('Logging Of Deleted Messages', `${guildData.allowsDeleting}`)
.addField('Google Images Profanity Filter Enabled:', `${guildData.giProfanityFilterEnabled}`)
.setFooter(`Requested by Admin: ${msg.author.tag} in #${msg.channel.name}`);
if (logChannelStatus != 'Not Set') {
ssCurrentEmbed.addField('Log Channel', `<#${msg.guild.channels.cache.get(logChannelStatus).id}>`);
Expand Down Expand Up @@ -159,6 +160,7 @@ module.exports = {
.addField('Spaces Replaced With % Formatting', 'In this bot, most commands have this style of formatting where spaces are replaced with the % sign, like pr!initiatespam hello%there 10 <channel ID>. This is to allow the bot to register commands quickly and properly and execute them as quickly as possible.', true)
.addField('pr!ss setdeletelogs <true or false>', 'This setting allows you to control whether the bot should report the deletion of messages throughout the server to the log channel. true means you allow and false means you don\'t')
.addField('pr!ss create.suggest', 'Creates a suggestion channel in the server for the pr!suggest command. Please do not rename this channel but you can change its permissions as you like.')
.addField('pr!ss profanity filter <true | false>', 'Turn on or off a profanity filter on the search queries I search to mitigate explicit media being sent.')
.setFooter('Do pr!cmdlist to view the full list of commands that can be executed.')
msg.channel.send(ssHelpEmbed)
} else if (ssParam == 'autosetup') {
Expand Down Expand Up @@ -265,6 +267,21 @@ module.exports = {
var currentGuildData = guildData
currentGuildData.autorolesEnabled = true
return currentGuildData
} else if (ssParam == 'profanityfilter') {
var trueOrFalse = args[2]
if (!trueOrFalse) return msg.reply('Please state whether you would like to enable (true) or disable (false) the Profanity Filter system.')
if (trueOrFalse == 'true') {
trueOrFalse = true
} else if (trueOrFalse == 'false') {
trueOrFalse = false
} else {
msg.reply('Invalid response. Only \`true\` and \`false\` are accepted.')
return
}
var currentGuildData = guildData
currentGuildData.giProfanityFilterEnabled = trueOrFalse
msg.reply(`Set the Profanity Filter system\'s status to \`${trueOrFalse}\` successfully`)
return currentGuildData
}
return guildData
}
Expand Down
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ bot.on('ready', () => {
console.log('Fetching Invites Error: ' + err)
})
//Setting guilds and their info
guilds.push({ id: guild.id, name: guild.name, logChannel: undefined, mainRole: '', muteRole: '', allowsDeleting: false, autorolesEnabled: false })
guilds.push({ id: guild.id, name: guild.name, logChannel: undefined, mainRole: '', muteRole: '', allowsDeleting: false, autorolesEnabled: false, giProfanityFilterEnabled: false })
})
let backEndChannel = bot.guilds.cache.get('805723501544603658').channels.cache.get('805733098297360406')
backEndChannel.send('Would you like to autoset guild data to custom guilds?')
//collector, for now, just autoset but itself
//collector, for now, just autoset by itself
var index = 0
for (const guildData of guilds) {
if (guildData.id == '773172065263943701') {
Expand All @@ -122,13 +122,15 @@ bot.on('ready', () => {
guilds[index].muteRole = ''
guilds[index].allowsDeleting = false
guilds[index].autorolesEnabled = false
guilds[index].giProfanityFilterEnabled = true
} else if (guildData.id == '807599800379768862') {
//3r4, discord's better than whatsapp
guilds[index].logChannel = '807615806988746783'
guilds[index].mainRole = 'verified'
guilds[index].muteRole = 'muted'
guilds[index].allowsDeleting = true
guilds[index].autorolesEnabled = true
guilds[index].giProfanityFilterEnabled = true
} else if (guildData.id == '696270592135135242') {
//NASS Robotics
guilds[index].logChannel = '812321866923376670'
Expand All @@ -137,12 +139,13 @@ bot.on('ready', () => {
guilds[index].allowsDeleting = true
guilds[index].autorolesEnabled = true
} else if (guildData.id == '805723501544603658') {
//Backend Server: idk
//Backend Server
guilds[index].logChannel = '805733098297360406'
guilds[index].mainRole = 'ma homie'
guilds[index].muteRole = 'stfu'
guilds[index].allowsDeleting = true
guilds[index].autorolesEnabled = true
guilds[index].giProfanityFilterEnabled = true
} else if (guildData.id == '815050446766080040') {
//Running Server
guilds[index].logChannel = '815094333799006218'
Expand Down Expand Up @@ -248,6 +251,7 @@ bot.on('message', msg => {
let serverIndex = guilds.findIndex(guildData => guildData.id === msg.guild.id)
if (serverIndex == undefined || serverIndex == -1) return msg.reply('There was a data error. This server is not in my backend servers list. Please contact my developers.')
console.log(`Message occurred, guild info: ${guilds[serverIndex]}`)

//Access guildData using params: msg, args, guildData, Prefix, bot, Discord
switch (args[0]) {
case 'clear':
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit f4437cd

Please sign in to comment.