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

Commit

Permalink
feat: send blocked message attachements
Browse files Browse the repository at this point in the history
  • Loading branch information
wdhdev committed Jul 9, 2023
1 parent 915f3a9 commit e534549
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 88 deletions.
19 changes: 0 additions & 19 deletions src/events/client/rateLimit.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/sentry-api/endpoints/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Discord = require("discord.js");

const cap = require("../util/cap");
const cap = require("../../util/cap");
const parser = require("../util/parser");

const schema = require("../../models/sentrySchema");
Expand Down
2 changes: 1 addition & 1 deletion src/sentry-api/util/cap.js → src/util/cap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function (str, length) {
if(str == null || str?.length <= length) return str;

return str.substr(0, length - 1) + "\u2026";
return str.substr(0, length - 1) + "**\u2026**";
}
14 changes: 8 additions & 6 deletions src/util/filter/tests/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,27 @@ module.exports = async function(message, client, Discord) {

const blocked = new Discord.EmbedBuilder()
.setTitle("⛔ Message Blocked")
.setDescription(`${message.content}`)
.setDescription(message.content)
.addFields (
{ name: "🚩 Filter", value: "🔗 Links" },
{ name: "❓ Reason", value: `⚠️ \`${linkResult.links.join("\`\n⚠️ \`")}\`` }
{ name: "❓ Reason", value: `- \`${linkResult.links.join("\`\n- \`")}\`` }
)

let attachment = null;

if(message.attachments.first()) {
const fileExt = path.extname(message.attachments.first().url.toLowerCase());
const allowedExtensions = ["jpeg", "jpg", "png", "svg", "webp"];
const allowedExtensions = ["gif", "jpeg", "jpg", "png", "svg", "webp"];

if(allowedExtensions.includes(fileExt.split(".").join(""))) {
const attachment = await new Discord.MessageAttachment(attachment.url).fetch();
attachment = new Discord.AttachmentBuilder(message.attachments.first().url, { name: `attachment${fileExt}` });

blocked.setImage(`attachment://${attachment.name}`);
}
}

try {
await message.author.send({ embeds: [error] });
await message.author.send({ embeds: [blocked], files: attachment ? [attachment] : [] });
} catch {}

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}` });
Expand All @@ -55,7 +57,7 @@ module.exports = async function(message, client, Discord) {
.setEmoji("🔨")
)

blockedChannel.send({ embeds: [blocked], components: [actions] });
blockedChannel.send({ embeds: [blocked], components: [actions], files: attachment ? [attachment] : [] });
return true;
}

Expand Down
33 changes: 16 additions & 17 deletions src/util/filter/tests/phishing.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module.exports = async function(message, client, Discord) {
const bannedUserSchema = require("../../../models/bannedUserSchema");
const blockedSchema = require("../../../models/blockedSchema");
const devSchema = require("../../../models/devSchema");
const modSchema = require("../../../models/modSchema");
const verifiedSchema = require("../../../models/verifiedSchema");

const blockedChannel = client.channels.cache.get(client.config_channels.blocked);
const modLogsChannel = client.channels.cache.get(client.config_channels.modLogs);
Expand All @@ -30,31 +27,25 @@ module.exports = async function(message, client, Discord) {

const blocked = new Discord.EmbedBuilder()
.setTitle("⛔ Message Blocked")
.setDescription(`${message.content}`)
.setDescription(message.content)
.addFields (
{ name: "🚩 Filter", value: "🪝 Phishing" },
{ name: "❓ Reason", value: "⚠️ Phishing link detected." }
{ name: "❓ Reason", value: "Phishing link detected." }
)

let attachment = null;

if(message.attachments.first()) {
const fileExt = path.extname(message.attachments.first().url.toLowerCase());
const allowedExtensions = ["jpeg", "jpg", "png", "svg", "webp"];
const allowedExtensions = ["gif", "jpeg", "jpg", "png", "svg", "webp"];

if(allowedExtensions.includes(fileExt.split(".").join(""))) {
const attachment = await new Discord.MessageAttachment(attachment.url).fetch();
attachment = new Discord.AttachmentBuilder(message.attachments.first().url, { name: `attachment${fileExt}` });

blocked.setImage(`attachment://${attachment.name}`);
}
}

