Skip to content

Commit 8b2b74a

Browse files
committed
Fixes
1 parent 868f4aa commit 8b2b74a

3 files changed

Lines changed: 32 additions & 11 deletions

File tree

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
.env
44
src/generated/
55

6-
src/commands/*.make.ts
7-
src/events/*.make.ts
6+
src/commands/*.make.ts
7+
src/events/*.make.ts
88
# ^ For commands/events that are being made - not ready for commits

src/commands/booster.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export default new Command({
146146

147147
if (booster.boostCounts == 0) {
148148
try {
149-
removeBoost(booster.userId, interaction.guild.id);
149+
await removeBoost(booster.userId, interaction.guild.id);
150150
} catch (err) {
151151
logger.error(
152152
`An error occured while removing ${booster.userId}'s data: ${err}`,
@@ -180,14 +180,18 @@ export default new Command({
180180
}
181181
}
182182

183+
const premiumSince = member?.premiumSince;
184+
const isActiveBooster =
185+
booster.active && booster.boostCounts > 0 && !!premiumSince;
186+
183187
const embed = new EmbedBuilder()
184188
.setColor(booster.active ? 0xf47fff : 0x99aab5)
185189
.setTitle(`Booster Info: ${user.username}`)
186190
.setThumbnail(avatarUrl)
187191
.addFields(
188192
{
189193
name: "Status",
190-
value: booster.active && booster.boostCounts > 0 ? "🟢 Active" : "🔴 Inactive",
194+
value: isActiveBooster ? "🟢 Active" : "🔴 Inactive",
191195
inline: true,
192196
},
193197
{
@@ -199,7 +203,9 @@ export default new Command({
199203
},
200204
{
201205
name: "Boosting since",
202-
value: `<t:${Math.floor(member!.premiumSince!.getTime() / 1000)}:D>`,
206+
value: premiumSince
207+
? `<t:${Math.floor(premiumSince.getTime() / 1000)}:D>`
208+
: "Not currently boosting",
203209
inline: true,
204210
},
205211
{
@@ -228,14 +234,17 @@ export default new Command({
228234
return;
229235
}
230236

231-
await registerBoost(
237+
const registered = await registerBoost(
232238
user.id,
233239
discordGuild.id,
234240
discordGuild.name,
235241
discordGuild.iconURL(),
236242
);
237243

238-
const updated = await addBoostCount(user.id, discordGuild.id, amount);
244+
const updated =
245+
amount > 1
246+
? await addBoostCount(user.id, discordGuild.id, amount - 1)
247+
: registered;
239248
if (!updated) {
240249
await interaction.editReply({
241250
content: "Failed to update boost count.",

src/libs/loops.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,36 @@ export async function loadLoops() {
2525

2626
for (const file of loopFiles) {
2727
const filePath = path.join(loops, file);
28-
const fileInfo = (await import(pathToFileURL(filePath).href)).default;
29-
console.log(file);
28+
let fileInfo;
29+
try {
30+
fileInfo = (await import(pathToFileURL(filePath).href)).default;
31+
} catch (err) {
32+
logger.error(`Failed to load loop "${file}": ${err}`);
33+
continue;
34+
}
3035

3136
if (!fileInfo?.runEvery || !fileInfo?.execute) {
3237
logger.warn(`Skipping ${file} - missing runEvery or execute`);
3338
continue;
3439
}
3540

3641
const run = async () => {
42+
if (running) return;
43+
running = true;
3744
try {
3845
await fileInfo.execute();
3946
} catch (err) {
4047
logger.error(`Loop "${file}" failed: ${err}`);
48+
} finally {
49+
running = false;
4150
}
4251
};
4352

44-
run();
45-
setInterval(run, fileInfo.runEvery * 1000);
53+
let running = false;
54+
void run();
55+
setInterval(() => {
56+
void run();
57+
}, fileInfo.runEvery * 1000);
4658

4759
logger.success(`Loaded loop "${file}"`);
4860
}

0 commit comments

Comments
 (0)