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

Compare commits

..

No commits in common. "b9ac812c6af7c255b5862e5106c3a931f262ed75" and "57122ae9dbf1ab01a5e86b751efa63f81371bd76" have entirely different histories.

7 changed files with 54 additions and 58 deletions

View File

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

View File

@ -38,17 +38,17 @@
"mathjs": "12.4.1",
"ms": "2.1.3",
"node-cron": "3.0.3",
"pg": "8.11.5",
"pg": "8.11.4",
"pg-hstore": "2.3.4",
"postgres-array": "3.0.2",
"redis": "4.6.13",
"simple-git": "3.24.0",
"systeminformation": "5.22.7",
"undici": "6.11.1"
"systeminformation": "5.22.6",
"undici": "6.10.2"
},
"devDependencies": {
"@types/ms": "0.7.34",
"@types/node": "20.12.3",
"@types/node": "20.12.2",
"@types/node-cron": "3.0.11",
"@types/pg": "8.11.4",
"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.');
const graph = await CanvasBuilder.generateGraph(data, 'leaderboard');
await interaction.reply({
interaction.reply({
embeds: [new client.embed().setColor(client.config.embedColor).setTitle('Leaderboard')
.setDescription(MessageTool.concatMessage(
`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();
}
nukeDays = async()=>await this.model.truncate();
nukeDays = async()=>await this.model.destroy();
fetchDays = async()=>await this.model.findAll();
async newDay(formattedDate:number, total:number) {
const [instance, created] = await this.model.findOrCreate({where: {day: formattedDate}, defaults: {total}});

View File

@ -72,6 +72,10 @@ export class UserLevelsSvc {
return true;
}
}
async getActiveUsers() {
const members = await this.model.findAll({order: [['messages', 'DESC']], limit: 5});
return members;
}
async messageIncremental(userId:string) {
const data = await this.model.findByPk(userId);
if (data && data.dataValues.isBlocked) return;
@ -106,39 +110,39 @@ export class UserLevelsSvc {
})
}
async initSelfdestruct() {
// Every 1st of January at 11:00 (London Time)
// Every 1st of January at 11:00 (Midnight in London, Middayish in Sydney)
cron.schedule('0 11 1 1 *', async()=>{
Logger.console('log', 'Cron', 'Running job "resetAllData", this is activated every 1st of January');
const performCountBeforeReset = await this.model.count();
const topMembers = await this.model.findAll({order: [['messages', 'DESC']], limit: 5});
Logger.console('log', 'Cron:resetAllData', `Counted ${performCountBeforeReset.toLocaleString()} members before reset`);
try {
await this.client.dailyMsgs.nukeDays();
await this.model.truncate();
const topMembers = await this.getActiveUsers();
Logger.console('log', 'Cron:resetAllData', `Counted ${performCountBeforeReset.toLocaleString()} members before reset`);
await this.client.dailyMsgs.nukeDays();
await this.model.truncate();
try {
// 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()
.setColor('#A3FFE3')
.setTitle('Yearly data reset has begun!')
.setDescription(MessageTool.concatMessage(
'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:',
...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`)
))
]});
// Reset LRSstart to current Epoch and save it to config file
const newEpoch = new Date().getTime();
if (this.client.config.LRSstart !== newEpoch) {
this.client.config.LRSstart = newEpoch;
Logger.console('log', 'Cron:resetAllData', `Resetting LRSstart to \`${newEpoch}\`, saved to config file`);
writeFileSync('src/config.json', JSON.stringify(this.client.config, null, 2));
Logger.console('log', 'Cron:resetAllData', 'Job completed');
}
} catch (why) {
Logger.console('error', 'Cron:resetAllData', why)
Logger.debug('Cron:resetAllData', why)
}
// Reset LRSstart to current Epoch and save it to config file
const newEpoch = new Date().getTime();
if (this.client.config.LRSstart !== newEpoch) {
this.client.config.LRSstart = newEpoch;
Logger.console('log', 'Cron:resetAllData', `Resetting LRSstart to \`${newEpoch}\`, saved to config file`);
writeFileSync('src/config.json', JSON.stringify(this.client.config, null, 2));
Logger.console('log', 'Cron:resetAllData', 'Job completed');
}
})
}

View File

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

View File

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