Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 96843b1

Browse files
committed
refactor: add await to all promises to avoid unhandled rejections
1 parent 4aeceaf commit 96843b1

File tree

22 files changed

+85
-66
lines changed

22 files changed

+85
-66
lines changed

src/InterChat.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class InterChat extends SuperClient {
2121
public constructor() {
2222
super();
2323

24-
this.once('ready', () => {
24+
this.once('ready', async () => {
2525
// initialize the client
2626
this.boot();
2727

2828
// initialize i18n for localization
2929
loadLocales('locales/src/locales');
3030

3131
// load commands
32-
CommandManager.loadCommandFiles();
32+
await CommandManager.loadCommandFiles();
3333

3434
Logger.info(`Logged in as ${this.user?.tag}!`);
3535
});
@@ -47,7 +47,7 @@ class InterChat extends SuperClient {
4747
Logger.info(`Joined ${guild.name} (${guild.id})`);
4848

4949
// log that bot joined a guild to goal channel in support server
50-
logGuildJoin(guild, channels.goal);
50+
await logGuildJoin(guild, channels.goal);
5151

5252
const { guildOwner, guildChannel } = await getWelcomeTargets(guild);
5353

src/commands/slash/Main/blacklist/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export default class BlacklistCommand extends BaseCommand {
225225
const choices = filteredUsers.map((user) => {
226226
return { name: user.username ?? `Unknown User - ${user.userId}`, value: user.userId };
227227
});
228-
interaction.respond(choices);
228+
await interaction.respond(choices);
229229
break;
230230
}
231231

src/commands/slash/Main/blacklist/server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default class UserBlacklist extends BlacklistCommand {
8888
catch (err) {
8989
Logger.error(err);
9090
captureException(err);
91-
interaction.followUp({
91+
await interaction.followUp({
9292
embeds: [
9393
simpleEmbed(
9494
t({
@@ -129,7 +129,9 @@ export default class UserBlacklist extends BlacklistCommand {
129129
await interaction.followUp({ embeds: [successEmbed] });
130130

131131
// notify the server that they have been blacklisted
132-
blacklistManager.notifyBlacklist('server', serverOpt, hubInDb.id, expires, reason);
132+
await blacklistManager
133+
.notifyBlacklist('server', serverOpt, hubInDb.id, expires, reason)
134+
.catch(() => null);
133135

134136
// delete all connections from db so they can't reconnect to the hub
135137
await db.connectedList.deleteMany({ where: { serverId: server.id, hubId: hubInDb.id } });

src/commands/slash/Main/blacklist/user.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import parse from 'parse-duration';
66
import { emojis } from '../../../../utils/Constants.js';
77
import { simpleEmbed } from '../../../../utils/Utils.js';
88
import { t } from '../../../../utils/Locale.js';
9+
import Logger from '../../../../utils/Logger.js';
10+
import { captureException } from '@sentry/node';
911

1012
export default class Server extends BlacklistCommand {
1113
async execute(interaction: ChatInputCommandInteraction) {
@@ -92,7 +94,12 @@ export default class Server extends BlacklistCommand {
9294
expires,
9395
);
9496
if (expires) blacklistManager.scheduleRemoval('user', user.id, hubInDb.id, expires);
95-
blacklistManager.notifyBlacklist('user', user.id, hubInDb.id, expires, reason);
97+
await blacklistManager
98+
.notifyBlacklist('user', user.id, hubInDb.id, expires, reason)
99+
.catch((e) => {
100+
Logger.error(e);
101+
captureException(e);
102+
});
96103

97104
const successEmbed = new EmbedBuilder()
98105
.setDescription(

src/commands/slash/Main/connection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export default class Connection extends BaseCommand {
159159
return { name: `${hub?.name} | #${channel?.name || channelId}`, value: channelId };
160160
});
161161

162-
interaction.respond(await Promise.all(filtered));
162+
await interaction.respond(await Promise.all(filtered));
163163
}
164164

165165
@RegisterInteractionHandler('connection')
@@ -332,7 +332,7 @@ export default class Connection extends BaseCommand {
332332
simpleEmbed(
333333
t(
334334
{ phrase: 'connection.alreadyConnected', locale: interaction.user.locale },
335-
{ channel: `${newChannel}`, emoji: emojis.no },
335+
{ channel: `${newChannel?.toString()}`, emoji: emojis.no },
336336
),
337337
),
338338
],
@@ -349,7 +349,7 @@ export default class Connection extends BaseCommand {
349349
await interaction.editReply({
350350
content: t(
351351
{ phrase: 'connection.switchSuccess', locale: interaction.user.locale },
352-
{ channel: `${newChannel}`, emoji: emojis.yes },
352+
{ channel: `${newChannel?.toString()}`, emoji: emojis.yes },
353353
),
354354
// remove error embed, if it occured
355355
embeds: [],
@@ -408,7 +408,7 @@ export default class Connection extends BaseCommand {
408408

409409
const hex_regex = /^#[0-9A-F]{6}$/i;
410410
if (embedColor && !hex_regex.test(embedColor)) {
411-
interaction.reply({
411+
await interaction.reply({
412412
content: t(
413413
{ phrase: 'connection.emColorInvalid', locale: interaction.user.locale },
414414
{ emoji: emojis.no },

src/commands/slash/Main/hub/browse.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default class Browse extends Hub {
100100
);
101101

102102
if (!hubList || hubList.length === 0) {
103-
interaction.reply({
103+
await interaction.reply({
104104
content: t(
105105
{ phrase: 'hub.browse.noHubs', locale: interaction.user.locale },
106106
{ emoji: emojis.no },
@@ -125,7 +125,7 @@ export default class Browse extends Hub {
125125
.setStyle(ButtonStyle.Success),
126126
);
127127

128-
paginate(interaction, hubList, {
128+
await paginate(interaction, hubList, {
129129
extraComponents: {
130130
actionRow: [paginateBtns],
131131
updateComponents(pageNumber) {
@@ -189,7 +189,7 @@ export default class Browse extends Hub {
189189
else if (customId.suffix === 'join') {
190190
const alreadyJoined = hubDetails.connections.find((c) => c.serverId === interaction.guildId);
191191
if (alreadyJoined) {
192-
interaction.reply({
192+
await interaction.reply({
193193
content: t(
194194
{ phrase: 'hub.alreadyJoined', locale: interaction.user.locale },
195195
{ hub: hubDetails.name, channel: `<#${alreadyJoined.channelId}>`, emoji: emojis.no },
@@ -350,7 +350,7 @@ export default class Browse extends Hub {
350350
await interaction.update({
351351
content: t(
352352
{ phrase: 'connection.alreadyConnected', locale: interaction.user.locale },
353-
{ channel: `${channel}`, emoji: emojis.no },
353+
{ channel: channel.toString(), emoji: emojis.no },
354354
),
355355
embeds: [],
356356
components: [],
@@ -401,7 +401,7 @@ export default class Browse extends Hub {
401401
await interaction.editReply({
402402
content: t(
403403
{ phrase: 'hub.join.success', locale: interaction.user.locale },
404-
{ hub: hubDetails.name, channel: `${channel}` },
404+
{ hub: hubDetails.name, channel: channel.toString() },
405405
),
406406
embeds: [],
407407
components: [],
@@ -449,7 +449,7 @@ export default class Browse extends Hub {
449449
const hubId = customId.args[0];
450450
const hub = await db.hubs.findFirst({ where: { id: hubId } });
451451
if (!hub) {
452-
interaction.reply({
452+
await interaction.reply({
453453
embeds: [
454454
simpleEmbed(
455455
t({ phrase: 'hub.notFound', locale: interaction.user.locale }, { emoji: emojis.no }),

src/commands/slash/Main/hub/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export default class Hub extends BaseCommand {
282282
interaction.options.getSubcommandGroup() || interaction.options.getSubcommand(),
283283
);
284284

285-
return await subcommand?.execute(interaction).catch((e) => handleError(e, interaction));
285+
return await subcommand?.execute(interaction).catch((e: Error) => handleError(e, interaction));
286286
}
287287

288288
async autocomplete(interaction: AutocompleteInteraction): Promise<unknown> {

src/commands/slash/Main/hub/join.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class JoinSubCommand extends Hub {
4747
simpleEmbed(
4848
t(
4949
{ phrase: 'hub.alreadyJoined', locale },
50-
{ channel: `${channel}`, hub: `${alrJoinedHub?.name}`, emoji: emojis.no },
50+
{ channel: `${channel.toString()}`, hub: `${alrJoinedHub?.name}`, emoji: emojis.no },
5151
),
5252
),
5353
],

src/commands/slash/Main/hub/joined.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class Joined extends Hub {
5757
}
5858
});
5959

60-
paginate(interaction, paginateEmbeds);
60+
await paginate(interaction, paginateEmbeds);
6161
return;
6262
}
6363

src/commands/slash/Main/hub/leave.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default class Leave extends Hub {
115115
// log server leave
116116
if (interaction.guild) {
117117
const hubId = customId.args[1];
118-
interaction.client.joinLeaveLogger.logServerLeave(hubId, interaction.guild);
118+
await interaction.client.joinLeaveLogger.logServerLeave(hubId, interaction.guild);
119119
}
120120
}
121121
}

0 commit comments

Comments
 (0)