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

Compare commits

...

5 Commits

Author SHA1 Message Date
AnxietyisReal
93303cb1d9 Filter moderator role properly 2024-01-14 17:58:25 +11:00
AnxietyisReal
785eb8eaf2 Add /reminder moderation command 2024-01-14 17:51:17 +11:00
AnxietyisReal
1884a6bd04 Fix typo in "modify_rank_msgs" subcmd 2024-01-14 17:27:47 +11:00
AnxietyisReal
61f358e76e Add top 5 members to yearly nuke. 2024-01-14 16:31:26 +11:00
AnxietyisReal
faa51f0dbb Update dependencies 2024-01-14 15:23:13 +11:00
9 changed files with 108 additions and 59 deletions

50
.pnp.cjs generated
View File

@ -30,15 +30,15 @@ const RAW_RUNTIME_STATE =
["@octokit/rest", "npm:20.0.2"],\
["@toast/tokenservice-client", "npm:1.0.6::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.6%2Ftokenservice-client-1.0.6.tgz"],\
["@types/ms", "npm:0.7.34"],\
["@types/node", "npm:20.10.7"],\
["@types/node", "npm:20.11.0"],\
["@types/node-cron", "npm:3.0.11"],\
["@types/pg", "npm:8.10.9"],\
["@types/sequelize", "npm:4.28.19"],\
["@types/sequelize", "npm:4.28.20"],\
["ansi-colors", "npm:4.1.3"],\
["canvas", "npm:2.11.2"],\
["dayjs", "npm:1.11.10"],\
["discord.js", "npm:14.14.1"],\
["fast-xml-parser", "npm:4.3.2"],\
["fast-xml-parser", "npm:4.3.3"],\
["ms", "npm:2.1.3"],\
["node-cron", "npm:3.0.3"],\
["pg", "virtual:20c353e2d6536e37339997f03975c6a660f4d296e664d291bd43620c6162cca8eb5ef90b0998dc9db75ff6862e5da587d0530bae26805f5fadc8f17aaa4ff794#npm:8.11.3"],\
@ -48,7 +48,7 @@ const RAW_RUNTIME_STATE =
["simple-git", "npm:3.22.0"],\
["systeminformation", "npm:5.21.22"],\
["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin<compat/typescript>::version=5.3.3&hash=e012d7"],\
["undici", "npm:6.2.1"]\
["undici", "npm:6.3.0"]\
],\
"linkType": "SOFT"\
}]\
@ -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/",\
"packageDependencies": [\
["@types/continuation-local-storage", "npm:3.2.7"],\
["@types/node", "npm:20.10.7"]\
["@types/node", "npm:20.11.0"]\
],\
"linkType": "HARD"\
}]\
@ -637,10 +637,10 @@ const RAW_RUNTIME_STATE =
}]\
]],\
["@types/node", [\
["npm:20.10.7", {\
"packageLocation": "./.yarn/cache/@types-node-npm-20.10.7-2d1f5de3e9-4a1ba3fb7f.zip/node_modules/@types/node/",\
["npm:20.11.0", {\
"packageLocation": "./.yarn/cache/@types-node-npm-20.11.0-cb757f0c2a-8da60a8ccb.zip/node_modules/@types/node/",\
"packageDependencies": [\
["@types/node", "npm:20.10.7"],\
["@types/node", "npm:20.11.0"],\
["undici-types", "npm:5.26.5"]\
],\
"linkType": "HARD"\
@ -660,7 +660,7 @@ const RAW_RUNTIME_STATE =
"packageLocation": "./.yarn/cache/@types-pg-npm-8.10.9-ee8620c8e7-787be5431a.zip/node_modules/@types/pg/",\
"packageDependencies": [\
["@types/pg", "npm:8.10.9"],\
["@types/node", "npm:20.10.7"],\
["@types/node", "npm:20.11.0"],\
["pg-protocol", "npm:1.6.0"],\
["pg-types", "npm:4.0.1"]\
],\
@ -668,10 +668,10 @@ const RAW_RUNTIME_STATE =
}]\
]],\
["@types/sequelize", [\
["npm:4.28.19", {\
"packageLocation": "./.yarn/cache/@types-sequelize-npm-4.28.19-1b925fbf8e-6378a703fc.zip/node_modules/@types/sequelize/",\
["npm:4.28.20", {\
"packageLocation": "./.yarn/cache/@types-sequelize-npm-4.28.20-a712a5ea90-8b3faec2e6.zip/node_modules/@types/sequelize/",\
"packageDependencies": [\
["@types/sequelize", "npm:4.28.19"],\
["@types/sequelize", "npm:4.28.20"],\
["@types/bluebird", "npm:3.5.42"],\
["@types/continuation-local-storage", "npm:3.2.7"],\
["@types/lodash", "npm:4.14.201"],\
@ -694,7 +694,7 @@ const RAW_RUNTIME_STATE =
"packageLocation": "./.yarn/cache/@types-ws-npm-8.5.9-91d1b2ab07-7cf66383b8.zip/node_modules/@types/ws/",\
"packageDependencies": [\
["@types/ws", "npm:8.5.9"],\
["@types/node", "npm:20.10.7"]\
["@types/node", "npm:20.11.0"]\
],\
"linkType": "HARD"\
}]\
@ -995,15 +995,15 @@ const RAW_RUNTIME_STATE =
["@octokit/rest", "npm:20.0.2"],\
["@toast/tokenservice-client", "npm:1.0.6::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.6%2Ftokenservice-client-1.0.6.tgz"],\
["@types/ms", "npm:0.7.34"],\
["@types/node", "npm:20.10.7"],\
["@types/node", "npm:20.11.0"],\
["@types/node-cron", "npm:3.0.11"],\
["@types/pg", "npm:8.10.9"],\
["@types/sequelize", "npm:4.28.19"],\
["@types/sequelize", "npm:4.28.20"],\
["ansi-colors", "npm:4.1.3"],\
["canvas", "npm:2.11.2"],\
["dayjs", "npm:1.11.10"],\
["discord.js", "npm:14.14.1"],\
["fast-xml-parser", "npm:4.3.2"],\
["fast-xml-parser", "npm:4.3.3"],\
["ms", "npm:2.1.3"],\
["node-cron", "npm:3.0.3"],\
["pg", "virtual:20c353e2d6536e37339997f03975c6a660f4d296e664d291bd43620c6162cca8eb5ef90b0998dc9db75ff6862e5da587d0530bae26805f5fadc8f17aaa4ff794#npm:8.11.3"],\
@ -1013,7 +1013,7 @@ const RAW_RUNTIME_STATE =
["simple-git", "npm:3.22.0"],\
["systeminformation", "npm:5.21.22"],\
["typescript", "patch:typescript@npm%3A5.3.3#optional!builtin<compat/typescript>::version=5.3.3&hash=e012d7"],\
["undici", "npm:6.2.1"]\
["undici", "npm:6.3.0"]\
],\
"linkType": "SOFT"\
}]\
@ -1209,10 +1209,10 @@ const RAW_RUNTIME_STATE =
}]\
]],\
["fast-xml-parser", [\
["npm:4.3.2", {\
"packageLocation": "./.yarn/cache/fast-xml-parser-npm-4.3.2-ccbd0655a8-cb3d9ad7d5.zip/node_modules/fast-xml-parser/",\
["npm:4.3.3", {\
"packageLocation": "./.yarn/cache/fast-xml-parser-npm-4.3.3-35a04105d1-501de1f38d.zip/node_modules/fast-xml-parser/",\
"packageDependencies": [\
["fast-xml-parser", "npm:4.3.2"],\
["fast-xml-parser", "npm:4.3.3"],\
["strnum", "npm:1.0.5"]\
],\
"linkType": "HARD"\
@ -2613,6 +2613,14 @@ const RAW_RUNTIME_STATE =
["@fastify/busboy", "npm:2.0.0"]\
],\
"linkType": "HARD"\
}],\
["npm:6.3.0", {\
"packageLocation": "./.yarn/cache/undici-npm-6.3.0-3653a9b474-4534474384.zip/node_modules/undici/",\
"packageDependencies": [\
["undici", "npm:6.3.0"],\
["@fastify/busboy", "npm:2.0.0"]\
],\
"linkType": "HARD"\
}]\
]],\
["undici-types", [\
@ -2725,7 +2733,7 @@ const RAW_RUNTIME_STATE =
"packageLocation": "./.yarn/cache/wkx-npm-0.5.0-fca5152cd8-b8975e33f9.zip/node_modules/wkx/",\
"packageDependencies": [\
["wkx", "npm:0.5.0"],\
["@types/node", "npm:20.10.7"]\
["@types/node", "npm:20.11.0"]\
],\
"linkType": "HARD"\
}]\

View File

@ -39,7 +39,7 @@
"canvas": "2.11.2",
"dayjs": "1.11.10",
"discord.js": "14.14.1",
"fast-xml-parser": "4.3.2",
"fast-xml-parser": "4.3.3",
"ms": "2.1.3",
"node-cron": "3.0.3",
"pg": "8.11.3",
@ -48,14 +48,14 @@
"sequelize": "6.35.2",
"simple-git": "3.22.0",
"systeminformation": "5.21.22",
"undici": "6.2.1"
"undici": "6.3.0"
},
"devDependencies": {
"@types/ms": "0.7.34",
"@types/node": "20.10.7",
"@types/node": "20.11.0",
"@types/node-cron": "3.0.11",
"@types/pg": "8.10.9",
"@types/sequelize": "4.28.19",
"@types/sequelize": "4.28.20",
"typescript": "5.3.3"
}
}

