mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 16:30:58 -05:00
Update messageCreate.ts
This commit is contained in:
parent
c5267e265d
commit
f70cf80ebe
@ -3,16 +3,56 @@ import TClient from '../client';
|
|||||||
export default {
|
export default {
|
||||||
async run(client:TClient, message:Discord.Message){
|
async run(client:TClient, message:Discord.Message){
|
||||||
if (message.author.bot || message.channel.type === ChannelType.DM) return;
|
if (message.author.bot || message.channel.type === ChannelType.DM) return;
|
||||||
const msgarr = message.content.toLowerCase().split(' ');
|
const msgarr = message.content.toLowerCase().replaceAll('\n', ' ').split(' ');
|
||||||
let automodded: boolean;
|
let automodded: boolean;
|
||||||
|
|
||||||
function onTimeout(){
|
|
||||||
delete client.repeatedMessages[message.author.id]
|
|
||||||
}
|
|
||||||
|
|
||||||
const Whitelist = [] // Array of channel ids for automod to be disabled in (Disables bannedWords and advertisement, mind you.)
|
const Whitelist = [] // Array of channel ids for automod to be disabled in (Disables bannedWords and advertisement, mind you.)
|
||||||
|
|
||||||
if (await client.bannedWords._content.findOne({_id:msgarr}) && !message.member.roles.cache.has(client.config.mainServer.roles.dcmod) && message.guildId == client.config.mainServer.id && !Whitelist.includes(message.channelId) && client.config.botSwitches.automod){
|
async function repeatedMessages(thresholdTime:number, thresholdAmount:number, type:string, muteTime:string, muteReason:string){
|
||||||
|
if (client.repeatedMessages[message.author.id]){
|
||||||
|
// Add message to the list
|
||||||
|
client.repeatedMessages[message.author.id].data.set(message.createdTimestamp, {type, channel: message.channelId});
|
||||||
|
|
||||||
|
// Reset the timeout
|
||||||
|
clearTimeout(client.repeatedMessages[message.author.id].timeout);
|
||||||
|
client.repeatedMessages[message.author.id].timeout = setTimeout(()=>delete client.repeatedMessages[message.author.id], thresholdTime);
|
||||||
|
|
||||||
|
// Message sent after (now - threshold), so purge those that were sent earlier
|
||||||
|
client.repeatedMessages[message.author.id].data = client.repeatedMessages[message.author.id].data.filter((x,i)=>i>=Date.now() - thresholdTime);
|
||||||
|
|
||||||
|
// A spammed message is one that has been sent within the threshold parameters
|
||||||
|
const spammedMessage = client.repeatedMessages[message.author.id].data.find(x=>{
|
||||||
|
return client.repeatedMessages[message.author.id].data.filter(y=>x.type===y.type).size >= thresholdAmount;
|
||||||
|
});
|
||||||
|
if (spammedMessage){
|
||||||
|
delete client.repeatedMessages[message.author.id];
|
||||||
|
await client.punishments.addPunishment('mute', {time: muteTime}, (client.user as Discord.User).id, `Automod; ${muteReason}`, message.author, message.member as Discord.GuildMember);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
client.repeatedMessages[message.author.id] = {data: new client.collection(), timeout: setTimeout(()=>delete client.repeatedMessages[message.author.id], thresholdTime)};
|
||||||
|
client.repeatedMessages[message.author.id].data.set(message.createdTimestamp, {type, channel: message.channelId});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client.config.botSwitches.automod && !client.isStaff(message.member as Discord.GuildMember)){
|
||||||
|
if (await client.bannedWords._content.findById(msgarr) && !Whitelist.includes(message.channelId)){
|
||||||
|
automodded = true;
|
||||||
|
message.delete().catch(()=>console.log('bannedWords automod; msg got possibly deleted by another bot.'));
|
||||||
|
message.channel.send('That word isn\'t allowed here.').then(x=>setTimeout(()=>x.delete(), 10000));
|
||||||
|
await repeatedMessages(30000, 3, 'bw', '30m', 'Constant swearing');
|
||||||
|
} else if (message.content.toLowerCase().includes('discord.gg/') && !client.isStaff(message.member as Discord.GuildMember)){
|
||||||
|
const url = msgarr.find(x=>x.includes('discord.gg/'));
|
||||||
|
const validInvite = await client.fetchInvite(url).catch(()=>undefined);
|
||||||
|
if (validInvite && validInvite.guild?.id !== client.config.mainServer.id){
|
||||||
|
automodded = true;
|
||||||
|
message.delete().catch(()=>console.log('Advertisement automod; msg got possibly deleted by another bot.'));
|
||||||
|
message.channel.send('Please don\'t advertise other Discord servers.').then(x=>setTimeout(()=>x.delete(), 15000));
|
||||||
|
await repeatedMessages(60000, 2, 'adv', '1h', 'Discord advertisement');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if (await client.bannedWords._content.findOne({_id:msgarr}) && !message.member.roles.cache.has(client.config.mainServer.roles.dcmod) && message.guildId == client.config.mainServer.id && !Whitelist.includes(message.channelId) && client.config.botSwitches.automod){
|
||||||
automodded = true;
|
automodded = true;
|
||||||
const threshold = 30000;
|
const threshold = 30000;
|
||||||
message.delete().catch(err=>console.log('bannedWords automod; msg got possibly deleted by another bot.'))
|
message.delete().catch(err=>console.log('bannedWords automod; msg got possibly deleted by another bot.'))
|
||||||
@ -67,7 +107,7 @@ export default {
|
|||||||
client.repeatedMessages[message.author.id] = { data: new client.collection(), timeout: setTimeout(onTimeout, threshold) };
|
client.repeatedMessages[message.author.id] = { data: new client.collection(), timeout: setTimeout(onTimeout, threshold) };
|
||||||
client.repeatedMessages[message.author.id].data.set(message.createdTimestamp, {cont: 1, ch: message.channelId});
|
client.repeatedMessages[message.author.id].data.set(message.createdTimestamp, {cont: 1, ch: message.channelId});
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if (message.guildId == client.config.mainServer.id && !automodded) client.userLevels.incrementUser(message.author.id)
|
if (message.guildId == client.config.mainServer.id && !automodded) client.userLevels.incrementUser(message.author.id)
|
||||||
// Mop gifs from banned channels without Monster having to mop them.
|
// Mop gifs from banned channels without Monster having to mop them.
|
||||||
|
@ -45,7 +45,7 @@ export default class punishments extends Schema {
|
|||||||
}
|
}
|
||||||
// Send it off to specific Discord channel.
|
// Send it off to specific Discord channel.
|
||||||
(this.client.channels.cache.get(channel) as Discord.TextChannel).send({embeds:[embed]});
|
(this.client.channels.cache.get(channel) as Discord.TextChannel).send({embeds:[embed]});
|
||||||
}// hi tae --- hi
|
}// hi tae --- hi --- hru?
|
||||||
getTense(type:string){// Get past tense form of punishment type, grammar yes
|
getTense(type:string){// Get past tense form of punishment type, grammar yes
|
||||||
return {
|
return {
|
||||||
ban: 'banned',
|
ban: 'banned',
|
||||||
|
2
src/typings/interfaces.d.ts
vendored
2
src/typings/interfaces.d.ts
vendored
@ -14,7 +14,7 @@ export interface punOpt {
|
|||||||
interaction?: Discord.ChatInputCommandInteraction<"cached">
|
interaction?: Discord.ChatInputCommandInteraction<"cached">
|
||||||
}
|
}
|
||||||
export interface repeatedMessages {
|
export interface repeatedMessages {
|
||||||
[key:string]: {data: Discord.Collection<number,{cont:number,ch:string}>, timeout: NodeJS.Timeout}
|
[key:string]: {data: Discord.Collection<number,{type:string,channel:string}>, timeout: NodeJS.Timeout}
|
||||||
}
|
}
|
||||||
export interface Punishment {
|
export interface Punishment {
|
||||||
_id: number;
|
_id: number;
|
||||||
|
Loading…
Reference in New Issue
Block a user