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

Compare commits

..

3 Commits

Author SHA1 Message Date
AnxietyisReal
32dda719e4 Increase PD capacity to 1920 from 256 2023-12-29 02:43:04 +11:00
AnxietyisReal
8c3052fee3 Refactor role conflict handling in interactionCreate.ts 2023-12-29 01:20:10 +11:00
AnxietyisReal
815f4aa3bb Add CLI args to TSClient 2023-12-29 00:28:44 +11:00
6 changed files with 21 additions and 26 deletions

15
.pnp.cjs generated
View File

@ -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.4.8"]\ ["@types/node", "npm:20.10.5"]\
],\ ],\
"linkType": "HARD"\ "linkType": "HARD"\
}]\ }]\
@ -644,13 +644,6 @@ const RAW_RUNTIME_STATE =
["undici-types", "npm:5.26.5"]\ ["undici-types", "npm:5.26.5"]\
],\ ],\
"linkType": "HARD"\ "linkType": "HARD"\
}],\
["npm:20.4.8", {\
"packageLocation": "./.yarn/cache/@types-node-npm-20.4.8-f8f2d8d349-199b047de6.zip/node_modules/@types/node/",\
"packageDependencies": [\
["@types/node", "npm:20.4.8"]\
],\
"linkType": "HARD"\
}]\ }]\
]],\ ]],\
["@types/node-cron", [\ ["@types/node-cron", [\
@ -667,7 +660,7 @@ const RAW_RUNTIME_STATE =
"packageLocation": "./.yarn/cache/@types-pg-npm-8.10.9-ee8620c8e7-787be5431a.zip/node_modules/@types/pg/",\ "packageLocation": "./.yarn/cache/@types-pg-npm-8.10.9-ee8620c8e7-787be5431a.zip/node_modules/@types/pg/",\
"packageDependencies": [\ "packageDependencies": [\
["@types/pg", "npm:8.10.9"],\ ["@types/pg", "npm:8.10.9"],\
["@types/node", "npm:20.4.8"],\ ["@types/node", "npm:20.10.5"],\
["pg-protocol", "npm:1.6.0"],\ ["pg-protocol", "npm:1.6.0"],\
["pg-types", "npm:4.0.1"]\ ["pg-types", "npm:4.0.1"]\
],\ ],\
@ -701,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.4.8"]\ ["@types/node", "npm:20.10.5"]\
],\ ],\
"linkType": "HARD"\ "linkType": "HARD"\
}]\ }]\
@ -2732,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.4.8"]\ ["@types/node", "npm:20.10.5"]\
],\ ],\
"linkType": "HARD"\ "linkType": "HARD"\
}]\ }]\

View File

@ -8,7 +8,7 @@
"url": "git+https://github.com/AnxietyisReal/Daggerbot-TS.git" "url": "git+https://github.com/AnxietyisReal/Daggerbot-TS.git"
}, },
"scripts": { "scripts": {
"dev": "yarn tsc && yarn node . src/DB-Beta.config.json", "dev": "yarn tsc && yarn node . src/DB-Beta.config.json daggerbotbeta",
"sdk": "yarn dlx @yarnpkg/sdks vscode" "sdk": "yarn dlx @yarnpkg/sdks vscode"
}, },
"author": "Toast", "author": "Toast",

View File

