Skip to content

Commit

Permalink
Fix some crashes wit hcalls
Browse files Browse the repository at this point in the history
  • Loading branch information
SunburntRock89 committed May 22, 2023
1 parent cefd960 commit ef7e8a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/internals/callClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ export default class CallClient implements CallsWithNumbers {
t: getFixedT(toNumber.guild?.locale || "en-US", undefined, "commands.call"),
};

// Don't bother sending it if we can find it on this shard
const eventReceivingOtherSideShardID = await this.client.shardIdForChannelId(this.to.channelID);

await db.activeCalls.create({
data: {
Expand All @@ -235,9 +237,6 @@ export default class CallClient implements CallsWithNumbers {
},
});

// Don't bother sending it if we can find it on this shard
const eventReceivingOtherSideShardID = await this.client.shardIdForChannelId(this.to.channelID);

if (eventReceivingOtherSideShardID !== Number(process.env.SHARDS)) {
// Send the call to another shard if required
this.otherSideShardID = await this.client.shardIdForChannelId(this.to.channelID);
Expand Down Expand Up @@ -322,6 +321,12 @@ export default class CallClient implements CallsWithNumbers {
],
});

await db.activeCalls.delete({
where: {
id: this.id,
},
});

return;
}

Expand Down
6 changes: 5 additions & 1 deletion src/internals/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class DTelClient extends Client<true> {
if (!process.env.SHARD_COUNT || Number(process.env.SHARD_COUNT) == 1) return 0;
const channelObject = await this.rest.get(`/channels/${id}`) as APITextChannel;

if (channelObject && !channelObject.guild_id) return 0;

return ShardClientUtil.shardIdForGuildId(channelObject.guild_id as string, Number(process.env.SHARD_COUNT));
}

Expand All @@ -94,7 +96,7 @@ class DTelClient extends Client<true> {
// Not safe to cache this as we won't get its updates
return this.channels.fetch(id, {
cache: false,
});
}).catch(() => null);
}

async getPerms(userID: string): Promise<Omit<PermissionLevel, "serverAdmin">> {
Expand Down Expand Up @@ -214,6 +216,8 @@ class DTelClient extends Client<true> {
},
});

this.log(`📕 Number \`${number}\` has been automatically deassigned as its channel has been deleted.`);

let ownerDMChannel: DMChannel | null | undefined;

if (numberDoc.guildID) {
Expand Down

0 comments on commit ef7e8a5

Please sign in to comment.