Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d-branch-1 #216

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
3 changes: 2 additions & 1 deletion src/commands/context-menu/deleteMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/commands/context-menu/editMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ActionRowBuilder,
ApplicationCommandType,
EmbedBuilder,
InteractionContextType,
Message,
MessageContextMenuCommandInteraction,
ModalBuilder,
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/commands/context-menu/messageInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
ComponentType,
EmbedBuilder,
Guild,
InteractionContextType,
MessageContextMenuCommandInteraction,
ModalBuilder,
ModalSubmitInteraction,
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/context-menu/modActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/context-menu/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ButtonStyle,
CacheType,
EmbedBuilder,
InteractionContextType,
MessageContextMenuCommandInteraction,
ModalBuilder,
ModalSubmitInteraction,
Expand All @@ -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<void> {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/slash/Main/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AutocompleteInteraction,
ChatInputCommandInteraction,
Collection,
InteractionContextType,
PermissionFlagsBits,
RESTPostAPIApplicationCommandsJSONBody,
} from 'discord.js';
Expand All @@ -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,
Expand Down
26 changes: 13 additions & 13 deletions src/commands/slash/Main/hub/blockwords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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.');
Expand All @@ -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.`);
Expand Down
26 changes: 7 additions & 19 deletions src/commands/slash/Main/hub/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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 {};
}
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/slash/Main/hub/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ChatInputCommandInteraction,
Collection,
Guild,
InteractionContextType,
RESTPostAPIApplicationCommandsJSONBody,
Snowflake,
} from 'discord.js';
Expand All @@ -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,
Expand Down Expand Up @@ -463,6 +464,7 @@ export default class HubCommand extends BaseCommand {
}

async autocomplete(interaction: AutocompleteInteraction): Promise<void> {
const modCmds = ['servers', 'invite', 'announce'];
const managerCmds = [
'edit',
'visibility',
Expand All @@ -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();
Expand Down
Loading