2023-12-24 10:21:40 -05:00
|
|
|
import Discord from 'discord.js';
|
|
|
|
import TClient from '../client.js';
|
|
|
|
import Logger from '../helpers/Logger.js';
|
|
|
|
export default class Automoderator {
|
|
|
|
private static lockQuery:Set<Discord.Snowflake> = new Set();
|
2024-01-16 06:41:30 -05:00
|
|
|
static scanMsg =(message:Discord.Message)=>message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b/g, '').split(' ').join('');
|
2024-01-29 01:46:28 -05:00
|
|
|
static async repeatedMessages(client:TClient, message:Discord.Message, action:'mute'|'ban', thresholdTime:number, thresholdAmount:number, type:string, duration:string, reason:string) {
|
2023-12-24 10:21:40 -05:00
|
|
|
const now = Date.now();
|
|
|
|
|
|
|
|
if (!client.repeatedMessages[message.author.id]) client.repeatedMessages[message.author.id] = {type: type, count:1, firstTime:now, timeout: null};
|
|
|
|
else {
|
|
|
|
const data = client.repeatedMessages[message.author.id];
|
|
|
|
if (now - data.firstTime < thresholdTime) {
|
|
|
|
// If the message is within the threshold time, increment.
|
|
|
|
data.count++;
|
|
|
|
if (data.count >= thresholdAmount) {
|
|
|
|
// If the count has reached the threshold amount, punish the user like most daddy would do to their child.
|
|
|
|
if (!this.lockQuery.has(message.author.id)) {
|
|
|
|
this.lockQuery.add(message.author.id);
|
2024-01-16 11:23:59 -05:00
|
|
|
Logger.console('log', 'AUTOMOD', `Lock acquired for ${message.author.tag} with reason: ${reason}`);
|
2024-01-29 01:46:28 -05:00
|
|
|
await client.punishments.punishmentAdd(action, {time: duration}, client.user.id, `AUTOMOD:${reason}`, message.author, message.member as Discord.GuildMember);
|
2023-12-24 10:21:40 -05:00
|
|
|
setTimeout(()=>{
|
|
|
|
this.lockQuery.delete(message.author.id);
|
2024-01-16 11:23:59 -05:00
|
|
|
Logger.console('log', 'AUTOMOD', `Lock released for ${message.author.tag}`);
|
2023-12-24 10:21:40 -05:00
|
|
|
}, 3500); // Wait 3.5 seconds before releasing the lock.
|
|
|
|
}
|
|
|
|
delete client.repeatedMessages[message.author.id];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If the message is outside the threshold time, reset the count and timestamp.
|
|
|
|
data.count = 1;
|
|
|
|
data.firstTime = now;
|
|
|
|
}
|
|
|
|
// Reset the timer.
|
|
|
|
clearTimeout(data.timeout);
|
|
|
|
data.timeout = setTimeout(()=>delete client.repeatedMessages[message.author.id], thresholdTime);
|
|
|
|
}
|
|
|
|
}
|
2024-01-10 17:19:39 -05:00
|
|
|
static async imageOnly(message:Discord.Message) {
|
|
|
|
const io_channels = ['468896467688620032'];
|
|
|
|
let deleteReason:string = 'This is an image-only channel and your message did not contain any images.';
|
|
|
|
if (io_channels.includes(message.channelId) && message.attachments.size < 1 && message.attachments.every(x=>!x.contentType.includes('image/'))) await message.delete().then(()=>message.channel.send(deleteReason).then((msg:Discord.Message)=>setTimeout(()=>msg.delete(), 8000)));
|
|
|
|
}
|
2023-12-24 10:21:40 -05:00
|
|
|
}
|