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

Compare commits

..

3 Commits

Author SHA1 Message Date
toast-ts
b9ac812c6a Update dependencies 2024-04-03 18:30:23 +11:00
toast-ts
e0706c632f LevelSys self-destruction test 2024-04-03 18:26:46 +11:00
toast-ts
433ae89769 Add missing font to Docker container 2024-04-03 18:04:05 +11:00
7 changed files with 57 additions and 53 deletions

View File

@ -2,8 +2,9 @@ FROM node:21.7.1-alpine3.19
ENV YARN_VERSION 4.1.1 ENV YARN_VERSION 4.1.1
ENV TZ Australia/Sydney ENV TZ Australia/Sydney
RUN yarn policies set-version $YARN_VERSION RUN yarn policies set-version $YARN_VERSION
RUN apk update && apk upgrade && apk add --no-cache git fontconfig && npm install -g typescript RUN apk update && apk upgrade && apk add --no-cache git fontconfig ttf-dejavu
WORKDIR /Daggerbot WORKDIR /Daggerbot
RUN npm install -g typescript
RUN git config --global --add safe.directory /Daggerbot RUN git config --global --add safe.directory /Daggerbot
COPY tsconfig.json package.json yarn.lock .yarnrc.yml ./ COPY tsconfig.json package.json yarn.lock .yarnrc.yml ./
RUN yarn RUN yarn

View File

