1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-18 00:31:00 -05:00

Compare commits

...

2 Commits

Author SHA1 Message Date
toast-ts
3fc6824e57 Update @types/pg 2024-02-25 20:43:32 +11:00
toast-ts
306d330914 Clean up some of the stuff 2024-02-25 20:40:44 +11:00
7 changed files with 32 additions and 32 deletions

12
.pnp.cjs generated
View File

@ -32,7 +32,7 @@ const RAW_RUNTIME_STATE =
["@types/ms", "npm:0.7.34"],\
["@types/node", "npm:20.11.20"],\
["@types/node-cron", "npm:3.0.11"],\
["@types/pg", "npm:8.11.0"],\
["@types/pg", "npm:8.11.1"],\
["@types/sequelize", "npm:4.28.20"],\
["ansi-colors", "npm:4.1.3"],\
["dayjs", "npm:1.11.10"],\
@ -674,10 +674,10 @@ const RAW_RUNTIME_STATE =
}]\
]],\
["@types/pg", [\
["npm:8.11.0", {\
"packageLocation": "./.yarn/cache/@types-pg-npm-8.11.0-bf104da0ba-91a7ccc5dc.zip/node_modules/@types/pg/",\
["npm:8.11.1", {\
"packageLocation": "./.yarn/cache/@types-pg-npm-8.11.1-5d06a4b9df-2fdcb0dc33.zip/node_modules/@types/pg/",\
"packageDependencies": [\
["@types/pg", "npm:8.11.0"],\
["@types/pg", "npm:8.11.1"],\
["@types/node", "npm:20.11.20"],\
["pg-protocol", "npm:1.6.0"],\
["pg-types", "npm:4.0.2"]\
@ -781,7 +781,7 @@ const RAW_RUNTIME_STATE =
["@types/ms", "npm:0.7.34"],\
["@types/node", "npm:20.11.20"],\
["@types/node-cron", "npm:3.0.11"],\
["@types/pg", "npm:8.11.0"],\
["@types/pg", "npm:8.11.1"],\
["@types/sequelize", "npm:4.28.20"],\
["ansi-colors", "npm:4.1.3"],\
["dayjs", "npm:1.11.10"],\
@ -1301,7 +1301,7 @@ const RAW_RUNTIME_STATE =
["@types/mariadb", null],\
["@types/mysql2", null],\
["@types/oracledb", null],\
["@types/pg", "npm:8.11.0"],\
["@types/pg", "npm:8.11.1"],\
["@types/pg-hstore", null],\
["@types/snowflake-sdk", null],\
["@types/sqlite3", null],\

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",
@ -53,7 +53,7 @@
"@types/ms": "0.7.34",
"@types/node": "20.11.20",
"@types/node-cron": "3.0.11",
"@types/pg": "8.11.0",
"@types/pg": "8.11.1",
"@types/sequelize": "4.28.20",
"typescript": "5.3.3"
}

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>)=>{

View File

@ -482,14 +482,14 @@ __metadata:
languageName: node
linkType: hard
"@types/pg@npm:8.11.0":
version: 8.11.0
resolution: "@types/pg@npm:8.11.0"
"@types/pg@npm:8.11.1":
version: 8.11.1
resolution: "@types/pg@npm:8.11.1"
dependencies:
"@types/node": "npm:*"
pg-protocol: "npm:*"
pg-types: "npm:^4.0.1"
checksum: 10/91a7ccc5dc8e162d9d181f48f699eb4628632e75bd9db1c0ca774ec9b055b177875fb4b426279961061912f25fb3948c48c96e63ac9e85efcf7ce6f2567b6485
checksum: 10/2fdcb0dc331c4f4e334061c30a14187a6d835a049be9e9a2d84d55935025c45be7f5f40fd6b854c19fcf72d17e854481b11a461d7679005d9813bf29c56ba380
languageName: node
linkType: hard
@ -575,7 +575,7 @@ __metadata:
"@types/ms": "npm:0.7.34"
"@types/node": "npm:20.11.20"
"@types/node-cron": "npm:3.0.11"
"@types/pg": "npm:8.11.0"
"@types/pg": "npm:8.11.1"
"@types/sequelize": "npm:4.28.20"
ansi-colors: "npm:4.1.3"
dayjs: "npm:1.11.10"