adding debounce

This commit is contained in:
Aster Fialla
2026-02-23 08:47:27 -05:00
parent 264c3e19fd
commit 1d27db960c
6 changed files with 17 additions and 11 deletions

View File

@@ -70,9 +70,10 @@ function printGuilds() {
}
const debouncePrintGuilds = utils.debounce(printGuilds, 2000);
const debounceLogin = utils.debounce(client.login, 60000);
try {
await client.login(token);
await debounceLogin(token);
// await db.check_connection();
} catch (err) {
console.error('Login failed:', err);

View File

@@ -54,7 +54,7 @@ cmds.set('import', {
if ((message.content.includes('--help') || (args[0] === '' && args.length === 1)) && !attachmentUrl ) {
return await message.reply(enums.help.IMPORT);
}
return await importHelper.pluralKitImport(message.author.id, attachmentUrl).then(async (successfullyAdded) => {
return await importHelper.debounceImport(message.author.id, attachmentUrl).then(async (successfullyAdded) => {
await message.reply(successfullyAdded);
}).catch(async (error) => {
if (error instanceof AggregateError) {

View File

@@ -1,5 +1,6 @@
import {enums} from "../enums.js";
import {memberHelper} from "./memberHelper.js";
import {utils} from "./utils.js";
const ih = {};
@@ -40,4 +41,6 @@ ih.pluralKitImport = async function (authorId, attachmentUrl) {
});
}
ih.debounceImport = utils.debounce(ih.pluralKitImport, 5000);
export const importHelper = ih;

View File

@@ -296,7 +296,7 @@ mh.updateProxy = async function (authorId, memberName, proxy) {
mh.updatePropic = async function (authorId, memberName, values, attachmentUrl = null, attachmentExpiration = null) {
const imgUrl = values ?? attachmentUrl;
// Throws error if invalid
await utils.checkImageFormatValidity(imgUrl).catch((e) => { throw e });
await utils.debounceCheckImageFormat(imgUrl).catch((e) => { throw e });
return await mh.updateMemberField(authorId, memberName, "propic", imgUrl, attachmentExpiration).catch((e) => { throw e });
}
@@ -381,7 +381,7 @@ mh.addFullMember = async function (authorId, memberName, displayName = null, pro
let isValidPropic;
if (propic && propic.length > 0) {
await utils.checkImageFormatValidity(propic).then(() => {
await utils.debounceCheckImageFormat(propic).then(() => {
isValidPropic = true;
}).catch((e) => {
errors.push(`Tried to set profile picture to \"${propic}\". ${e.message}. ${enums.err.SET_TO_NULL}`);

View File

@@ -26,4 +26,6 @@ u.checkImageFormatValidity = async function (imageUrl) {
});
}
u.debounceCheckImageFormat = u.debounce(u.checkImageFormatValidity, 60000);
export const utils = u;