Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
feat: autoban filter
Browse files Browse the repository at this point in the history
  • Loading branch information
wdhdev committed Jun 24, 2023
1 parent a4d65ff commit b4ee09a
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 158 deletions.
159 changes: 43 additions & 116 deletions src/commands/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const modSchema = require("../models/modSchema");

module.exports = {
name: "filter",
description: "Manage the bot's filter.",
description: "Manage the bot's filters.",
options: [
{
type: 1,
Expand All @@ -20,54 +20,27 @@ module.exports = {
min_length: 3,
max_length: 64,
required: true
} // ,
},

// {
// type: 3,
// name: "filter",
// description: "The filter you want to add the word to.",
// choices: [
// {
// name: "block",
// description: "Add the word to the blocked words filter.",
// value: "block"
// },

// {
// name: "unblock",
// description: "Add the word to the unblocked words filter.",
// value: "unblock"
// }
// ],
// required: true
// }
]
},

{
type: 1,
name: "list",
description: "Get a list of all the words in a filter.",
options: [
// {
// type: 3,
// name: "filter",
// description: "The filter you want the list of.",
// choices: [
// {
// name: "block",
// description: "Get a list of the blocked words filter.",
// value: "block"
// },

// {
// name: "unblock",
// description: "Get a list of the blocked words filter.",
// value: "unblock"
// }
// ],
// required: true
// }
{
type: 3,
name: "filter",
description: "The filter you want to add the word to.",
choices: [
{
name: "block",
description: "Add the word to the blocked words filter.",
value: "block"
},

{
name: "autoban",
description: "Add the word to the autoban filter.",
value: "autoban"
}
],
required: true
}
]
},

Expand All @@ -83,27 +56,27 @@ module.exports = {
min_length: 3,
max_length: 64,
required: true
} // ,

// {
// type: 3,
// name: "filter",
// description: "The filter you want to remove the word from.",
// choices: [
// {
// name: "block",
// description: "Remove the word from the blocked words filter.",
// value: "block"
// },
},

// {
// name: "unblock",
// description: "Remove the word to from unblocked words filter.",
// value: "unblock"
// }
// ],
// required: true
// }
{
type: 3,
name: "filter",
description: "The filter you want to remove the word from.",
choices: [
{
name: "block",
description: "Remove the word from the blocked words filter.",
value: "block"
},

{
name: "autoban",
description: "Remove the word to from autoban filter.",
value: "autoban"
}
],
required: true
}
]
}
],
Expand All @@ -128,8 +101,7 @@ module.exports = {

if(interaction.options.getSubcommand() === "add") {
const word = interaction.options.getString("word");
// const filter = interaction.options.getString("filter");
const filter = "block";
const filter = interaction.options.getString("filter");

filterSchema.findOne({ _id: filter }, async (err, data) => {
if(data) {
Expand Down Expand Up @@ -172,54 +144,9 @@ module.exports = {
return;
}

// if(interaction.options.getSubcommand() === "list") {
// // const filter = interaction.options.getString("filter");
// const filter = "block";

// const data = await filterSchema.findOne({ _id: filter });

// if(!data) {
// const error = new Discord.EmbedBuilder()
// .setColor(client.config_embeds.error)
// .setDescription(`${emoji.error} There are no words on the filter!`)

// await interaction.editReply({ embeds: [error], ephemeral: true });
// return;
// }

// const filters = {
// "block": "Block",
// // "unblock": "Unblock"
// }

// const embed = new Discord.EmbedBuilder()
// .setColor(client.config_embeds.default)
// .setTitle(`${filters[filter]} Filter`)
// .setDescription(`\`${data.words.sort().join("\`, \`")}\``)

// try {
// await interaction.user.send({ embeds: [embed] });
// } catch {
// const error = new Discord.EmbedBuilder()
// .setColor(client.config_embeds.error)
// .setDescription(`${emoji.error} I could not DM you!`)

// await interaction.editReply({ embeds: [error], ephemeral: true });
// return;
// }

// const sent = new Discord.EmbedBuilder()
// .setColor(client.config_embeds.default)
// .setDescription(`${emoji.successful} Check your DMs!`)

// await interaction.editReply({ embeds: [sent] });
// return;
// }

if(interaction.options.getSubcommand() === "remove") {
const word = interaction.options.getString("word");
// const filter = interaction.options.getString("filter");
const filter = "block";
const filter = interaction.options.getString("filter");

filterSchema.findOne({ _id: filter }, async (err, data) => {
if(data) {
Expand Down
16 changes: 13 additions & 3 deletions src/util/filter/filters/profranity.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@ module.exports = async function profanity(message) {
const filterSchema = require("../../../models/filterSchema");
const replaceContent = require("../replaceContent");

const filter = await filterSchema.findOne({ _id: "block" });
const blockFilter = await filterSchema.findOne({ _id: "block" });
const autobanFilter = await filterSchema.findOne({ _id: "autoban" });

const content = replaceContent(message.content.toLowerCase());

const blockedWords = [];
let autoban = false;

filter.words.some(word => {
blockFilter.words.some(word => {
if(content.includes(word)) blockedWords.push(word);
})

autobanFilter.words.some(word => {
if(content.includes(word)) {
blockedWords.push(word);
autoban = true;
}
})

if(blockedWords.length) {
return {
"result": true,
"words": blockedWords
"words": blockedWords,
"autoban": autoban
}
} else {
return {
Expand Down
2 changes: 0 additions & 2 deletions src/util/filter/tests/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ module.exports = async function(message, client, Discord) {
const attachment = await new Discord.MessageAttachment(attachment.url).fetch();

blocked.setImage(`attachment://${attachment.name}`);
} else if(!message.content.length) {
return;
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/util/filter/tests/phishing.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ module.exports = async function(message, client, Discord) {
const attachment = await new Discord.MessageAttachment(attachment.url).fetch();

blocked.setImage(`attachment://${attachment.name}`);
} else if(!message.content.length) {
return;
}
}

Expand All @@ -77,9 +75,6 @@ module.exports = async function(message, client, Discord) {

blocked.setAuthor({ name: message.author.tag.endsWith("#0") ? `@${message.author.username}` : message.author.tag, iconURL: message.author.displayAvatarURL({ format: "png", dynamic: true }), url: `https://discord.com/users/${message.author.id}` });
blocked.setDescription(null);
blocked.addFields (
{ name: "🔨 Banned", value: "✅" }
)

const blockedInfo = new Discord.EmbedBuilder()
.addFields (
Expand Down
Loading

0 comments on commit b4ee09a

Please sign in to comment.