@ -1,6 +1,7 @@
import Discord from 'discord.js'; import Discord from 'discord.js';
import TClient from '../client.js'; import TClient from '../client.js';
import Logger from '../helpers/Logger.js'; import Logger from '../helpers/Logger.js';
import MessageTool from '../helpers/MessageTool.js';
export default class InteractionCreate { export default class InteractionCreate {
static async run(client:TClient, interaction:Discord.BaseInteraction){ static async run(client:TClient, interaction:Discord.BaseInteraction){
if (!interaction.inGuild() || !interaction.inCachedGuild()) return; if (!interaction.inGuild() || !interaction.inCachedGuild()) return;
@ -30,14 +31,14 @@ export default class InteractionCreate {
if (interaction.customId.startsWith('reaction-') && client.config.botSwitches.buttonRoles){ if (interaction.customId.startsWith('reaction-') && client.config.botSwitches.buttonRoles){
const RoleID = interaction.customId.replace('reaction-',''); const RoleID = interaction.customId.replace('reaction-','');
let roleConflictMsg = 'Cannot have both roles! - Button Role';
const MFFarm1 = '1149139369433776269'; const MFFarm1 = '1149139369433776269';
const MFFarm2 = '1149139583729160325'; const MFFarm2 = '1149139583729160325';
if (interaction.member.roles.cache.has(MFFarm1) && RoleID === MFFarm2) interaction.member.roles.remove(MFFarm1, roleConflictMsg);
else if (interaction.member.roles.cache.has(MFFarm2) && RoleID === MFFarm1) interaction.member.roles.remove(MFFarm2, roleConflictMsg);
if (interaction.member.roles.cache.has(RoleID)) interaction.member.roles.remove(RoleID, 'Button Role').then(()=>interaction.reply({content: `You have been removed from <@&${RoleID}>`, ephemeral: true})); if (interaction.member.roles.cache.has(RoleID)) interaction.member.roles.remove(RoleID, 'Button Role').then(()=>interaction.reply({content: `You have been removed from <@&${RoleID}>`, ephemeral: true}));
else interaction.member.roles.add(RoleID, 'Button Role').then(()=>interaction.reply({content: `You have been added to <@&${RoleID}>`, ephemeral: true})); else interaction.member.roles.add(RoleID, 'Button Role').then(()=>{
this.roleConflictHandler(interaction, MFFarm1, MFFarm2, RoleID);
interaction.reply({content: `You have been added to <@&${RoleID}>`, ephemeral: true, fetchReply: true})
});
} else if (interaction.customId.includes('deleteEvalEmbed')) { } else if (interaction.customId.includes('deleteEvalEmbed')) {
if (!client.config.whitelist.includes(interaction.user.id)) return interaction.reply({content: 'You are not whitelisted, therefore you cannot delete this message.', ephemeral: true}); if (!client.config.whitelist.includes(interaction.user.id)) return interaction.reply({content: 'You are not whitelisted, therefore you cannot delete this message.', ephemeral: true});
interaction.message.delete(); interaction.message.delete();
@ -45,4 +46,12 @@ export default class InteractionCreate {
} else Logger.console('log', logPrefix, `Button has been pressed at ${interaction.message.url}`); } else Logger.console('log', logPrefix, `Button has been pressed at ${interaction.message.url}`);
} }
} }
static roleConflictHandler(interaction:Discord.ButtonInteraction<'cached'>, role1:Discord.Snowflake, role2:Discord.Snowflake, newRole:Discord.Snowflake) {
if (interaction.member.roles.cache.has(role1) && interaction.member.roles.cache.has(role2)) {
const roleToRemove = newRole === role1 ? role2 : role1;
interaction.member.roles.remove(roleToRemove, 'Cannot have both roles! - Button Role').then(()=>interaction.editReply({
content: `You cannot have both farm roles, so you have been removed from ${MessageTool.formatMention(roleToRemove, 'role')} and added to ${MessageTool.formatMention(newRole, 'role')}`}
));
}
}
} }

View File

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

View File

@ -98,7 +98,7 @@ export class MPServerSvc {
const findServerByName = await this.model.findOne({where: {serverName: serverName}}); const findServerByName = await this.model.findOne({where: {serverName: serverName}});
if (findServerByName) { if (findServerByName) {
let PD = findServerByName.dataValues.playerData; let PD = findServerByName.dataValues.playerData;
if (PD.length > 256) PD = []; if (PD.length > 1920) PD = []; //Selfnote: 86400/45 = 1920, where 86400 is seconds in a day and 45 is the MPModule's refresh interval.
PD.push(playerCount); PD.push(playerCount);
const updatePD = await this.model.update({playerData: PD}, {where: {serverName: serverName}}); const updatePD = await this.model.update({playerData: PD}, {where: {serverName: serverName}});
if (updatePD) true; if (updatePD) true;

View File

@ -441,14 +441,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@types/node@npm:*": "@types/node@npm:*, @types/node@npm:20.10.5":
version: 20.4.8
resolution: "@types/node@npm:20.4.8"
checksum: 199b047de67708c36d4c432d46a6b9ef2cef4bfbf0c0e0b6831aee1a9c071e8430287a7cba18ea3c0b7d0332bc5e69e2bf71ba2da022769990e5551b90a65b18
languageName: node
linkType: hard
"@types/node@npm:20.10.5":
version: 20.10.5 version: 20.10.5
resolution: "@types/node@npm:20.10.5" resolution: "@types/node@npm:20.10.5"
dependencies: dependencies: