Skip to content

Commit

Permalink
get rid of foreach 🖕
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik K committed Sep 21, 2023
1 parent 6ceff10 commit fa726a1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
17 changes: 7 additions & 10 deletions src/util/cooldownHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ module.exports = class VoteLogger {
* @private
*/
startSweeper() {
this.cooldownSweeperInterval = setInterval(
() => {
this.c.used.forEach((value, key) => {
if (value < Date.now()) {
this.c.used.delete(key);
}
});
},
15 * 60 * 1000,
);
this.cooldownSweeperInterval = setInterval(() => {
for (const [key, value] of this.c.used.entries()) {
if (value < Date.now()) {
this.c.used.delete(key);
}
}
}, 15 * 60 * 1000);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/util/eventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module.exports = class EventHandler {
readdir("./src/events/", (err, files) => {
if (err) return console.error(err);

files.forEach((file) => {
for (const file of files) {
console.log(`Loading event ${file}`);
const event = require(`../events/${file}`);
let eventName = file.split(".")[0];

Expand All @@ -22,8 +23,8 @@ module.exports = class EventHandler {
} else {
this.c.on(eventName, event.bind(null, this.c));
}
}
});
});
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/util/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ module.exports = class Paginator {
.setStyle("Secondary"),
);

this.pages.forEach((e, i = 0) => {
for (let i = 0; i < this.pages.length; i++) {
const e = this.pages[i];
e.data.footer = {
text: `Would You | Page ${i + 1} / ${this.pages.length}`,
iconURL: this.client.user.avatarURL(),
};
});
}
const message = await interaction.reply({
embeds: [this.pages[0]],
components: [buttons],
Expand Down
11 changes: 6 additions & 5 deletions src/util/votingHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ module.exports = class Voting {

const options = ["op_one", "op_two"];

options.forEach((option) => {
for (const option of options) {
vote.votes[option] = vote.votes[option].filter((v) => v !== userId);
});
};

vote.votes[options[option]].push(userId);

Expand Down Expand Up @@ -206,14 +206,15 @@ module.exports = class Voting {

setTimeout(async () => {
const votes = await voteSchema.find();
votes.forEach((vote) => {
if (olderthen(new Date(vote.createdAt), 30))
for (const vote of votes) {
if (olderthen(new Date(vote.createdAt), 30))
return voteSchema.deleteOne({ id: vote.id }).catch((err) => {
Sentry.captureException(err);
return;
});
this._cache.set(vote.id, vote);
});
}


console.log(
`${ChalkAdvanced.white("Would You?")} ${ChalkAdvanced.gray(
Expand Down
4 changes: 2 additions & 2 deletions src/util/webhookHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module.exports = class WebhookHandler {

if (webhooks && webhooks.size > 0) {
let i = 0;
webhooks.forEach((web) => {
for (const web of webhooks) {
i++;
setInterval(() => {
if (web?.owner?.id === this.c?.user?.id) {
Expand All @@ -140,7 +140,7 @@ module.exports = class WebhookHandler {
});
}
}, 1000 * i);
});
};
}

const webhook = await this.createWebhook(
Expand Down

0 comments on commit fa726a1

Please sign in to comment.