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

Compare commits

...

4 Commits

Author SHA1 Message Date
toast-ts
3e1a441ee4 Change Advertisement rule to ban from mute 2024-01-29 17:46:28 +11:00
toast-ts
5106f0e849 Add startDocker.sh 2024-01-29 15:00:04 +11:00
toast-ts
5e980363a3 Isolate the bot to its own compose file 2024-01-29 14:50:26 +11:00
toast-ts
07a4c48f97 Update TokenService to work in isolated environment 2024-01-29 14:45:08 +11:00
9 changed files with 59 additions and 52 deletions

40
.pnp.cjs generated
View File

@ -28,9 +28,9 @@ const RAW_RUNTIME_STATE =
"packageDependencies": [\ "packageDependencies": [\
["@octokit/auth-token", "npm:4.0.0"],\ ["@octokit/auth-token", "npm:4.0.0"],\
["@octokit/rest", "npm:20.0.2"],\ ["@octokit/rest", "npm:20.0.2"],\
["@toast/tokenservice-client", "npm:1.0.10::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.10%2Ftokenservice-client-1.0.10.tgz"],\ ["@toast/tokenservice-client", "npm:1.0.11::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.11%2Ftokenservice-client-1.0.11.tgz"],\
["@types/ms", "npm:0.7.34"],\ ["@types/ms", "npm:0.7.34"],\
["@types/node", "npm:20.11.6"],\ ["@types/node", "npm:20.11.10"],\
["@types/node-cron", "npm:3.0.11"],\ ["@types/node-cron", "npm:3.0.11"],\
["@types/pg", "npm:8.11.0"],\ ["@types/pg", "npm:8.11.0"],\
["@types/sequelize", "npm:4.28.20"],\ ["@types/sequelize", "npm:4.28.20"],\
@ -48,7 +48,7 @@ const RAW_RUNTIME_STATE =
["simple-git", "npm:3.22.0"],\ ["simple-git", "npm:3.22.0"],\
["systeminformation", "npm:5.21.24"],\ ["systeminformation", "npm:5.21.24"],\
["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin<compat/typescript>::version=5.3.3&hash=e012d7"],\ ["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin<compat/typescript>::version=5.3.3&hash=e012d7"],\
["undici", "npm:6.4.0"]\ ["undici", "npm:6.5.0"]\
],\ ],\
"linkType": "SOFT"\ "linkType": "SOFT"\
}]\ }]\
@ -571,11 +571,11 @@ const RAW_RUNTIME_STATE =
}]\ }]\
]],\ ]],\
["@toast/tokenservice-client", [\ ["@toast/tokenservice-client", [\
["npm:1.0.10::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.10%2Ftokenservice-client-1.0.10.tgz", {\ ["npm:1.0.11::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.11%2Ftokenservice-client-1.0.11.tgz", {\
"packageLocation": "./.yarn/cache/@toast-tokenservice-client-npm-1.0.10-3f262fca44-f832828a1d.zip/node_modules/@toast/tokenservice-client/",\ "packageLocation": "./.yarn/cache/@toast-tokenservice-client-npm-1.0.11-c95d3498fc-c910af2b01.zip/node_modules/@toast/tokenservice-client/",\
"packageDependencies": [\ "packageDependencies": [\
["@toast/tokenservice-client", "npm:1.0.10::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.10%2Ftokenservice-client-1.0.10.tgz"],\ ["@toast/tokenservice-client", "npm:1.0.11::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.11%2Ftokenservice-client-1.0.11.tgz"],\
["undici", "npm:6.4.0"]\ ["undici", "npm:6.5.0"]\
],\ ],\
"linkType": "HARD"\ "linkType": "HARD"\
}]\ }]\
@ -603,7 +603,7 @@ const RAW_RUNTIME_STATE =
"packageLocation": "./.yarn/cache/@types-continuation-local-storage-npm-3.2.7-763e4dc12b-1f272b53bc.zip/node_modules/@types/continuation-local-storage/",\ "packageLocation": "./.yarn/cache/@types-continuation-local-storage-npm-3.2.7-763e4dc12b-1f272b53bc.zip/node_modules/@types/continuation-local-storage/",\
"packageDependencies": [\ "packageDependencies": [\
["@types/continuation-local-storage", "npm:3.2.7"],\ ["@types/continuation-local-storage", "npm:3.2.7"],\
["@types/node", "npm:20.11.6"]\ ["@types/node", "npm:20.11.10"]\
],\ ],\
"linkType": "HARD"\ "linkType": "HARD"\
}]\ }]\
@ -637,10 +637,10 @@ const RAW_RUNTIME_STATE =
}]\ }]\
]],\ ]],\
["@types/node", [\ ["@types/node", [\
["npm:20.11.6", {\ ["npm:20.11.10", {\
"packageLocation": "./.yarn/cache/@types-node-npm-20.11.6-e5e1974d32-375dfc75f0.zip/node_modules/@types/node/",\ "packageLocation": "./.yarn/cache/@types-node-npm-20.11.10-169269fe65-41ca9c7e7c.zip/node_modules/@types/node/",\
"packageDependencies": [\ "packageDependencies": [\
["@types/node", "npm:20.11.6"],\ ["@types/node", "npm:20.11.10"],\
["undici-types", "npm:5.26.5"]\ ["undici-types", "npm:5.26.5"]\
],\ ],\
"linkType": "HARD"\ "linkType": "HARD"\
@ -660,7 +660,7 @@ const RAW_RUNTIME_STATE =
"packageLocation": "./.yarn/cache/@types-pg-npm-8.11.0-bf104da0ba-91a7ccc5dc.zip/node_modules/@types/pg/",\ "packageLocation": "./.yarn/cache/@types-pg-npm-8.11.0-bf104da0ba-91a7ccc5dc.zip/node_modules/@types/pg/",\
"packageDependencies": [\ "packageDependencies": [\
["@types/pg", "npm:8.11.0"],\ ["@types/pg", "npm:8.11.0"],\
["@types/node", "npm:20.11.6"],\ ["@types/node", "npm:20.11.10"],\
["pg-protocol", "npm:1.6.0"],\ ["pg-protocol", "npm:1.6.0"],\
["pg-types", "npm:4.0.1"]\ ["pg-types", "npm:4.0.1"]\
],\ ],\
@ -694,7 +694,7 @@ const RAW_RUNTIME_STATE =
"packageLocation": "./.yarn/cache/@types-ws-npm-8.5.9-91d1b2ab07-7cf66383b8.zip/node_modules/@types/ws/",\ "packageLocation": "./.yarn/cache/@types-ws-npm-8.5.9-91d1b2ab07-7cf66383b8.zip/node_modules/@types/ws/",\
"packageDependencies": [\ "packageDependencies": [\
["@types/ws", "npm:8.5.9"],\ ["@types/ws", "npm:8.5.9"],\
["@types/node", "npm:20.11.6"]\ ["@types/node", "npm:20.11.10"]\
],\ ],\
"linkType": "HARD"\ "linkType": "HARD"\
}]\ }]\
@ -993,9 +993,9 @@ const RAW_RUNTIME_STATE =
["daggerbot-ts", "workspace:."],\ ["daggerbot-ts", "workspace:."],\
["@octokit/auth-token", "npm:4.0.0"],\ ["@octokit/auth-token", "npm:4.0.0"],\
["@octokit/rest", "npm:20.0.2"],\ ["@octokit/rest", "npm:20.0.2"],\
["@toast/tokenservice-client", "npm:1.0.10::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.10%2Ftokenservice-client-1.0.10.tgz"],\ ["@toast/tokenservice-client", "npm:1.0.11::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.11%2Ftokenservice-client-1.0.11.tgz"],\
["@types/ms", "npm:0.7.34"],\ ["@types/ms", "npm:0.7.34"],\
["@types/node", "npm:20.11.6"],\ ["@types/node", "npm:20.11.10"],\
["@types/node-cron", "npm:3.0.11"],\ ["@types/node-cron", "npm:3.0.11"],\
["@types/pg", "npm:8.11.0"],\ ["@types/pg", "npm:8.11.0"],\
["@types/sequelize", "npm:4.28.20"],\ ["@types/sequelize", "npm:4.28.20"],\
@ -1013,7 +1013,7 @@ const RAW_RUNTIME_STATE =
["simple-git", "npm:3.22.0"],\ ["simple-git", "npm:3.22.0"],\
["systeminformation", "npm:5.21.24"],\ ["systeminformation", "npm:5.21.24"],\
["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin<compat/typescript>::version=5.3.3&hash=e012d7"],\ ["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin<compat/typescript>::version=5.3.3&hash=e012d7"],\
["undici", "npm:6.4.0"]\ ["undici", "npm:6.5.0"]\
],\ ],\
"linkType": "SOFT"\ "linkType": "SOFT"\
}]\ }]\
@ -2606,10 +2606,10 @@ const RAW_RUNTIME_STATE =
],\ ],\
"linkType": "HARD"\ "linkType": "HARD"\
}],\ }],\
["npm:6.4.0", {\ ["npm:6.5.0", {\
"packageLocation": "./.yarn/cache/undici-npm-6.4.0-3c1375c132-65552916aa.zip/node_modules/undici/",\ "packageLocation": "./.yarn/cache/undici-npm-6.5.0-5598def435-0ad9289bd8.zip/node_modules/undici/",\
"packageDependencies": [\ "packageDependencies": [\
["undici", "npm:6.4.0"],\ ["undici", "npm:6.5.0"],\
["@fastify/busboy", "npm:2.0.0"]\ ["@fastify/busboy", "npm:2.0.0"]\
],\ ],\
"linkType": "HARD"\ "linkType": "HARD"\
@ -2725,7 +2725,7 @@ const RAW_RUNTIME_STATE =
"packageLocation": "./.yarn/cache/wkx-npm-0.5.0-fca5152cd8-b8975e33f9.zip/node_modules/wkx/",\ "packageLocation": "./.yarn/cache/wkx-npm-0.5.0-fca5152cd8-b8975e33f9.zip/node_modules/wkx/",\
"packageDependencies": [\ "packageDependencies": [\
["wkx", "npm:0.5.0"],\ ["wkx", "npm:0.5.0"],\
["@types/node", "npm:20.11.6"]\ ["@types/node", "npm:20.11.10"]\
],\ ],\
"linkType": "HARD"\ "linkType": "HARD"\
}]\ }]\

