1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 08:20:58 -05:00

i hope i did it right. (Sync from TAEMBO/IRTGaming-bot)

This commit is contained in:
AnxietyisReal 2023-02-16 19:48:24 +11:00
parent dd1ac87666
commit 4c545fac07
3 changed files with 28 additions and 25 deletions

View File

@ -1,7 +1,7 @@
import Discord, { Client, WebhookClient, GatewayIntentBits, Partials } from 'discord.js'; import Discord, { Client, WebhookClient, GatewayIntentBits, Partials } from 'discord.js';
import fs from 'node:fs'; import fs from 'node:fs';
import timeNames from './timeNames'; import timeNames from './timeNames';
import { Punishment, formatTimeOpt, Tokens, Config } from './typings/interfaces'; import { Punishment, formatTimeOpt, Tokens, Config, repeatedMessages } from './typings/interfaces';
import { bannedWords, bonkCount, userLevels, punishments } from './schoolClassroom'; import { bannedWords, bonkCount, userLevels, punishments } from './schoolClassroom';
import MPDB from './models/MPServer'; import MPDB from './models/MPServer';
import axios from 'axios'; import axios from 'axios';
@ -38,7 +38,7 @@ export default class TClient extends Client {
punishments: punishments; punishments: punishments;
bonkCount: bonkCount; bonkCount: bonkCount;
bannedWords: bannedWords; bannedWords: bannedWords;
repeatedMessages: any; repeatedMessages: repeatedMessages;
statsGraph: number; statsGraph: number;
constructor(){ constructor(){

View File

@ -20,21 +20,21 @@ export default {
message.channel.send('That word is banned here.').then((x)=>setTimeout(()=>x.delete(), 5000)); message.channel.send('That word is banned here.').then((x)=>setTimeout(()=>x.delete(), 5000));
if (client.repeatedMessages[message.author.id]){ if (client.repeatedMessages[message.author.id]){
// add this message to the list // add this message to the list
client.repeatedMessages[message.author.id].set(message.createdTimestamp, {cont: 0, ch: message.channelId}); client.repeatedMessages[message.author.id].data.set(message.createdTimestamp, {cont: 0, ch: message.channelId});
// reset timeout // reset timeout
clearTimeout(client.repeatedMessages[message.author.id].to); clearTimeout(client.repeatedMessages[message.author.id].timeout);
client.repeatedMessages[message.author.id].to = setTimeout(onTimeout, 30000); client.repeatedMessages[message.author.id].timeout = setTimeout(onTimeout, 30000);
// this is the time in which 4 messages have to be sent, in milliseconds (ms) // this is the time in which 4 messages have to be sent, in milliseconds (ms)
const threshold = 30000; const threshold = 30000;
// message mustve been sent after (now - threshold), so purge those that were sent earlier // message mustve been sent after (now - threshold), so purge those that were sent earlier
client.repeatedMessages[message.author.id] = client.repeatedMessages[message.author.id].filter((x, i)=>i >= Date.now() - threshold) client.repeatedMessages[message.author.id].data = client.repeatedMessages[message.author.id].data.filter((x, i)=>i >= Date.now() - threshold)
// a spammed message is one that has been sent atleast 4 times in the last threshold milliseconds // a spammed message is one that has been sent atleast 4 times in the last threshold milliseconds
const spammedMessage = client.repeatedMessages[message.author.id]?.find((x)=>{ const spammedMessage = client.repeatedMessages[message.author.id]?.data.find((x)=>{
return client.repeatedMessages[message.author.id].size >= 4; return client.repeatedMessages[message.author.id].data.size >= 4;
}); });
// if a spammed message exists; // if a spammed message exists;
@ -46,9 +46,9 @@ export default {
} }
} else { } else {
client.repeatedMessages[message.author.id] = new client.collection(); client.repeatedMessages[message.author.id] = new client.collection();
client.repeatedMessages[message.author.id].set(message.createdTimestamp, {cont: 0, ch: message.channelId}); client.repeatedMessages[message.author.id].data.set(message.createdTimestamp, {cont: 0, ch: message.channelId});
// autodelete after 30 secs // autodelete after 30 secs
client.repeatedMessages[message.author.id].to = setTimeout(onTimeout, 30000); client.repeatedMessages[message.author.id].timeout = setTimeout(onTimeout, 30000);
} }
} }
if (message.content.toLowerCase().includes('discord.gg/') && !message.member.roles.cache.has(client.config.mainServer.roles.dcmod) && message.guildId == client.config.mainServer.id && !Whitelist.includes(message.channelId)) { if (message.content.toLowerCase().includes('discord.gg/') && !message.member.roles.cache.has(client.config.mainServer.roles.dcmod) && message.guildId == client.config.mainServer.id && !Whitelist.includes(message.channelId)) {
@ -56,14 +56,14 @@ export default {
message.delete().catch(err=>console.log('advertisement automod; msg got possibly deleted by another bot.')) message.delete().catch(err=>console.log('advertisement automod; msg got possibly deleted by another bot.'))
message.channel.send('Advertising other Discord servers is not allowed.').then(x=>setTimeout(()=>x.delete(), 10000)) message.channel.send('Advertising other Discord servers is not allowed.').then(x=>setTimeout(()=>x.delete(), 10000))
if (client.repeatedMessages[message.author.id]){ if (client.repeatedMessages[message.author.id]){
client.repeatedMessages[message.author.id].set(message.createdTimestamp,{cont:1,ch:message.channelId}); client.repeatedMessages[message.author.id].data.set(message.createdTimestamp,{cont:1,ch:message.channelId});
clearTimeout(client.repeatedMessages[message.author.id].to); clearTimeout(client.repeatedMessages[message.author.id].timeout);
client.repeatedMessages[message.author.id].to = setTimeout(onTimeout, 60000); client.repeatedMessages[message.author.id].timeout = setTimeout(onTimeout, 60000);
const threshold = 60000; const threshold = 60000;
client.repeatedMessages[message.author.id] = client.repeatedMessages[message.author.id].filter((x:any, i:number)=> i >= Date.now() - threshold) client.repeatedMessages[message.author.id].data = client.repeatedMessages[message.author.id].data.filter((x, i)=> i >= Date.now() - threshold)
const spammedMessage = client.repeatedMessages[message.author.id]?.find((x:any)=>{ const spammedMessage = client.repeatedMessages[message.author.id]?.data.find((x)=>{
return client.repeatedMessages[message.author.id].filter((y:any)=>x.cont === y.cont).size >= 4; return client.repeatedMessages[message.author.id].data.filter((y)=>x.cont === y.cont).size >= 4;
}); });
if (spammedMessage){ if (spammedMessage){
@ -72,8 +72,8 @@ export default {
} }
}else{ }else{
client.repeatedMessages[message.author.id] = new client.collection(); client.repeatedMessages[message.author.id] = new client.collection();
client.repeatedMessages[message.author.id].set(message.createdTimestamp, {cont: 1, ch: message.channelId}); client.repeatedMessages[message.author.id].data.set(message.createdTimestamp, {cont: 1, ch: message.channelId});
client.repeatedMessages[message.author.id].to = setTimeout(onTimeout, 60000); client.repeatedMessages[message.author.id].timeout = setTimeout(onTimeout, 60000);
} }
} }

View File

@ -1,4 +1,4 @@
import Discord, { ColorResolvable } from 'discord.js'; import Discord from 'discord.js';
export interface UserLevels { export interface UserLevels {
messages: number, messages: number,
@ -13,6 +13,9 @@ export interface punOpt {
reason?: string, reason?: string,
interaction?: Discord.ChatInputCommandInteraction<"cached"> interaction?: Discord.ChatInputCommandInteraction<"cached">
} }
export interface repeatedMessages {
[key:string]: {data: Discord.Collection<number,{cont:number,ch:string}>, timeout: NodeJS.Timeout}
}
export interface Punishment { export interface Punishment {
id: number; id: number;
type: string; type: string;
@ -127,12 +130,12 @@ export interface Tokens {
webhook_url_test: string webhook_url_test: string
} }
export interface Config { export interface Config {
embedColor: ColorResolvable, embedColor: Discord.ColorResolvable,
embedColorGreen: ColorResolvable, embedColorGreen: Discord.ColorResolvable,
embedColorYellow: ColorResolvable, embedColorYellow: Discord.ColorResolvable,
embedColorRed: ColorResolvable, embedColorRed: Discord.ColorResolvable,
embedColorBCA: ColorResolvable, embedColorBCA: Discord.ColorResolvable,
embedColorXmas: ColorResolvable, embedColorXmas: Discord.ColorResolvable,
LRSstart: number, LRSstart: number,
whitelistedServers: Array<string>, whitelistedServers: Array<string>,
botSwitches: botSwitches, botSwitches: botSwitches,