Skip to content

Commit

Permalink
fix: fix error handling in getOrCreateWebhook
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Nov 9, 2023
1 parent d7290c8 commit 0c550ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/commands/slash/Main/hub/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Hub from './index.js';
import db from '../../../../utils/Db.js';
import BlacklistManager from '../../../../managers/BlacklistManager.js';
import { hubs } from '@prisma/client';
import { getOrCreateWebhook } from '../../../../utils/Utils.js';
import { errorEmbed, getOrCreateWebhook } from '../../../../utils/Utils.js';
import { showOnboarding } from '../../../../scripts/network/onboarding.js';
import { stripIndents } from 'common-tags';

Expand Down Expand Up @@ -98,7 +98,16 @@ export default class JoinSubCommand extends Hub {
}

const webhook = await getOrCreateWebhook(channel);
if (!webhook) return;
if (!webhook) {
await interaction.editReply({
embeds: [
errorEmbed(
`${emojis.no} I could not create a webhook in ${channel}. Please make sure I have the \`Manage Webhooks\` permission in that channel.`,
),
],
});
return;
}

// finally make the connection
await networkManager.createConnection({
Expand Down
7 changes: 3 additions & 4 deletions src/managers/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ export default class NetworkManager extends Factory {
// preview embed for the message being replied to
const replyEmbed = replyContent
? new EmbedBuilder({
description:
replyContent.length > 30 ? replyContent?.slice(0, 30) + '...' : replyContent,
description: replyContent,
author: {
name: `${referredMessage?.author.username.slice(0, 30)}`,
icon_url: referredMessage?.author.displayAvatarURL(),
Expand Down Expand Up @@ -342,8 +341,8 @@ export default class NetworkManager extends Factory {
if (!referredContent) {
referredContent = '*Original message contains attachment <:attachment:1102464803647275028>*';
}
else if (referredContent.length > 1000) {
referredContent = referredContent.slice(0, 1000) + '...';
else if (referredContent.length > 100) {
referredContent = referredContent.slice(0, 100) + '...';
}

return referredContent;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function getOrCreateWebhook(
? channel
: channel.parent;

const webhooks = await channelOrParent?.fetchWebhooks();
const webhooks = await channelOrParent?.fetchWebhooks().catch(() => null);
const existingWebhook = webhooks?.find((w) => w.owner?.id === channel.client.user?.id);

if (existingWebhook) {
Expand All @@ -95,7 +95,7 @@ export async function getOrCreateWebhook(
return await channelOrParent?.createWebhook({
name: 'InterChat Network',
avatar,
});
}).catch(() => undefined);
}

export function getCredits() {
Expand Down

0 comments on commit 0c550ab

Please sign in to comment.