View File

@ -125,13 +125,13 @@ export default class Developer {
},
modify_rank_msgs: async()=>{
const member = interaction.options.getMember('member');
const messages = interaction.options.getInteger('new-messages-count');
const messages = interaction.options.getInteger('new-message-count');
const oldData = await client.userLevels.fetchUser(member.id);
const newData = await client.userLevels.modifyUser(member.id, messages);
await interaction.reply({embeds:[new client.embed()
.setColor(client.config.embedColorGreen)
.setDescription(MessageTool.concatMessage(
`Successfully modified the messages count of **${member.displayName}**`,
`Successfully modified the message count of **${member.displayName}**`,
`╰ Old: **${oldData.dataValues.messages.toLocaleString('en-US')}**`,
`╰ New: **${newData.messages.toLocaleString('en-US')}**`,
`╰ Difference: **${(newData.messages - oldData.dataValues.messages).toLocaleString('en-US')}**`,
@ -211,11 +211,11 @@ export default class Developer {
.setDescription('Modify the messages count of a member')
.addUserOption(x=>x
.setName('member')
.setDescription('Member to modify the messages count of')
.setDescription('Member to modify the message count of')
.setRequired(true))
.addIntegerOption(x=>x
.setName('new-messages-count')
.setDescription('Replace the messages count of the member with this number')
.setName('new-message-count')
.setDescription('Replace the message count of the member with this number')
.setRequired(true)
.setMinValue(5)
.setMaxValue(1999999999)))

18
src/commands/reminder.ts Normal file
View File

@ -0,0 +1,18 @@
import Discord from 'discord.js';
import TClient from '../client.js';
import Punish from '../components/Punish.js';
export default class Reminder {
static run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
Punish(client, interaction, 'remind');
}
static data = new Discord.SlashCommandBuilder()
.setName('reminder')
.setDescription('Remind a member that they\'re breaking the rules')
.addUserOption(x=>x
.setName('member')
.setDescription('Which member to remind?')
.setRequired(true))
.addStringOption(x=>x
.setName('reason')
.setDescription('Reason for the reminder'))
}

View File

@ -1,8 +1,8 @@
import Discord from 'discord.js';
import TClient from '../client.js';
import MessageTool from '../helpers/MessageTool.js';
export default async(client:TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>, type: string)=>{
if (!MessageTool.isStaff(interaction.member)) return MessageTool.youNeedRole(interaction, 'dcmod');
export default async(client:TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>, type: 'ban'|'softban'|'kick'|'mute'|'warn'|'remind')=>{
if (!MessageTool.isModerator(interaction.member)) return MessageTool.youNeedRole(interaction, 'dcmod');
const time = interaction.options.getString('time') ?? undefined;
const reason = interaction.options.getString('reason') ?? 'Reason unspecified';

View File

@ -14,4 +14,5 @@ export default class MessageTool {
static formatMention =(mention:string, type:'user'|'channel'|'role')=>`<${type === 'role' ? '@&' : type === 'channel' ? '#' : '@'}${mention}>`;
static isStaff =(guildMember:Discord.GuildMember)=>config.dcServer.staffRoles.map((x:string)=>config.dcServer.roles[x]).some((x:string)=>guildMember.roles.cache.has(x));
static youNeedRole =(interaction:Discord.CommandInteraction, role:RoleKeys)=>interaction.reply(`You do not have ${this.formatMention(config.dcServer.roles[role], 'role')} role to use this command.`);
static isModerator =(guildMember:Discord.GuildMember)=>config.dcServer.staffRoles.filter((x:string)=>/^admin|^dcmod/.test(x)).map((x:string)=>config.dcServer.roles[x]).some((x:string)=>guildMember.roles.cache.has(x));
}

View File

@ -139,7 +139,8 @@ export class PunishmentsSvc {
softban: 'softbanned',
kick: 'kicked',
mute: 'muted',
warn: 'warned'
warn: 'warned',
remind: 'reminded'
}[type];
}
async punishmentAdd(type:string, options:{time?:string, interaction?:Discord.ChatInputCommandInteraction}, moderator:string, reason: string, user:Discord.User, guildUser?:Discord.GuildMember) {
@ -147,7 +148,7 @@ export class PunishmentsSvc {
const now = Date.now();
const guild = this.client.guilds.cache.get(this.client.config.dcServer.id) as Discord.Guild;
const punishment:Punishment = {type, case_id: await this.generateCaseId(), member: user.id, reason, moderator, time: now};
const inOrFromBoolean = ['warn', 'mute'].includes(type) ? 'in' : 'from';
const inOrFromBoolean = ['warn', 'mute', 'remind'].includes(type) ? 'in' : 'from';
const auditLogReason = `${reason ?? 'Reason unspecified'} | Case #${punishment.case_id}`;
const embed = new this.client.embed()
.setColor(this.client.config.embedColor)

View File

@ -60,6 +60,10 @@ export class UserLevelsSvc {
await this.model.update({messages: updatedMessages}, {where: {id: userId}});
return (await this.model.findByPk(userId)).dataValues;
}
async getActiveUsers() {
const members = (await this.model.findAll()).sort((a,b)=>b.dataValues.messages-a.dataValues.messages);
return members.slice(0, 5);
}
async messageIncremental(userId:string) {
const data = await this.model.findByPk(userId);
if (data) {
@ -82,19 +86,27 @@ export class UserLevelsSvc {
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.getActiveUsers();
Logger.console('log', 'Cron:resetAllData', `Counted ${performCountBeforeReset.toLocaleString()} members before reset`);
await this.client.dailyMsgs.nukeDays();
await this.model.drop().then(async()=>await this.model.sync());
// Send notification to dcServer's logs channel after cronjob is complete.
(this.client.channels.resolve(this.client.config.dcServer.channels.logs) 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.`
))
]});
try {
// Send notification to dcServer's logs channel after cronjob is complete.
(this.client.channels.resolve(this.client.config.dcServer.channels.logs) 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`,
'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`)
))
]});
} catch (why) {
Logger.console('error', 'Cron:resetAllData:DEBUG', why)
}
// Reset LRSstart to current Epoch and save it to config file
const newEpoch = new Date().getTime();

View File

@ -441,12 +441,12 @@ __metadata:
languageName: node
linkType: hard
"@types/node@npm:*, @types/node@npm:20.10.7":
version: 20.10.7
resolution: "@types/node@npm:20.10.7"
"@types/node@npm:*, @types/node@npm:20.11.0":
version: 20.11.0
resolution: "@types/node@npm:20.11.0"
dependencies:
undici-types: "npm:~5.26.4"
checksum: 4a1ba3fb7fc0a262c6b2d5ec763cec7abf5b5d6b2d277798ddbf05227f5778f9a806987821fd4d3eacd6f37c946ac61a9c64fb79ae4b84daaec12354158835a3
checksum: 8da60a8ccb65181c3d6f7686ddc5f1b1616cafa14d9e520a866adff82c17cc99336a78dd7ce7bee8f54e2332946f678b0e3aa377fbaaf751d3c05b64600872c6
languageName: node
linkType: hard
@ -461,15 +461,15 @@ __metadata:
languageName: node
linkType: hard
"@types/sequelize@npm:4.28.19":
version: 4.28.19
resolution: "@types/sequelize@npm:4.28.19"
"@types/sequelize@npm:4.28.20":
version: 4.28.20
resolution: "@types/sequelize@npm:4.28.20"
dependencies:
"@types/bluebird": "npm:*"
"@types/continuation-local-storage": "npm:*"
"@types/lodash": "npm:*"
"@types/validator": "npm:*"
checksum: 6378a703fc427808b11d9d31e426f2ad57a7ebc727bb1133981bc4bcdd07b378132c9ab40d487d9f433f6b048c51c29f18e903a4ffdaf2cea25b34e11fc7c53f
checksum: 8b3faec2e650ee299ae8a8a06bab7bd928131938ba34c7faa1d5c099682d6649e7aa68b0540a3e4883db7e3bc10d043ae3f23624d11b42a60f6bcbd40800ffac
languageName: node
linkType: hard
@ -748,15 +748,15 @@ __metadata:
"@octokit/rest": "npm:20.0.2"
"@toast/tokenservice-client": "npm:1.0.6"
"@types/ms": "npm:0.7.34"
"@types/node": "npm:20.10.7"
"@types/node": "npm:20.11.0"
"@types/node-cron": "npm:3.0.11"
"@types/pg": "npm:8.10.9"
"@types/sequelize": "npm:4.28.19"
"@types/sequelize": "npm:4.28.20"
ansi-colors: "npm:4.1.3"
canvas: "npm:2.11.2"
dayjs: "npm:1.11.10"
discord.js: "npm:14.14.1"
fast-xml-parser: "npm:4.3.2"
fast-xml-parser: "npm:4.3.3"
ms: "npm:2.1.3"
node-cron: "npm:3.0.3"
pg: "npm:8.11.3"
@ -766,7 +766,7 @@ __metadata:
simple-git: "npm:3.22.0"
systeminformation: "npm:5.21.22"
typescript: "npm:5.3.3"
undici: "npm:6.2.1"
undici: "npm:6.3.0"
languageName: unknown
linkType: soft
@ -920,14 +920,14 @@ __metadata:
languageName: node
linkType: hard
"fast-xml-parser@npm:4.3.2":
version: 4.3.2
resolution: "fast-xml-parser@npm:4.3.2"
"fast-xml-parser@npm:4.3.3":
version: 4.3.3
resolution: "fast-xml-parser@npm:4.3.3"
dependencies:
strnum: "npm:^1.0.5"
bin:
fxparser: src/cli/cli.js
checksum: cb3d9ad7d5508e7ec1e6ee4b4753f659c7b7c93c3eb76439cb03072532d07521d53a7e35f243b490dce3fcc16519415bf1f99c6a1004a6de1dccd3d3647c336f
checksum: 501de1f38d9d22c98b8f722fe27a3bb6907cf82a4e37639aa5702f725721424123a1a05a3cc19ec5f3c995ba65fadc7891b10d425eb0dc833580d32aff373777
languageName: node
linkType: hard
@ -2169,6 +2169,15 @@ __metadata:
languageName: node
linkType: hard
"undici@npm:6.3.0":
version: 6.3.0
resolution: "undici@npm:6.3.0"
dependencies:
"@fastify/busboy": "npm:^2.0.0"
checksum: 4534474384267ea2818b23a61daa6d851895e9caa9998be0bd71687322f7fbad653ffbaba084bc9d75f41ae2ac1c27adab65d631837890e26a2a52a8e0408ec4
languageName: node
linkType: hard
"unique-filename@npm:^3.0.0":
version: 3.0.0
resolution: "unique-filename@npm:3.0.0"