1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-12-26 11:45:37 -05:00

Clean up some of the stuff

This commit is contained in:
toast-ts 2024-02-25 20:01:04 +11:00
parent 97fc6b6389
commit a48c8441b9
5 changed files with 20 additions and 20 deletions

View File

@ -8,7 +8,7 @@
"url": "git+https://github.com/toast-ts/Daggerbot-TS.git"
},
"scripts": {
"dev": "yarn tsc && yarn node . src/DB-Beta.config.json daggerbotbeta",
"dev": "yarn tsc && yarn node . src/DB-Beta.config.json daggerbotbeta true",
"sdk": "yarn dlx @yarnpkg/sdks vscode"
},
"author": "Toast",

View File

@ -2,6 +2,7 @@ import Discord from 'discord.js';
import TClient from '../client.js';
import Logger from '../helpers/Logger.js';
export default class Automoderator {
private static logPrefix:string = 'Automod';
private static lockQuery:Set<Discord.Snowflake> = new Set();
static scanMsg =(message:Discord.Message)=>message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b|ed\b/g, '').split(' ').join('');
static async repeatedMessages(client:TClient, message:Discord.Message, action:'mute'|'ban'|'softban', thresholdTime:number, thresholdAmount:number, type:string, duration:string, reason:string) {
@ -17,11 +18,11 @@ export default class Automoderator {
// 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);
Logger.console('log', 'AUTOMOD', `Lock acquired for ${message.author.tag} with reason: ${reason}`);
Logger.console('log', this.logPrefix, `Lock acquired for ${message.author.tag} with reason: ${reason}`);
await client.punishments.punishmentAdd(action, {time: duration}, client.user.id, `AUTOMOD:${reason}`, message.author, message.member as Discord.GuildMember);
setTimeout(()=>{
this.lockQuery.delete(message.author.id);
Logger.console('log', 'AUTOMOD', `Lock released for ${message.author.tag}`);
Logger.console('log', this.logPrefix, `Lock released for ${message.author.tag}`);
}, 3500); // Wait 3.5 seconds before releasing the lock.
}
delete client.repeatedMessages[message.author.id];

View File

@ -4,22 +4,23 @@ import TSClient from '../helpers/TSClient.js';
const postgresUri = (await TSClient()).postgres_uri;
export default class DatabaseServer {
private static logPrefix:string = 'Database';
public static seq:Sequelize = new Sequelize(postgresUri, {dialect: 'postgres', logging: false, ssl: false, pool: {max: 10, min: 0, acquire: 15000, idle: 8000}})
public static async init() {
try {
await this.seq.authenticate();
this.healthCheck();
} catch {
Logger.console('error', 'Database', 'Cannot initialize Sequelize -- is PostgreSQL running?');
Logger.console('error', this.logPrefix, 'Cannot initialize Sequelize -- is PostgreSQL running?');
process.exit(1);
}
}
private static async healthCheck() {
try {
await this.seq.query('SELECT 1');
Logger.console('log', 'Database', 'Connection to PostgreSQL has been established');
Logger.console('log', this.logPrefix, 'Connection to PostgreSQL has been established');
} catch {
Logger.console('error', 'Database', 'Connection to PostgreSQL has been lost');
Logger.console('error', this.logPrefix, 'Connection to PostgreSQL has been lost');
}
}
}

View File

@ -15,21 +15,22 @@ export default class MessageCreate {
if (client.config.botSwitches.automod && !message.member?.roles.cache.has(client.config.dcServer.roles.dcmod) && !message.member?.roles.cache.has(client.config.dcServer.roles.admin) && message.guildId === client.config.dcServer.id) {
const automodFailReason = 'msg got possibly deleted by another bot.';
const automodLog = 'Automod:';
const automodRules = {
phishingDetection: {
check: async()=>await __PRIVATE__.phishingDetection(message),
action: async()=>{
automodded = true;
message.delete().catch(()=>Logger.console('log', 'AUTOMOD:PHISHING', automodFailReason));
message.delete().catch(()=>Logger.console('log', `${automodLog}Phishing`, automodFailReason));
message.channel.send('Phishing links aren\'t allowed here. Nice try though!').then(msg=>setTimeout(()=>msg.delete(), 15000));
await Automoderator.repeatedMessages(client, message, 'softban', 60000, 3, 'phish', '15m', 'Phishing/scam link');
await Automoderator.repeatedMessages(client, message, 'softban', 60000, 3, 'phish', '15m', 'Phishing scam link');
}
},
prohibitedWords: {
check: async()=>await client.prohibitedWords.findWord(Automoderator.scanMsg(message)),
action: async()=>{
automodded = true;
message.delete().catch(()=>Logger.console('log', 'AUTOMOD:PROHIBITEDWORDS', automodFailReason));
message.delete().catch(()=>Logger.console('log', `${automodLog}ProhibitedWords`, automodFailReason));
message.channel.send('That word isn\'t allowed here.').then(x=>setTimeout(()=>x.delete(), 15000));
await Automoderator.repeatedMessages(client, message, 'mute', 30000, 3, 'bw', '30m', 'Prohibited word spam');
}
@ -40,7 +41,7 @@ export default class MessageCreate {
const validInvite = await client.fetchInvite(message.content.split(' ').find(x=>x.includes('discord.gg/'))).catch(()=>null);
if (validInvite && validInvite.guild?.id !== client.config.dcServer.id) {
automodded = true;
message.delete().catch(()=>Logger.console('log', 'AUTOMOD:ADVERTISEMENT', automodFailReason));
message.delete().catch(()=>Logger.console('log', `${automodLog}Advertisement`, automodFailReason));
message.channel.send('Please don\'t advertise other Discord servers.').then(x=>setTimeout(()=>x.delete(), 15000));
await Automoderator.repeatedMessages(client, message, 'ban', 60000, 4, 'adv', null, 'Discord advertisement');
}

View File

@ -21,7 +21,7 @@ process.on('unhandledRejection', (error: Error)=>_(error, 'unhandledRejection'))
process.on('uncaughtException', (error: Error)=>_(error, 'uncaughtException'));
process.on('error', (error: Error)=>_(error, 'processError'));
client.on('error', (error: Error)=>_(error, 'clientError'));
if (process.argv[3] ?? null) client.on('debug', console.log);
if ((typeof process.argv[4] === 'string' && process.argv[4] === 'true') ?? null) client.on('debug', console.log);
// Interval timers for modules
setInterval(async()=>await MPModule(client), refreshTimerSecs);
@ -33,9 +33,8 @@ setInterval(async()=>{
for await (const thread of forum.threads.cache.values()) {
await thread.messages.fetch();
if (!thread.archived && thread.lastMessage.createdTimestamp <= Date.now() - 1555200000) {// check if thread is inactive for over 18 days
await thread.setLocked(true).catch(()=>null);
await thread.setArchived(true, 'Inactive for over 18 days').catch(()=>null);
Logger.console('log', 'ThreadTimer', `${thread.name} has been archived and locked due to inactivity`);
await thread.delete('Thread has been inactive for 18 days');
Logger.console('log', 'ThreadTimer', `"#${thread.name}" has been deleted due to inactivity for 18 days`);
}
}
}, 1200000); // 20 minutes
@ -100,15 +99,13 @@ if (!client.config.botSwitches.logs) {
rawSwitches.MESSAGE_UPDATE = true;
};
client.on('raw', async (packet:RawGatewayPacket<RawMessageUpdate>)=>{
if (rawSwitches[packet.t]) return;
if (packet.t !== 'MESSAGE_UPDATE') return;
if (packet.d.guild_id != client.config.dcServer.id || disabledChannels.includes(packet.d.channel_id)) return;
if (typeof packet.d.content === 'undefined') return;
if (rawSwitches[packet.t] || packet.t !== 'MESSAGE_UPDATE') return;
if (packet.d.guild_id != client.config.dcServer.id || disabledChannels.includes(packet.d.channel_id) || typeof packet.d.content === 'undefined') return;
const channel = client.channels.cache.get(packet.d.channel_id) as Discord.TextBasedChannel;
const message = await channel.messages.fetch(packet.d.id);
client.emit('messageUpdate', message, message);
// Switched to console.log to prevent useless embed creation that has same content as the original message.
if (!rawSwitches.MESSAGE_UPDATE) return Logger.console('log', 'RawEvent:Edit', `Message was edited in #${(channel as Discord.TextChannel).name}`);
});
client.on('raw', async (packet:RawGatewayPacket<RawMessageDelete>)=>{