9
docker-compose.bot.yml Normal file
View File

@ -0,0 +1,9 @@
services:
bot:
container_name: daggerbot-prod
build: .
restart: unless-stopped
volumes:
- ./.git:/Daggerbot/.git:rw
- ./src/:/Daggerbot/src/:rw
- ./dist/:/Daggerbot/dist/:rw

View File

@ -1,12 +1,4 @@
services: services:
bot:
container_name: daggerbot-prod
build: .
restart: unless-stopped
volumes:
- ./.git:/Daggerbot/.git:rw
- ./src/:/Daggerbot/src/:rw
- ./dist/:/Daggerbot/dist/:rw
cache: cache:
container_name: redis-cache container_name: redis-cache
image: redis/redis-stack-server:7.2.0-v6 image: redis/redis-stack-server:7.2.0-v6

View File

@ -34,7 +34,7 @@
"dependencies": { "dependencies": {
"@octokit/auth-token": "4.0.0", "@octokit/auth-token": "4.0.0",
"@octokit/rest": "20.0.2", "@octokit/rest": "20.0.2",
"@toast/tokenservice-client": "1.0.10", "@toast/tokenservice-client": "1.0.11",
"ansi-colors": "4.1.3", "ansi-colors": "4.1.3",
"canvas": "2.11.2", "canvas": "2.11.2",
"dayjs": "1.11.10", "dayjs": "1.11.10",
@ -48,11 +48,11 @@
"sequelize": "6.35.2", "sequelize": "6.35.2",
"simple-git": "3.22.0", "simple-git": "3.22.0",
"systeminformation": "5.21.24", "systeminformation": "5.21.24",
"undici": "6.4.0" "undici": "6.5.0"
}, },
"devDependencies": { "devDependencies": {
"@types/ms": "0.7.34", "@types/ms": "0.7.34",
"@types/node": "20.11.6", "@types/node": "20.11.10",
"@types/node-cron": "3.0.11", "@types/node-cron": "3.0.11",
"@types/pg": "8.11.0", "@types/pg": "8.11.0",
"@types/sequelize": "4.28.20", "@types/sequelize": "4.28.20",

View File

@ -4,7 +4,7 @@ import Logger from '../helpers/Logger.js';
export default class Automoderator { export default class Automoderator {
private static lockQuery:Set<Discord.Snowflake> = new Set(); private static lockQuery:Set<Discord.Snowflake> = new Set();
static scanMsg =(message:Discord.Message)=>message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b/g, '').split(' ').join(''); static scanMsg =(message:Discord.Message)=>message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n?0-9]|[]|ing\b/g, '').split(' ').join('');
static async repeatedMessages(client:TClient, message:Discord.Message, thresholdTime:number, thresholdAmount:number, type:string, duration:string, reason:string) { static async repeatedMessages(client:TClient, message:Discord.Message, action:'mute'|'ban', thresholdTime:number, thresholdAmount:number, type:string, duration:string, reason:string) {
const now = Date.now(); const now = Date.now();
if (!client.repeatedMessages[message.author.id]) client.repeatedMessages[message.author.id] = {type: type, count:1, firstTime:now, timeout: null}; if (!client.repeatedMessages[message.author.id]) client.repeatedMessages[message.author.id] = {type: type, count:1, firstTime:now, timeout: null};
@ -18,7 +18,7 @@ export default class Automoderator {
if (!this.lockQuery.has(message.author.id)) { if (!this.lockQuery.has(message.author.id)) {
this.lockQuery.add(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', 'AUTOMOD', `Lock acquired for ${message.author.tag} with reason: ${reason}`);
await client.punishments.punishmentAdd('mute', {time: duration}, client.user.id, `AUTOMOD:${reason}`, message.author, message.member as Discord.GuildMember); await client.punishments.punishmentAdd(action, {time: duration}, client.user.id, `AUTOMOD:${reason}`, message.author, message.member as Discord.GuildMember);
setTimeout(()=>{ setTimeout(()=>{
this.lockQuery.delete(message.author.id); this.lockQuery.delete(message.author.id);
Logger.console('log', 'AUTOMOD', `Lock released for ${message.author.tag}`); Logger.console('log', 'AUTOMOD', `Lock released for ${message.author.tag}`);

View File

@ -21,7 +21,7 @@ export default class MessageCreate {
automodded = true; automodded = true;
message.delete().catch(()=>Logger.console('log', 'AUTOMOD:PROHIBITEDWORDS', automodFailReason)); message.delete().catch(()=>Logger.console('log', 'AUTOMOD:PROHIBITEDWORDS', automodFailReason));
message.channel.send('That word isn\'t allowed here.').then(x=>setTimeout(()=>x.delete(), 10000)); message.channel.send('That word isn\'t allowed here.').then(x=>setTimeout(()=>x.delete(), 10000));
await Automoderator.repeatedMessages(client, message, 30000, 3, 'bw', '30m', 'Prohibited word spam'); await Automoderator.repeatedMessages(client, message, 'mute', 30000, 3, 'bw', '30m', 'Prohibited word spam');
} }
}, },
discordInvite: { discordInvite: {
@ -32,7 +32,7 @@ export default class MessageCreate {
automodded = true; automodded = true;
message.delete().catch(()=>Logger.console('log', 'AUTOMOD:ADVERTISEMENT', automodFailReason)); message.delete().catch(()=>Logger.console('log', 'AUTOMOD:ADVERTISEMENT', automodFailReason));
message.channel.send('Please don\'t advertise other Discord servers.').then(x=>setTimeout(()=>x.delete(), 15000)); message.channel.send('Please don\'t advertise other Discord servers.').then(x=>setTimeout(()=>x.delete(), 15000));
await Automoderator.repeatedMessages(client, message, 60000, 2, 'adv', '1h', 'Discord advertisement'); await Automoderator.repeatedMessages(client, message, 'ban', 60000, 4, 'adv', null, 'Discord advertisement');
} }
} }
}, },

View File

@ -1,3 +1,3 @@
import TokenService from '@toast/tokenservice-client'; import TokenService from '@toast/tokenservice-client';
export default async()=>new TokenService(process.argv[3] ?? 'daggerbot').connect(); export default async()=>new TokenService(process.argv[3] ?? 'daggerbot', false).connect();

6
startDocker.sh Normal file
View File

@ -0,0 +1,6 @@
#!/bin/bash
docker compose -f docker-compose.bot.yml build bot && \
docker compose -f docker-compose.bot.yml up -d bot
exit 0

View File

@ -379,12 +379,12 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@toast/tokenservice-client@npm:1.0.10": "@toast/tokenservice-client@npm:1.0.11":
version: 1.0.10 version: 1.0.11
resolution: "@toast/tokenservice-client@npm:1.0.10::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.10%2Ftokenservice-client-1.0.10.tgz" resolution: "@toast/tokenservice-client@npm:1.0.11::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.11%2Ftokenservice-client-1.0.11.tgz"
dependencies: dependencies:
undici: "npm:6.4.0" undici: "npm:6.5.0"
checksum: f832828a1d076cd961fca408cf10b9240c99526801b6d68e262d3fab9b460ee1eb45bef0d37abc6eecd2e24f96d9af8c410a39f6f93337e352a1bf07110e3fca checksum: c910af2b01876ca53de3078cf6b20c3cd8619ed807c3ce573074bc886a8690e6edc43f961088acf4bc2a7e925e8a0cb0e35df930b5923b20ecbbad6fd9bf4c81
languageName: node languageName: node
linkType: hard linkType: hard
@ -441,12 +441,12 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@types/node@npm:*, @types/node@npm:20.11.6": "@types/node@npm:*, @types/node@npm:20.11.10":
version: 20.11.6 version: 20.11.10
resolution: "@types/node@npm:20.11.6" resolution: "@types/node@npm:20.11.10"
dependencies: dependencies:
undici-types: "npm:~5.26.4" undici-types: "npm:~5.26.4"
checksum: 375dfc75f0aa8b7fb99382d84c317e5dab2969dcc3f54d8490b119151060923eae6483839552347bc78262bbcefb2951ee131e15372f4e80b755be2dda9afe80 checksum: 41ca9c7e7c95bf070ad747ab266f267f41950e01f5ddda739d0665c2ed39acc45cce46f78e33ffa2bf2dacd74a8493044b967c86358017dacce12958e49db664
languageName: node languageName: node
linkType: hard linkType: hard
@ -746,9 +746,9 @@ __metadata:
dependencies: dependencies:
"@octokit/auth-token": "npm:4.0.0" "@octokit/auth-token": "npm:4.0.0"
"@octokit/rest": "npm:20.0.2" "@octokit/rest": "npm:20.0.2"
"@toast/tokenservice-client": "npm:1.0.10" "@toast/tokenservice-client": "npm:1.0.11"
"@types/ms": "npm:0.7.34" "@types/ms": "npm:0.7.34"
"@types/node": "npm:20.11.6" "@types/node": "npm:20.11.10"
"@types/node-cron": "npm:3.0.11" "@types/node-cron": "npm:3.0.11"
"@types/pg": "npm:8.11.0" "@types/pg": "npm:8.11.0"
"@types/sequelize": "npm:4.28.20" "@types/sequelize": "npm:4.28.20"
@ -766,7 +766,7 @@ __metadata:
simple-git: "npm:3.22.0" simple-git: "npm:3.22.0"
systeminformation: "npm:5.21.24" systeminformation: "npm:5.21.24"
typescript: "npm:5.3.3" typescript: "npm:5.3.3"
undici: "npm:6.4.0" undici: "npm:6.5.0"
languageName: unknown languageName: unknown
linkType: soft linkType: soft
@ -2160,12 +2160,12 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"undici@npm:6.4.0": "undici@npm:6.5.0":
version: 6.4.0 version: 6.5.0
resolution: "undici@npm:6.4.0" resolution: "undici@npm:6.5.0"
dependencies: dependencies:
"@fastify/busboy": "npm:^2.0.0" "@fastify/busboy": "npm:^2.0.0"
checksum: 65552916aa84eb8ea262cf7205bf2dc1ca86b616843adceb6d994a172a5a6be7fbf384ab790e7ede82811942f0c71a53e639309e92e05be044866ca54993e0be checksum: 0ad9289bd8dc8a5ee8cf81a48a629a59c33814702ae706b1d8e7c7fac3cfa85bd6a73943db5d9379f4d420858d239ed3857ec1003e517ddb67eb44fdbc227f3e
languageName: node languageName: node
linkType: hard linkType: hard