Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-Santana-j committed Jun 16, 2024
1 parent 655abef commit 2519ec8
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions Discord/discordIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ module.exports = (Discord2, client) => {

//ticket
client.on('messageCreate', async message => {

try {
var DiscordServer = await client.guilds.cache.get(message.guildId);
var DiscordChannel = await DiscordServer.channels.cache.get(message.channelId)
Expand All @@ -73,6 +72,48 @@ module.exports = (Discord2, client) => {
})
}
}


//sistema de castigo
const SPAM_THRESHOLD = 3; // Número de menções
const TIME_WINDOW = 10000; // 10 segundos em milissegundos
const TIMEOUT_DURATION = 5 * 60 * 1000; // 5 minutos em milissegundos

if (message.author.bot) return; // Ignorar mensagens de bots

const mentionedUsers = message.mentions.users;
if (mentionedUsers.size === 0) return; // Ignorar se não houver menções

const authorId = message.author.id;
const channelId = message.channel.id;

for (const [mentionedUserId, mentionedUser] of mentionedUsers) {
if (mentionedUserId === authorId) continue; // Ignorar menções a si mesmo

try {
// Buscar mensagens recentes no canal
const messages = await message.channel.messages.fetch({ limit: 100 });
const now = Date.now();

// Filtrar mensagens para encontrar quantas vezes o autor mencionou o mesmo usuário
const recentMentions = messages.filter(
msg => msg.author.id === authorId &&
msg.mentions.users.has(mentionedUserId) &&
(now - msg.createdTimestamp < TIME_WINDOW)
);

if (recentMentions.size >= SPAM_THRESHOLD) {
// Colocar o usuário em timeout
const member = message.guild.members.cache.get(authorId);
if (member) {
await member.timeout(TIMEOUT_DURATION, `Menções excessivas a ${mentionedUser.username}`);
}
break;
}
} catch (err) {
console.error(`Erro ao processar menções:`, err);
}
}
}
} catch (error) {
// console.log(error);
Expand Down Expand Up @@ -805,7 +846,7 @@ module.exports = (Discord2, client) => {
];
let dataFormatada = `${dataAtual.getDate()} de ${meses[dataAtual.getMonth()]} de ${dataAtual.getFullYear()} às ${dataAtual.getHours()}:${dataAtual.getMinutes()}`;
let findMotivo = await serverData.ticketOptions.motivos.find(element => element.id == interaction.values[0])

DiscordChannelPublicLog.send({
embeds: [
new Discord.EmbedBuilder()
Expand Down Expand Up @@ -955,7 +996,7 @@ module.exports = (Discord2, client) => {
"Setembro", "Outubro", "Novembro", "Dezembro"
];
let dataFormatada = `${dataAtual.getDate()} de ${meses[dataAtual.getMonth()]} de ${dataAtual.getFullYear()} às ${dataAtual.getHours()}:${dataAtual.getMinutes()}`;

DiscordChannelPublicLog.send({
embeds: [
new Discord.EmbedBuilder()
Expand Down

0 comments on commit 2519ec8

Please sign in to comment.