const actions = new Discord.ActionRowBuilder()
.addComponents (
new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Secondary)
.setCustomId(`blocked-message-info-${message.id}`)
.setEmoji("ℹ️")
)

const ban = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setTitle("Banned")
Expand All @@ -69,7 +60,7 @@ module.exports = async function(message, client, Discord) {
let sentDM = false;

try {
await message.author.send({ embeds: [blocked] });
await message.author.send({ embeds: [blocked], files: attachment ? [attachment] : [] });
await message.author.send({ embeds: [ban] });
sentDM = true;
} catch {}
Expand All @@ -79,7 +70,15 @@ module.exports = async function(message, client, Discord) {
{ name: "⚒️ Action", value: "🔨 Ban" }
)

blockedChannel.send({ embeds: [blocked], components: [actions] });
const actions = new Discord.ActionRowBuilder()
.addComponents (
new Discord.ButtonBuilder()
.setStyle(Discord.ButtonStyle.Secondary)
.setCustomId(`blocked-message-info-${message.id}`)
.setEmoji("ℹ️")
)

blockedChannel.send({ embeds: [blocked], components: [actions], files: attachment ? [attachment] : [] });

const banLog = new Discord.EmbedBuilder()
.setColor(client.config_embeds.default)
Expand Down
19 changes: 9 additions & 10 deletions src/util/filter/tests/profanity.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module.exports = async function(message, client, Discord) {
const bannedUserSchema = require("../../../models/bannedUserSchema");
const blockedSchema = require("../../../models/blockedSchema");
const devSchema = require("../../../models/devSchema");
const modSchema = require("../../../models/modSchema");
const verifiedSchema = require("../../../models/verifiedSchema");

const blockedChannel = client.channels.cache.get(client.config_channels.blocked);
const modLogsChannel = client.channels.cache.get(client.config_channels.modLogs);
Expand All @@ -22,18 +19,20 @@ module.exports = async function(message, client, Discord) {

const blocked = new Discord.EmbedBuilder()
.setTitle("⛔ Message Blocked")
.setDescription(`${message.content}`)
.setDescription(message.content)
.addFields (
{ name: "🚩 Filter", value: `🤬 Profanity (${profanityResult.filter.autoban ? "autoban" : "blacklist"})` },
{ name: "❓ Reason", value: `⚠️ \`${profanityResult.words.join("\`\n⚠️ \`")}\`` }
{ name: "❓ Reason", value: `- \`${profanityResult.words.join("\`\n- \`")}\`` }
)

let attachment = null;

if(message.attachments.first()) {
const fileExt = path.extname(message.attachments.first().url.toLowerCase());
const allowedExtensions = ["jpeg", "jpg", "png", "svg", "webp"];
const allowedExtensions = ["gif", "jpeg", "jpg", "png", "svg", "webp"];

if(allowedExtensions.includes(fileExt.split(".").join(""))) {
const attachment = await new Discord.AttachmentBuilder(attachment.url).fetch();
attachment = new Discord.AttachmentBuilder(message.attachments.first().url, { name: `attachment${fileExt}` });

blocked.setImage(`attachment://${attachment.name}`);
}
Expand Down Expand Up @@ -70,7 +69,7 @@ module.exports = async function(message, client, Discord) {
let sentDM = false;

try {
await message.author.send({ embeds: [blocked] });
await message.author.send({ embeds: [blocked], files: attachment ? [attachment] : [] });
await message.author.send({ embeds: [ban] });
sentDM = true;
} catch {}
Expand All @@ -94,7 +93,7 @@ module.exports = async function(message, client, Discord) {
modLogsChannel.send({ embeds: [banLog] });
} else {
try {
await message.author.send({ embeds: [blocked] });
await message.author.send({ embeds: [blocked], files: attachment ? [attachment] : [] });
} catch {}

actions.addComponents (
Expand All @@ -107,7 +106,7 @@ 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}` });

blockedChannel.send({ embeds: [blocked], components: [actions] });
blockedChannel.send({ embeds: [blocked], files: attachment ? [attachment] : [], components: [actions] });
return true;
}

Expand Down
53 changes: 19 additions & 34 deletions src/util/send.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = async function (message, client, Discord) {
const assignRoles = require("./roles/assign");
const cap = require("./cap");
const emoji = require("../config.json").emojis;
const path = require("path");
const role = await require("./roles/get")(message.author.id, client);
const test = require("./filter/test");

Expand All @@ -16,30 +18,37 @@ module.exports = async function (message, client, Discord) {

const blockedChannel = client.channels.cache.get(client.config_channels.blocked);

if(await bannedUserSchema.exists({ _id: message.author.id })) {
if(await bannedUserSchema.exists({ _id: message.author.id })) return

if(message.content.length > 2000) {
const blocked = new Discord.EmbedBuilder()
.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}` })
.setTitle("⛔ Message Blocked")
.setDescription(cap(message.content, 2000))
.addFields (
{ name: "❓ Reason", value: "🔨 Banned User" }
{ name: "❓ Reason", value: "Message is too long." }
)
.setTimestamp()

if(message.content.length) blocked.setDescription(message.content);
let attachment = null;

if(message.attachments.first()) {
const fileExt = path.extname(message.attachments.first().url.toLowerCase());
const allowedExtensions = ["jpeg", "jpg", "png", "svg", "webp"];
const allowedExtensions = ["gif", "jpeg", "jpg", "png", "svg", "webp"];

if(allowedExtensions.includes(fileExt.split(".").join(""))) {
const attachment = await new Discord.MessageAttachment(attachment.url).fetch();
attachment = new Discord.AttachmentBuilder(message.attachments.first().url, { name: `attachment${fileExt}` });

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

try {
await message.author.send({ embeds: [blocked], files: attachment ? [attachment] : [] });
} catch {}

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}` });

const info = new Discord.EmbedBuilder()
.addFields (
{ name: "🕰️ Timestamp", value: `<t:${Date.now().toString().slice(0, -3)}> (<t:${Date.now().toString().slice(0, -3)}:R>)` },
Expand All @@ -48,31 +57,7 @@ module.exports = async function (message, client, Discord) {
{ name: "🗄️ Guild ID", value: `${message.guild.id}` }
)

blockedChannel.send({ embeds: [blocked, info] });
return;
}

if(!message.content.length) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} Your media was not processed as the CDN is down.`)

try {
await message.author.send({ embeds: [error] });
} catch {}

return;
}

if(message.content.length >= 2048) {
const error = new Discord.EmbedBuilder()
.setColor(client.config_embeds.error)
.setDescription(`${emoji.cross} Your message can only contain less than 2048 characters!`)

try {
await message.author.send({ embeds: [error] });
} catch {}

blockedChannel.send({ embeds: [blocked, info], files: attachment ? [attachment] : [] });
return;
}

Expand Down Expand Up @@ -114,7 +99,7 @@ module.exports = async function (message, client, Discord) {
.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}` })
.setTimestamp()

if(message.content.length) chat.setDescription(`${message.content}`);
if(message.content.length) chat.setDescription(message.content);

await assignRoles(message.author, client, chat);

Expand Down Expand Up @@ -143,7 +128,7 @@ module.exports = async function (message, client, Discord) {
.setEmoji("🔨")
)

if(message.content.length >= 1) messageLog.setDescription(`${message.content}`);
if(message.content.length >= 1) messageLog.setDescription(message.content);

// Send Global Message
const messages = [];
Expand Down

0 comments on commit e534549

Please sign in to comment.