From 7d374cab31d64668924501fe74b5d1b0aa0b0d19 Mon Sep 17 00:00:00 2001 From: dev-737 <73829355+dev-737@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:29:31 +0530 Subject: [PATCH 1/4] refactor(slashies): use contexts instead of deprecated dm_permission --- src/commands/context-menu/deleteMsg.ts | 3 ++- src/commands/context-menu/editMsg.ts | 3 ++- src/commands/context-menu/messageInfo.ts | 3 ++- src/commands/context-menu/modActions.ts | 3 ++- src/commands/context-menu/translate.ts | 3 ++- src/commands/slash/Main/connection/index.ts | 3 ++- src/commands/slash/Main/hub/index.ts | 6 +++--- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/commands/context-menu/deleteMsg.ts b/src/commands/context-menu/deleteMsg.ts index 7042d0f8..af5bc5a4 100644 --- a/src/commands/context-menu/deleteMsg.ts +++ b/src/commands/context-menu/deleteMsg.ts @@ -14,6 +14,7 @@ import { deleteMessageFromHub, isDeleteInProgress } from '#utils/moderation/dele import { Hub, HubLogConfig } from '@prisma/client'; import { ApplicationCommandType, + InteractionContextType, MessageContextMenuCommandInteraction, RESTPostAPIApplicationCommandsJSONBody, } from 'discord.js'; @@ -22,7 +23,7 @@ export default class DeleteMessage extends BaseCommand { readonly data: RESTPostAPIApplicationCommandsJSONBody = { type: ApplicationCommandType.Message, name: 'Delete Message', - dm_permission: false, + contexts: [InteractionContextType.Guild], }; readonly cooldown = 10_000; diff --git a/src/commands/context-menu/editMsg.ts b/src/commands/context-menu/editMsg.ts index c72fa908..6da87ad2 100644 --- a/src/commands/context-menu/editMsg.ts +++ b/src/commands/context-menu/editMsg.ts @@ -22,6 +22,7 @@ import { ActionRowBuilder, ApplicationCommandType, EmbedBuilder, + InteractionContextType, Message, MessageContextMenuCommandInteraction, ModalBuilder, @@ -42,7 +43,7 @@ export default class EditMessage extends BaseCommand { readonly data: RESTPostAPIApplicationCommandsJSONBody = { type: ApplicationCommandType.Message, name: 'Edit Message', - dm_permission: false, + contexts: [InteractionContextType.Guild], }; readonly cooldown = 10_000; diff --git a/src/commands/context-menu/messageInfo.ts b/src/commands/context-menu/messageInfo.ts index d9674728..695c981f 100644 --- a/src/commands/context-menu/messageInfo.ts +++ b/src/commands/context-menu/messageInfo.ts @@ -28,6 +28,7 @@ import { ComponentType, EmbedBuilder, Guild, + InteractionContextType, MessageContextMenuCommandInteraction, ModalBuilder, ModalSubmitInteraction, @@ -53,7 +54,7 @@ export default class MessageInfo extends BaseCommand { readonly data: RESTPostAPIApplicationCommandsJSONBody = { type: ApplicationCommandType.Message, name: 'Message Info/Report', - dm_permission: false, + contexts: [InteractionContextType.Guild], }; async execute(interaction: MessageContextMenuCommandInteraction) { diff --git a/src/commands/context-menu/modActions.ts b/src/commands/context-menu/modActions.ts index f9699ff5..1c51f65a 100644 --- a/src/commands/context-menu/modActions.ts +++ b/src/commands/context-menu/modActions.ts @@ -11,6 +11,7 @@ import { isStaffOrHubMod } from '#utils/hub/utils.js'; import { t, type supportedLocaleCodes } from '#utils/Locale.js'; import { ApplicationCommandType, + InteractionContextType, type MessageContextMenuCommandInteraction, type RepliableInteraction, type RESTPostAPIApplicationCommandsJSONBody, @@ -20,7 +21,7 @@ export default class BlacklistCtxMenu extends BaseCommand { readonly data: RESTPostAPIApplicationCommandsJSONBody = { type: ApplicationCommandType.Message, name: 'Moderation Actions', - dm_permission: false, + contexts: [InteractionContextType.Guild], }; async execute(interaction: MessageContextMenuCommandInteraction) { diff --git a/src/commands/context-menu/translate.ts b/src/commands/context-menu/translate.ts index 7cacca61..ec7b2c38 100644 --- a/src/commands/context-menu/translate.ts +++ b/src/commands/context-menu/translate.ts @@ -12,6 +12,7 @@ import { ButtonStyle, CacheType, EmbedBuilder, + InteractionContextType, MessageContextMenuCommandInteraction, ModalBuilder, ModalSubmitInteraction, @@ -25,7 +26,7 @@ export default class Translate extends BaseCommand { readonly data: RESTPostAPIApplicationCommandsJSONBody = { type: ApplicationCommandType.Message, name: 'Translate', - dm_permission: false, + contexts: [InteractionContextType.Guild], }; async execute(interaction: MessageContextMenuCommandInteraction): Promise { diff --git a/src/commands/slash/Main/connection/index.ts b/src/commands/slash/Main/connection/index.ts index f3b4412f..f2f65ee7 100644 --- a/src/commands/slash/Main/connection/index.ts +++ b/src/commands/slash/Main/connection/index.ts @@ -5,6 +5,7 @@ import { AutocompleteInteraction, ChatInputCommandInteraction, Collection, + InteractionContextType, PermissionFlagsBits, RESTPostAPIApplicationCommandsJSONBody, } from 'discord.js'; @@ -18,7 +19,7 @@ export default class Connection extends BaseCommand { name: 'connection', description: 'Pause, unpause or edit your connections to hubs in this server.', default_member_permissions: PermissionFlagsBits.ManageMessages.toString(), - dm_permission: false, + contexts: [InteractionContextType.Guild], options: [ { type: ApplicationCommandOptionType.Subcommand, diff --git a/src/commands/slash/Main/hub/index.ts b/src/commands/slash/Main/hub/index.ts index 21b2739d..2b572d1e 100644 --- a/src/commands/slash/Main/hub/index.ts +++ b/src/commands/slash/Main/hub/index.ts @@ -11,6 +11,7 @@ import { ChatInputCommandInteraction, Collection, Guild, + InteractionContextType, RESTPostAPIApplicationCommandsJSONBody, Snowflake, } from 'discord.js'; @@ -36,7 +37,7 @@ export default class HubCommand extends BaseCommand { readonly data: RESTPostAPIApplicationCommandsJSONBody = { name: 'hub', description: 'Manage your hubs.', - dm_permission: false, + contexts: [InteractionContextType.Guild], options: [ { type: ApplicationCommandOptionType.Subcommand, @@ -463,6 +464,7 @@ export default class HubCommand extends BaseCommand { } async autocomplete(interaction: AutocompleteInteraction): Promise { + const modCmds = ['servers', 'invite', 'announce']; const managerCmds = [ 'edit', 'visibility', @@ -471,9 +473,7 @@ export default class HubCommand extends BaseCommand { 'logging', 'appeal', 'blockwords', - 'announce', ]; - const modCmds = ['servers', 'invite']; const subcommand = interaction.options.getSubcommand(); const subcommandGroup = interaction.options.getSubcommandGroup(); From 370e32dc6c47efb483adcc09386ee9493167da28 Mon Sep 17 00:00:00 2001 From: dev-737 <73829355+dev-737@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:30:51 +0530 Subject: [PATCH 2/4] refactor: refactor subcommand handling --- locales/en.yml | 5 + src/commands/slash/Main/hub/blockwords.ts | 26 +- src/commands/slash/Main/hub/invite.ts | 329 +++++++++++----------- src/commands/slash/Main/hub/moderator.ts | 27 +- src/types/TranslationKeys.d.ts | 4 + 5 files changed, 199 insertions(+), 192 deletions(-) diff --git a/locales/en.yml b/locales/en.yml index c942ee28..0c61b78a 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -128,6 +128,11 @@ connection: hub: notFound: '{emoji} Unable to find hub. Please make sure you have entered the correct hub name.' notFound_mod: '{emoji} Unable to find hub. Please make sure you have entered the correct hub name & that you are the owner or a moderator of the hub.' + notManager: '{emoji} You must be a hub manager to perform this action.' + notModerator: '{emoji} You need to be a hub moderator to perform this action.' + notPrivate: '{emoji} This hub is not private.' + notOwner: '{emoji} Only the owner of this hub can perform this action.' + alreadyJoined: '{emoji} You have already joined **{hub}** from {channel}!' invalidChannel: '{emoji} Invalid channel. Only text and thread channels are supported!' invalidImgurUrl: '{emoji} Invalid image URL for icon or banner. Please make sure you have entered a valid Imgur image URL that is not a gallery or album.' diff --git a/src/commands/slash/Main/hub/blockwords.ts b/src/commands/slash/Main/hub/blockwords.ts index 7eabb062..20883597 100644 --- a/src/commands/slash/Main/hub/blockwords.ts +++ b/src/commands/slash/Main/hub/blockwords.ts @@ -35,19 +35,14 @@ export default class BlockWordCommand extends HubCommand { return; } - switch (interaction.options.getSubcommand()) { - case 'edit': - await this.handleEditSubcommand(interaction, hub); - break; - case 'list': - await this.handleList(interaction, hub); - break; - case 'create': - await this.handleAdd(interaction, hub); - break; - default: - break; - } + const handlers = { + edit: () => this.handleEditSubcommand(interaction, hub), + list: () => this.handleList(interaction, hub), + create: () => this.handleAdd(interaction, hub), + }; + + const subcommand = interaction.options.getSubcommand(true) as keyof typeof handlers; + await handlers[subcommand]?.(); } @RegisterInteractionHandler('blockwordsButton', 'editWords') @@ -92,6 +87,8 @@ export default class BlockWordCommand extends HubCommand { const name = interaction.fields.getTextInputValue('name'); const newWords = sanitizeWords(interaction.fields.getTextInputValue('words')); + + // new rule if (!ruleId) { if (hub.msgBlockList.length >= 2) { await interaction.editReply('You can only have 2 block word rules per hub.'); @@ -110,10 +107,13 @@ export default class BlockWordCommand extends HubCommand { components: [buttons], }); } + // remove rule else if (newWords.length === 0) { await db.messageBlockList.delete({ where: { id: ruleId } }); await interaction.editReply(`${emojis.yes} Rule removed.`); } + + // update rule else { await db.messageBlockList.update({ where: { id: ruleId }, data: { words: newWords, name } }); await interaction.editReply(`${emojis.yes} Rule updated.`); diff --git a/src/commands/slash/Main/hub/invite.ts b/src/commands/slash/Main/hub/invite.ts index d8a8b763..12447dc6 100644 --- a/src/commands/slash/Main/hub/invite.ts +++ b/src/commands/slash/Main/hub/invite.ts @@ -1,178 +1,183 @@ +import { handleError } from '#main/utils/Utils.js'; import Constants, { emojis } from '#utils/Constants.js'; import db from '#utils/Db.js'; -import { t } from '#utils/Locale.js'; -import Logger from '#utils/Logger.js'; -import { captureException } from '@sentry/node'; +import { supportedLocaleCodes, t } from '#utils/Locale.js'; import { CacheType, ChatInputCommandInteraction, EmbedBuilder } from 'discord.js'; import ms from 'ms'; import HubCommand from './index.js'; +import { HubService } from '#main/services/HubService.js'; +import { isHubManager } from '#main/utils/hub/utils.js'; +import { InfoEmbed } from '#main/utils/EmbedUtils.js'; export default class Invite extends HubCommand { readonly cooldown = 3000; // 3 seconds async execute(interaction: ChatInputCommandInteraction) { - const subcommand = interaction.options.getSubcommand(); - const { userManager } = interaction.client; const locale = await userManager.getUserLocale(interaction.user.id); - switch (subcommand) { - case 'create': { - const hubName = interaction.options.getString('hub', true); - const expiryStr = interaction.options.getString('expiry'); - const duration = expiryStr ? ms(expiryStr) : undefined; - const expires = new Date(Date.now() + (duration || 60 * 60 * 4000)); - - const hubInDb = await db.hub.findFirst({ - where: { - name: hubName, - private: true, - OR: [ - { ownerId: interaction.user.id }, - { moderators: { some: { userId: interaction.user.id, position: 'manager' } } }, - ], - }, - }); - - if (!hubInDb) { - await this.replyEmbed(interaction, t('hub.notFound_mod', locale, { emoji: emojis.no }), { - ephemeral: true, - }); - return; - } - - if (!Date.parse(expires.toString())) { - await interaction.reply({ - content: `${emojis.no} Invalid Expiry Duration provided!`, - ephemeral: true, - }); - return; - } - - const createdInvite = await db.hubInvite.create({ - data: { - hub: { connect: { name: hubName } }, - expires, - }, - }); - - const embed = new EmbedBuilder() - .setDescription( - t('hub.invite.create.success', locale, { - inviteCode: createdInvite.code, - docs_link: Constants.Links.Docs, - expiry: ``, - }), - ) - .setColor('Green') - .setTimestamp(); - - await interaction.reply({ - embeds: [embed], - ephemeral: true, - }); - break; - } - - case 'revoke': { - const code = interaction.options.getString('code', true); - const inviteInDb = await db.hubInvite.findFirst({ - where: { - code, - hub: { - OR: [ - { ownerId: interaction.user.id }, - { moderators: { some: { userId: interaction.user.id, position: 'manager' } } }, - ], - }, - }, - }); - - if (!inviteInDb) { - await interaction.reply({ - content: t('hub.invite.revoke.invalidCode', locale, { emoji: emojis.no }), - ephemeral: true, - }); - return; - } - - try { - await db.hubInvite.delete({ where: { code } }); - await this.replyEmbed( - interaction, - t('hub.invite.revoke.success', locale, { emoji: emojis.yes, inviteCode: code }), - { ephemeral: true }, - ); - } - catch (e) { - Logger.error(e); - captureException(e); - await this.replyEmbed( - interaction, - t('errors.unknown', locale, { - emoji: emojis.no, - support_invite: Constants.Links.SupportInvite, - }), - { - ephemeral: true, - }, - ).catch(() => null); - return; - } - break; - } - - case 'list': { - const hubName = interaction.options.getString('hub', true); - const hubInDb = await db.hub.findFirst({ - where: { - name: hubName, - OR: [ - { ownerId: interaction.user.id }, - { moderators: { some: { userId: interaction.user.id, position: 'manager' } } }, - ], - }, - }); - - if (!hubInDb?.private) { - await this.replyEmbed( - interaction, - t('hub.invite.list.notPrivate', locale, { emoji: emojis.no }), - { ephemeral: true }, - ); - return; - } - - const invitesInDb = await db.hubInvite.findMany({ where: { hubId: hubInDb.id } }); - if (invitesInDb.length === 0) { - await this.replyEmbed( - interaction, - t('hub.invite.list.noInvites', locale, { emoji: emojis.no }), - { ephemeral: true }, - ); - return; - } - - const inviteArr = invitesInDb.map( - (inv, index) => - `${index + 1}. \`${inv.code}\` - `, - ); - - const inviteEmbed = new EmbedBuilder() - .setTitle(t('hub.invite.list.title', locale)) - .setDescription(inviteArr.join('\n')) - .setColor('Yellow') - .setTimestamp(); - - await interaction.reply({ - embeds: [inviteEmbed], - ephemeral: true, - }); - break; - } - - default: - break; + const handlers = { + create: () => this.handleCreateSubcommand(interaction, locale), + revoke: () => this.handleRevokeSubcommand(interaction, locale), + list: () => this.handleListSubcommand(interaction, locale), + }; + + const subcommand = interaction.options.getSubcommand() as keyof typeof handlers; + await handlers[subcommand]?.(); + } + + private async handleCreateSubcommand( + interaction: ChatInputCommandInteraction, + locale: supportedLocaleCodes, + ) { + const hubName = interaction.options.getString('hub', true); + const expiryStr = interaction.options.getString('expiry'); + const duration = expiryStr ? ms(expiryStr) : undefined; + const expires = new Date(Date.now() + (duration || 60 * 60 * 4000)); + + const hubService = new HubService(db); + const hubInDb = await hubService.getHubByName(hubName); + + if (!hubInDb) { + await this.replyEmbed(interaction, 'hub.notFound_mod', { + t: { emoji: emojis.no }, + ephemeral: true, + }); + return; + } + else if (!hubInDb?.private) { + await this.replyEmbed(interaction, 'hub.notPrivate', { + t: { emoji: emojis.no }, + ephemeral: true, + }); + return; + } + + if (!isHubManager(interaction.user.id, hubInDb)) { + await this.replyEmbed(interaction, 'hub.notManager', { + t: { emoji: emojis.no }, + ephemeral: true, + }); + return; + } + + if (!Date.parse(expires.toString())) { + await interaction.reply({ + content: `${emojis.no} Invalid Expiry Duration provided!`, + ephemeral: true, + }); + return; + } + + const createdInvite = await db.hubInvite.create({ + data: { + hub: { connect: { name: hubName } }, + expires, + }, + }); + + const embed = new EmbedBuilder() + .setDescription( + t('hub.invite.create.success', locale, { + inviteCode: createdInvite.code, + docs_link: Constants.Links.Docs, + expiry: ``, + }), + ) + .setColor('Green') + .setTimestamp(); + + await interaction.reply({ + embeds: [embed], + ephemeral: true, + }); + } + + private async handleRevokeSubcommand( + interaction: ChatInputCommandInteraction, + locale: supportedLocaleCodes, + ) { + const code = interaction.options.getString('code', true); + const inviteInDb = await db.hubInvite.findFirst({ + where: { + code, + hub: { + OR: [ + { ownerId: interaction.user.id }, + { moderators: { some: { userId: interaction.user.id, position: 'manager' } } }, + ], + }, + }, + }); + + if (!inviteInDb) { + await interaction.reply({ + content: t('hub.invite.revoke.invalidCode', locale, { emoji: emojis.no }), + ephemeral: true, + }); + return; + } + + try { + await db.hubInvite.delete({ where: { code } }); + await this.replyEmbed( + interaction, + t('hub.invite.revoke.success', locale, { emoji: emojis.yes, inviteCode: code }), + { ephemeral: true }, + ); + } + catch (e) { + handleError(e, interaction); + return; + } + } + + private async handleListSubcommand( + interaction: ChatInputCommandInteraction, + locale: supportedLocaleCodes, + ) { + const hubName = interaction.options.getString('hub', true); + const hubInDb = await db.hub.findFirst({ + where: { + name: hubName, + OR: [ + { ownerId: interaction.user.id }, + { moderators: { some: { userId: interaction.user.id, position: 'manager' } } }, + ], + }, + }); + + if (!hubInDb?.private) { + await this.replyEmbed( + interaction, + t('hub.invite.list.notPrivate', locale, { emoji: emojis.no }), + { ephemeral: true }, + ); + return; + } + + const invitesInDb = await db.hubInvite.findMany({ where: { hubId: hubInDb.id } }); + if (invitesInDb.length === 0) { + await this.replyEmbed( + interaction, + t('hub.invite.list.noInvites', locale, { emoji: emojis.no }), + { ephemeral: true }, + ); + return; } + + const inviteArr = invitesInDb.map( + (inv, index) => + `${index + 1}. \`${inv.code}\` - `, + ); + + const inviteEmbed = new InfoEmbed() + .setTitle(t('hub.invite.list.title', locale)) + .setDescription(inviteArr.join('\n')); + + await interaction.reply({ + embeds: [inviteEmbed], + ephemeral: true, + }); } } diff --git a/src/commands/slash/Main/hub/moderator.ts b/src/commands/slash/Main/hub/moderator.ts index bfb7b686..47d81b2c 100644 --- a/src/commands/slash/Main/hub/moderator.ts +++ b/src/commands/slash/Main/hub/moderator.ts @@ -26,24 +26,17 @@ export default class Moderator extends HubCommand { return; } - switch (interaction.options.getSubcommand()) { - case 'add': - await this.handleAddSubcommand(interaction, hub, locale); - break; - case 'remove': - await this.handleRemoveSubcommand(interaction, hub, locale); - break; - case 'edit': - await this.handleEditSubcommand(interaction, hub, locale); - break; - case 'list': - await this.handleListSubcommand(interaction, hub, locale); - break; - - default: - break; - } + const handlers = { + add: () => this.handleAddSubcommand(interaction, hub, locale), + remove: () => this.handleRemoveSubcommand(interaction, hub, locale), + edit: () => this.handleEditSubcommand(interaction, hub, locale), + list: () => this.handleListSubcommand(interaction, hub, locale), + }; + + const subcommand = interaction.options.getSubcommand(true) as keyof typeof handlers; + await handlers[subcommand]?.(); } + private async handleRemoveSubcommand( interaction: ChatInputCommandInteraction, hub: Hub, diff --git a/src/types/TranslationKeys.d.ts b/src/types/TranslationKeys.d.ts index 317146b6..267c565b 100644 --- a/src/types/TranslationKeys.d.ts +++ b/src/types/TranslationKeys.d.ts @@ -63,6 +63,10 @@ export type TranslationKeys = { 'connection.paused.tips': 'unpause_cmd' | 'leave_cmd'; 'hub.notFound': 'emoji'; 'hub.notFound_mod': 'emoji'; + 'hub.notManager': 'emoji'; + 'hub.notModerator': 'emoji'; + 'hub.notPrivate': 'emoji'; + 'hub.notOwner': 'emoji'; 'hub.alreadyJoined': 'emoji' | 'hub' | 'channel'; 'hub.invalidChannel': 'emoji'; 'hub.invalidImgurUrl': 'emoji'; From ffb60c498b86be230dba835715b62c7d2b4af5ab Mon Sep 17 00:00:00 2001 From: dev-737 <73829355+dev-737@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:41:03 +0530 Subject: [PATCH 3/4] refactor: add new methods to HubService --- src/commands/slash/Main/hub/edit.ts | 26 +++++++------------------- src/services/HubService.ts | 10 +++++----- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/commands/slash/Main/hub/edit.ts b/src/commands/slash/Main/hub/edit.ts index e14d146d..8e4fac7d 100644 --- a/src/commands/slash/Main/hub/edit.ts +++ b/src/commands/slash/Main/hub/edit.ts @@ -6,7 +6,7 @@ import { CustomID } from '#utils/CustomID.js'; import db from '#utils/Db.js'; import { InfoEmbed } from '#utils/EmbedUtils.js'; import { hubEditSelects, hubEmbed } from '#utils/hub/edit.js'; -import { sendToHub } from '#utils/hub/utils.js'; +import { isHubManager, sendToHub } from '#utils/hub/utils.js'; import { type supportedLocaleCodes, t } from '#utils/Locale.js'; import type { Hub } from '@prisma/client'; import { @@ -19,8 +19,11 @@ import { TextInputStyle, } from 'discord.js'; import HubCommand from './index.js'; +import { HubService } from '#main/services/HubService.js'; export default class HubEdit extends HubCommand { + private readonly hubService = new HubService(db); + async execute(interaction: ChatInputCommandInteraction) { const { hubInDb, locale } = await this.getInitialData(interaction); if (!hubInDb) return; @@ -317,14 +320,9 @@ export default class HubEdit extends HubCommand { return {}; } - const hubInDb = await db.hub.findFirst({ - where: { id: customId.args[1] }, - include: { connections: true }, - }); - + const hubInDb = await this.hubService.fetchHub(customId.args[1], { connections: true }); if (!hubInDb) { const embed = new InfoEmbed().setDescription(t('hub.notFound', locale, { emoji: emojis.no })); - await interaction.reply({ embeds: [embed], ephemeral: true }); return {}; } @@ -338,18 +336,8 @@ export default class HubEdit extends HubCommand { const { userManager } = interaction.client; const locale = await userManager.getUserLocale(interaction.user.id); - const hubInDb = await db.hub.findFirst({ - where: { - id: hubId, - OR: [ - { ownerId: interaction.user.id }, - { moderators: { some: { userId: interaction.user.id, position: 'manager' } } }, - ], - }, - include: { connections: true }, - }); - - if (!hubInDb) { + const hubInDb = await this.hubService.fetchHub(hubId, { connections: true }); + if (!hubInDb || !isHubManager(interaction.user.id, hubInDb)) { await interaction.reply({ content: t('hub.notFound_mod', locale, { emoji: emojis.no }), ephemeral: true, diff --git a/src/services/HubService.ts b/src/services/HubService.ts index 5167688f..8767d56f 100644 --- a/src/services/HubService.ts +++ b/src/services/HubService.ts @@ -1,7 +1,7 @@ import { HubSettingsBits } from '#main/modules/BitFields.js'; import { deleteConnections } from '#main/utils/ConnectedListUtils.js'; import Constants from '#main/utils/Constants.js'; -import { PrismaClient } from '@prisma/client'; +import { Prisma, PrismaClient } from '@prisma/client'; export interface HubCreationData { name: string; @@ -17,8 +17,8 @@ export class HubService { this.db = db; } - async fetchHub(id: string) { - return await this.db.hub.findFirst({ where: { id } }); + async fetchHub(id: string, include: Prisma.HubInclude = {}) { + return await this.db.hub.findFirst({ where: { id }, include }); } async createHub(data: HubCreationData): Promise { @@ -53,8 +53,8 @@ export class HubService { return await this.db.hub.findMany({ where: { ownerId: userId } }); } - async getHubByName(name: string) { - return await this.db.hub.findFirst({ where: { name } }); + async getHubByName(name: string, ownerId?: string, include: Prisma.HubInclude = {}) { + return await this.db.hub.findFirst({ where: { name, ownerId }, include }); } async getExistingHubs(ownerId: string, hubName: string) { From 00309201bf257d35f3f7d06e0f45991676096e2e Mon Sep 17 00:00:00 2001 From: dev-737 <73829355+dev-737@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:41:22 +0530 Subject: [PATCH 4/4] fix: make mentions work in hub logs --- src/utils/hub/logger/Default.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utils/hub/logger/Default.ts b/src/utils/hub/logger/Default.ts index 458b93d0..78899995 100644 --- a/src/utils/hub/logger/Default.ts +++ b/src/utils/hub/logger/Default.ts @@ -29,7 +29,12 @@ export const sendLog = async ( if (channel?.isSendable()) { await channel - .send({ content: ctx.content, embeds: [ctx.embed], components: ctx.components }) + .send({ + content: ctx.content, + embeds: [ctx.embed], + components: ctx.components, + allowedMentions: { parse: ['roles'] }, + }) .catch(() => null); } },