@ -38,17 +38,17 @@
"mathjs": "12.4.1", "mathjs": "12.4.1",
"ms": "2.1.3", "ms": "2.1.3",
"node-cron": "3.0.3", "node-cron": "3.0.3",
"pg": "8.11.4", "pg": "8.11.5",
"pg-hstore": "2.3.4", "pg-hstore": "2.3.4",
"postgres-array": "3.0.2", "postgres-array": "3.0.2",
"redis": "4.6.13", "redis": "4.6.13",
"simple-git": "3.24.0", "simple-git": "3.24.0",
"systeminformation": "5.22.6", "systeminformation": "5.22.7",
"undici": "6.10.2" "undici": "6.11.1"
}, },
"devDependencies": { "devDependencies": {
"@types/ms": "0.7.34", "@types/ms": "0.7.34",
"@types/node": "20.12.2", "@types/node": "20.12.3",
"@types/node-cron": "3.0.11", "@types/node-cron": "3.0.11",
"@types/pg": "8.11.4", "@types/pg": "8.11.4",
"typescript": "5.4.3" "typescript": "5.4.3"

View File

@ -33,7 +33,7 @@ export default class Rank {
if (data.length < 2) return interaction.reply('Not enough data to generate graph.'); if (data.length < 2) return interaction.reply('Not enough data to generate graph.');
const graph = await CanvasBuilder.generateGraph(data, 'leaderboard'); const graph = await CanvasBuilder.generateGraph(data, 'leaderboard');
interaction.reply({ await interaction.reply({
embeds: [new client.embed().setColor(client.config.embedColor).setTitle('Leaderboard') embeds: [new client.embed().setColor(client.config.embedColor).setTitle('Leaderboard')
.setDescription(MessageTool.concatMessage( .setDescription(MessageTool.concatMessage(
`Level System was created **${Math.floor((Date.now()-client.config.LRSstart)/1000/60/60/24)}** days ago.`, `Level System was created **${Math.floor((Date.now()-client.config.LRSstart)/1000/60/60/24)}** days ago.`,

View File

@ -32,7 +32,7 @@ export class DailyMsgsSvc {
}) })
this.model.sync(); this.model.sync();
} }
nukeDays = async()=>await this.model.destroy(); nukeDays = async()=>await this.model.truncate();
fetchDays = async()=>await this.model.findAll(); fetchDays = async()=>await this.model.findAll();
async newDay(formattedDate:number, total:number) { async newDay(formattedDate:number, total:number) {
const [instance, created] = await this.model.findOrCreate({where: {day: formattedDate}, defaults: {total}}); const [instance, created] = await this.model.findOrCreate({where: {day: formattedDate}, defaults: {total}});

View File

@ -72,10 +72,6 @@ export class UserLevelsSvc {
return true; return true;
} }
} }
async getActiveUsers() {
const members = await this.model.findAll({order: [['messages', 'DESC']], limit: 5});
return members;
}
async messageIncremental(userId:string) { async messageIncremental(userId:string) {
const data = await this.model.findByPk(userId); const data = await this.model.findByPk(userId);
if (data && data.dataValues.isBlocked) return; if (data && data.dataValues.isBlocked) return;
@ -110,31 +106,28 @@ export class UserLevelsSvc {
}) })
} }
async initSelfdestruct() { async initSelfdestruct() {
// Every 1st of January at 11:00 (Midnight in London, Middayish in Sydney) // Every 1st of January at 11:00 (London Time)
cron.schedule('0 11 1 1 *', async()=>{ cron.schedule('0 11 1 1 *', async()=>{
Logger.console('log', 'Cron', 'Running job "resetAllData", this is activated every 1st of January'); Logger.console('log', 'Cron', 'Running job "resetAllData", this is activated every 1st of January');
const performCountBeforeReset = await this.model.count(); const performCountBeforeReset = await this.model.count();
const topMembers = await this.getActiveUsers(); const topMembers = await this.model.findAll({order: [['messages', 'DESC']], limit: 5});
Logger.console('log', 'Cron:resetAllData', `Counted ${performCountBeforeReset.toLocaleString()} members before reset`); Logger.console('log', 'Cron:resetAllData', `Counted ${performCountBeforeReset.toLocaleString()} members before reset`);
try {
await this.client.dailyMsgs.nukeDays(); await this.client.dailyMsgs.nukeDays();
await this.model.truncate(); await this.model.truncate();
try {
// Send notification to dcServer's logs channel after cronjob is complete. // Send notification to dcServer's logs channel after cronjob is complete.
(this.client.channels.resolve(this.client.config.dcServer.channels.bot_log) as Discord.TextChannel).send({embeds: [new this.client.embed() (this.client.channels.resolve(this.client.config.dcServer.channels.bot_log) as Discord.TextChannel).send({embeds: [new this.client.embed()
.setColor('#A3FFE3') .setColor('#A3FFE3')
.setTitle('Yearly data reset has begun!') .setTitle('Yearly data reset has begun!')
.setDescription(MessageTool.concatMessage( .setDescription(MessageTool.concatMessage(
'I have gone ahead and reset everyone\'s rank data.', 'I have gone ahead and reset everyone\'s rank data.',
`There was ${Intl.NumberFormat('en-US').format(performCountBeforeReset)} members in database before reset.\n`, `There was **${Intl.NumberFormat('en-US').format(performCountBeforeReset)}** members in database before reset.\n`,
'Top 5 most active members:', 'Top 5 most active members:',
...topMembers.map((m,i)=>`${i+1}. **${(this.client.users.resolve(m.dataValues.id) ? this.client.users.resolve(m.dataValues.id).displayName : '*Unknown User*')}** - **${m.dataValues.messages.toLocaleString()}** messages`) ...topMembers.map((m,i)=>`${i+1}. **${(this.client.users.resolve(m.dataValues.id) ? this.client.users.resolve(m.dataValues.id).displayName : '*Unknown User*')}** - **${m.dataValues.messages.toLocaleString()}** messages`)
)) ))
]}); ]});
} catch (why) {
Logger.debug('Cron:resetAllData', why)
}
// Reset LRSstart to current Epoch and save it to config file // Reset LRSstart to current Epoch and save it to config file
const newEpoch = new Date().getTime(); const newEpoch = new Date().getTime();
@ -144,6 +137,9 @@ export class UserLevelsSvc {
writeFileSync('src/config.json', JSON.stringify(this.client.config, null, 2)); writeFileSync('src/config.json', JSON.stringify(this.client.config, null, 2));
Logger.console('log', 'Cron:resetAllData', 'Job completed'); Logger.console('log', 'Cron:resetAllData', 'Job completed');
} }
} catch (why) {
Logger.console('error', 'Cron:resetAllData', why)
}
}) })
} }
algorithm = (level:number)=>level*level*15; algorithm = (level:number)=>level*level*15;

View File

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

View File

@ -548,12 +548,12 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@types/node@npm:*, @types/node@npm:20.12.2": "@types/node@npm:*, @types/node@npm:20.12.3":
version: 20.12.2 version: 20.12.3
resolution: "@types/node@npm:20.12.2" resolution: "@types/node@npm:20.12.3"
dependencies: dependencies:
undici-types: "npm:~5.26.4" undici-types: "npm:~5.26.4"
checksum: 10/f1f0ebfe475aefa183763b856e0023b81b76554196e8676a45b9fcfd1012cdd20d32adefb3c0330001c0011e074676603c34c24821a4924228250ea13a75da43 checksum: 10/3f3c5c6ba118a18aa997c51cdc3c66259d69021f87475a99ed6c913a6956e22de49748e09843bf6447a7a63ae474e61945a6dbcca93e23b2359fc0b6f9914f7a
languageName: node languageName: node
linkType: hard linkType: hard
@ -653,7 +653,7 @@ __metadata:
"@sequelize/core": "npm:7.0.0-alpha.39" "@sequelize/core": "npm:7.0.0-alpha.39"
"@toast/tokenservice-client": "npm:1.2.1" "@toast/tokenservice-client": "npm:1.2.1"
"@types/ms": "npm:0.7.34" "@types/ms": "npm:0.7.34"
"@types/node": "npm:20.12.2" "@types/node": "npm:20.12.3"
"@types/node-cron": "npm:3.0.11" "@types/node-cron": "npm:3.0.11"
"@types/pg": "npm:8.11.4" "@types/pg": "npm:8.11.4"
ansi-colors: "npm:4.1.3" ansi-colors: "npm:4.1.3"
@ -663,14 +663,14 @@ __metadata:
mathjs: "npm:12.4.1" mathjs: "npm:12.4.1"
ms: "npm:2.1.3" ms: "npm:2.1.3"
node-cron: "npm:3.0.3" node-cron: "npm:3.0.3"
pg: "npm:8.11.4" pg: "npm:8.11.5"
pg-hstore: "npm:2.3.4" pg-hstore: "npm:2.3.4"
postgres-array: "npm:3.0.2" postgres-array: "npm:3.0.2"
redis: "npm:4.6.13" redis: "npm:4.6.13"
simple-git: "npm:3.24.0" simple-git: "npm:3.24.0"
systeminformation: "npm:5.22.6" systeminformation: "npm:5.22.7"
typescript: "npm:5.4.3" typescript: "npm:5.4.3"
undici: "npm:6.10.2" undici: "npm:6.11.1"
languageName: unknown languageName: unknown
linkType: soft linkType: soft
@ -971,10 +971,10 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"pg-connection-string@npm:^2.5.0, pg-connection-string@npm:^2.6.3": "pg-connection-string@npm:^2.5.0, pg-connection-string@npm:^2.6.4":
version: 2.6.3 version: 2.6.4
resolution: "pg-connection-string@npm:2.6.3" resolution: "pg-connection-string@npm:2.6.4"
checksum: 10/2684742c563f113b9b976c2d2d6af0de67179910ac9490b4ffb9e5291d2e5ab6ac9fca23954b8f49ae42bc1ab886102162fb3abb4a78fad49d03921e80cb6356 checksum: 10/2c1d2ac1add1f93076f1594d217a0980f79add05dc48de6363e1c550827c78a6ee3e3b5420da9c54858f6b678cdb348aed49732ee68158b6cdb70f1d1c748cf9
languageName: node languageName: node
linkType: hard linkType: hard
@ -1045,12 +1045,12 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"pg@npm:8.11.4": "pg@npm:8.11.5":
version: 8.11.4 version: 8.11.5
resolution: "pg@npm:8.11.4" resolution: "pg@npm:8.11.5"
dependencies: dependencies:
pg-cloudflare: "npm:^1.1.1" pg-cloudflare: "npm:^1.1.1"
pg-connection-string: "npm:^2.6.3" pg-connection-string: "npm:^2.6.4"
pg-pool: "npm:^3.6.2" pg-pool: "npm:^3.6.2"
pg-protocol: "npm:^1.6.1" pg-protocol: "npm:^1.6.1"
pg-types: "npm:^2.1.0" pg-types: "npm:^2.1.0"
@ -1063,7 +1063,7 @@ __metadata:
peerDependenciesMeta: peerDependenciesMeta:
pg-native: pg-native:
optional: true optional: true
checksum: 10/33c2d7f049ccbdf4574d77e0ba8c5180694e603068bb697280baff6673de77af6bf36a367fb855f1b72f27965c943a59ec819d73cd2c7bb1c07a49f2fde5c739 checksum: 10/1510bc42943ea1749bfffac3f7ebae52ae638dc798e38786552fc67ffc0b2e4bd54456e7fd5cda7e805f30a0a59126c98e8c59afa88b6952f95411f16a16f709
languageName: node languageName: node
linkType: hard linkType: hard
@ -1251,12 +1251,12 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"systeminformation@npm:5.22.6": "systeminformation@npm:5.22.7":
version: 5.22.6 version: 5.22.7
resolution: "systeminformation@npm:5.22.6" resolution: "systeminformation@npm:5.22.7"
bin: bin:
systeminformation: lib/cli.js systeminformation: lib/cli.js
checksum: 10/f5c9e6f674c8a857514ce21709111d05e0e7b5d5a82265a64626bfb16f0ea82dce1f88455ca481ebb0ef1f83ec9072c07af1a0318de7ec01e80947d9d8a9d0d4 checksum: 10/c928782578d9783d49b3536ef5be6891d298a006cd087f149c2f24cbbde46dfa9cee88018d2bd4e9b82fe24e6dde59fad075a3e19367ee5e88b7e89574f50af7
conditions: (os=darwin | os=linux | os=win32 | os=freebsd | os=openbsd | os=netbsd | os=sunos | os=android) conditions: (os=darwin | os=linux | os=win32 | os=freebsd | os=openbsd | os=netbsd | os=sunos | os=android)
languageName: node languageName: node
linkType: hard linkType: hard
@ -1299,9 +1299,9 @@ __metadata:
linkType: hard linkType: hard
"type-fest@npm:^4.12.0": "type-fest@npm:^4.12.0":
version: 4.14.0 version: 4.15.0
resolution: "type-fest@npm:4.14.0" resolution: "type-fest@npm:4.15.0"
checksum: 10/fcf3b62fed194a3fc3d22bf287af3b1e1e93d4b5cb9723c093b694998d1588f27cc78dc4942ff4d319bb94ec60cb4afe5d1cd3d50ef144e47e327acbc34a5234 checksum: 10/8f897551877daa0df7bb17a21b6acd8a21ac5a0bdb14dbfd353b16013fed99f23c6d9c12a2c7685c8dededb4739ec8bfb120a914330f8b11a478a89758a11acc
languageName: node languageName: node
linkType: hard linkType: hard
@ -1362,6 +1362,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"undici@npm:6.11.1":
version: 6.11.1
resolution: "undici@npm:6.11.1"
checksum: 10/129480684630e5723b7f4a946c1d9f8120f9b5697cb2032d791d1e3d2898a90eed0ed63c6ef5641502569dca0112759948564354a932c8172fc96845aaf2dd28
languageName: node
linkType: hard
"universal-user-agent@npm:^6.0.0": "universal-user-agent@npm:^6.0.0":
version: 6.0.1 version: 6.0.1
resolution: "universal-user-agent@npm:6.0.1" resolution: "universal-user-agent@npm:6.0.1"