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-2 #204

Merged
merged 7 commits into from
Nov 9, 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
1 change: 0 additions & 1 deletion dev/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.7'
services:
mongodb_container:
# This image automatically creates a replica set required for transactions
Expand Down
5 changes: 3 additions & 2 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rules:
And remember to follow [Discord's Terms of Service](https://discord.com/terms) and [Community Guidelines](https://discord.com/guidelines).
welcome: |
{emoji} Hey {user}, welcome to InterChat!
To use InterChat you need to accept the guidelines. Please read and accept them by clicking next.
To use InterChat you need to accept the guidelines. Please read and accept them by clicking continue.
accepted: |
{emoji} Welcome to InterChat! You have accepted the rules and are now ready to chat with members from other servers!
If you are not already in a hub, use `/hub browse` to join one and start chatting. We have a simple [wiki and guide]({guide}) for more tips and tricks. Good luck!
Expand Down Expand Up @@ -348,8 +348,9 @@ errors:
cooldown: '{emoji} You are on cooldown. Please wait until **{time}** before attempting again.'
serverNameInappropriate: '{emoji} Your server name contains inappropriate words. Please change it before joining the hub.'
banned: |
{emoji} You have been banned from using InterChat for reason **{reason}**
{emoji} You have been banned from using InterChat for violating our [guidelines](https://interchat.fun/guidelines).
If you think an appeal is applicable create a ticket in the [support server]( {support_invite} ).

misc:
webhookNoLongerExists: '{emoji} The webhook for this channel no longer exists. To continue using InterChat, please re-create the webhook by using `/connection unpause`.'
noReason: No reason provided.
Expand Down
54 changes: 8 additions & 46 deletions src/commands/context-menu/messageInfo.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import Constants, { emojis } from '#utils/Constants.js';
import BaseCommand from '#main/core/BaseCommand.js';
import { RegisterInteractionHandler } from '#main/decorators/RegisterInteractionHandler.js';
import { modPanelButton } from '#main/interactions/ShowModPanel.js';
import HubLogManager from '#main/managers/HubLogManager.js';
import {
findOriginalMessage,
getOriginalMessage,
OriginalMessage,
} from '#main/utils/network/messageUtils.js';
import { findOriginalMessage, getOriginalMessage } from '#main/utils/network/messageUtils.js';
import type { RemoveMethods } from '#types/CustomClientProps.d.ts';
import { greyOutButton, greyOutButtons } from '#utils/ComponentUtils.js';
import { getHubConnections } from '#utils/ConnectedListUtils.js';
import Constants, { emojis } from '#utils/Constants.js';
import { CustomID } from '#utils/CustomID.js';
import db from '#utils/Db.js';
import { InfoEmbed } from '#utils/EmbedUtils.js';
import { fetchHub, isStaffOrHubMod } from '#utils/hub/utils.js';
import { sendHubReport } from '#utils/hub/logger/Report.js';
import { fetchHub, isStaffOrHubMod } from '#utils/hub/utils.js';
import { supportedLocaleCodes, t } from '#utils/Locale.js';
import modActionsPanel from '#utils/moderation/modActions/modActionsPanel.js';
import type { connectedList, Hub } from '@prisma/client';
import {
ActionRow,
Expand Down Expand Up @@ -50,7 +46,6 @@ type MsgInfo = { messageId: string };
type UserInfoOpts = LocaleInfo & AuthorInfo;
type MsgInfoOpts = AuthorInfo & ServerInfo & LocaleInfo & HubInfo & MsgInfo;
type ReportOpts = LocaleInfo & HubInfo & MsgInfo;
type ModActionsOpts = { originalMsg: OriginalMessage };
type ServerInfoOpts = LocaleInfo & ServerInfo & { connection: connectedList | undefined };

export default class MessageInfo extends BaseCommand {
Expand Down Expand Up @@ -93,17 +88,12 @@ export default class MessageInfo extends BaseCommand {
const connection = (await getHubConnections(hub.id))?.find(
(c) => c.connected && c.serverId === originalMsg.guildId,
);
const components = this.buildButtons(locale, {
const components = this.buildButtons(target.id, locale, {
buildModActions: isStaffOrHubMod(interaction.user.id, hub),
inviteButtonUrl: connection?.invite,
});

const reply = await interaction.followUp({
embeds: [embed],
components,
ephemeral: true,
});

const reply = await interaction.followUp({ embeds: [embed], components, ephemeral: true });
const collector = reply.createMessageComponentCollector({
idle: 60_000,
componentType: ComponentType.Button,
Expand Down Expand Up @@ -148,10 +138,6 @@ export default class MessageInfo extends BaseCommand {
this.handleReportButton(i, { hub, locale, messageId: target.id });
break;

case 'modActions':
this.handleModActionsButton(i, { originalMsg });
break;

default:
break;
}
Expand Down Expand Up @@ -318,23 +304,6 @@ export default class MessageInfo extends BaseCommand {
await interaction.update({ embeds: [embed], components, files: [] });
}

private async handleModActionsButton(
interaction: ButtonInteraction,
{ originalMsg }: ModActionsOpts,
) {
const hub = await fetchHub(originalMsg.hubId);
if (!hub || !isStaffOrHubMod(interaction.user.id, hub)) {
await interaction.reply({
content: t('hub.notFound_mod', 'en', { emoji: emojis.no }),
ephemeral: true,
});
return;
}

const { buttons, embed } = await modActionsPanel.buildMessage(interaction, originalMsg);
await interaction.reply({ embeds: [embed], components: buttons, ephemeral: true });
}

private async handleReportButton(
interaction: ButtonInteraction,
{ hub, locale, messageId }: ReportOpts,
Expand Down Expand Up @@ -394,6 +363,7 @@ export default class MessageInfo extends BaseCommand {
}

private buildButtons(
targetMsgId: string,
locale: supportedLocaleCodes = 'en',
opts?: { buildModActions?: boolean; inviteButtonUrl?: string | null },
) {
Expand All @@ -404,15 +374,7 @@ export default class MessageInfo extends BaseCommand {
.setCustomId(new CustomID().setIdentifier('msgInfo', 'report').toString()),
];

if (opts?.buildModActions) {
extras.push(
new ButtonBuilder()
.setStyle(ButtonStyle.Secondary)
.setEmoji('🛠️')
.setLabel('Mod Actions')
.setCustomId(new CustomID().setIdentifier('msgInfo', 'modActions').toString()),
);
}
if (opts?.buildModActions) extras.push(modPanelButton(targetMsgId));
if (opts?.inviteButtonUrl) {
extras.push(
new ButtonBuilder()
Expand Down
84 changes: 2 additions & 82 deletions src/commands/context-menu/modActions.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
import { emojis } from '#utils/Constants.js';
import BaseCommand from '#main/core/BaseCommand.js';
import { RegisterInteractionHandler } from '#main/decorators/RegisterInteractionHandler.js';
import { buildModPanel } from '#main/interactions/ModPanel.js';
import {
findOriginalMessage,
getOriginalMessage,
OriginalMessage,
} from '#main/utils/network/messageUtils.js';
import { CustomID } from '#utils/CustomID.js';
import { fetchHub, isStaffOrHubMod } from '#utils/hub/utils.js';
import { t, type supportedLocaleCodes } from '#utils/Locale.js';
import {
BlacklistServerHandler,
BlacklistUserHandler,
} from '#utils/moderation/modActions/handlers/blacklistHandler.js';
import DeleteMessageHandler from '#utils/moderation/modActions/handlers/deleteMsgHandler.js';
import RemoveReactionsHandler from '#utils/moderation/modActions/handlers/RemoveReactionsHandler.js';
import UserBanHandler from '#utils/moderation/modActions/handlers/userBanHandler.js';
import ViewInfractionsHandler from '#utils/moderation/modActions/handlers/viewInfractions.js';
import modActionsPanel from '#utils/moderation/modActions/modActionsPanel.js';
import { ModAction } from '#utils/moderation/modActions/utils.js';
import {
ApplicationCommandType,
type ButtonInteraction,
type MessageContextMenuCommandInteraction,
type ModalSubmitInteraction,
type RepliableInteraction,
type RESTPostAPIApplicationCommandsJSONBody,
} from 'discord.js';
Expand All @@ -35,20 +21,6 @@ export default class BlacklistCtxMenu extends BaseCommand {
dm_permission: false,
};

private readonly modActionHandlers: Record<string, ModAction>;

constructor() {
super();
this.modActionHandlers = {
deleteMsg: new DeleteMessageHandler(),
banUser: new UserBanHandler(),
blacklistUser: new BlacklistUserHandler(),
blacklistServer: new BlacklistServerHandler(),
removeAllReactions: new RemoveReactionsHandler(),
viewInfractions: new ViewInfractionsHandler(),
};
}

async execute(interaction: MessageContextMenuCommandInteraction) {
await interaction.deferReply({ ephemeral: true });

Expand All @@ -67,47 +39,10 @@ export default class BlacklistCtxMenu extends BaseCommand {
return;
}

const { embed, buttons } = await modActionsPanel.buildMessage(interaction, originalMsg);

const { embed, buttons } = await buildModPanel(interaction, originalMsg);
await interaction.editReply({ embeds: [embed], components: buttons });
}

@RegisterInteractionHandler('modActions')
async handleButtons(interaction: ButtonInteraction): Promise<void> {
const customId = CustomID.parseCustomId(interaction.customId);
const [userId, originalMsgId] = customId.args;
const locale = await interaction.client.userManager.getUserLocale(interaction.user.id);

if (!(await this.validateUser(interaction, userId, locale))) return;

const handler = this.modActionHandlers[customId.suffix];
if (handler) {
await handler.handle(interaction, originalMsgId, locale);
}
}

@RegisterInteractionHandler('blacklist_modal')
async handleBlacklistModal(interaction: ModalSubmitInteraction): Promise<void> {
await interaction.deferUpdate();

const customId = CustomID.parseCustomId(interaction.customId);
const [originalMsgId] = customId.args;
const originalMsg = await getOriginalMessage(originalMsgId);
const locale = await interaction.client.userManager.getUserLocale(interaction.user.id);

if (
!BlacklistCtxMenu.dbMsgExists(originalMsg) ||
!(await this.validateMessage(interaction, originalMsg, locale))
) {
return;
}
const handlerId = customId.suffix === 'user' ? 'blacklistUser' : 'blacklistServer';
const handler = this.modActionHandlers[handlerId];
if (handler?.handleModal) {
await handler.handleModal(interaction, originalMsg, locale);
}
}

private static dbMsgExists(originalMsg: OriginalMessage | null): originalMsg is OriginalMessage {
return Boolean(originalMsg);
}
Expand All @@ -128,19 +63,4 @@ export default class BlacklistCtxMenu extends BaseCommand {

return true;
}

private async validateUser(
interaction: RepliableInteraction,
userId: string,
locale: supportedLocaleCodes,
) {
if (interaction.user.id !== userId) {
await this.replyEmbed(interaction, t('errors.notYourAction', locale, { emoji: emojis.no }), {
ephemeral: true,
});
return false;
}

return true;
}
}
14 changes: 5 additions & 9 deletions src/commands/prefix/modpanel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BasePrefixCommand, { CommandData } from '#main/core/BasePrefixCommand.js';
import { buildModPanel } from '#main/interactions/ModPanel.js';
import { fetchHub, isStaffOrHubMod } from '#main/utils/hub/utils.js';
import modActionsPanel from '#main/utils/moderation/modActions/modActionsPanel.js';
import {
findOriginalMessage,
getMessageIdFromStr,
Expand All @@ -13,13 +13,9 @@ export default class BlacklistPrefixCommand extends BasePrefixCommand {
name: 'modpanel',
description: 'Blacklist a user or server from using the bot',
category: 'Moderation',
usage: 'blacklist ` user ID or server ID `',
examples: [
'blacklist 123456789012345678',
'blacklist 123456789012345678',
'> Reply to a message with `blacklist` to blacklist the user who sent the message',
],
aliases: ['bl', 'modactions', 'modpanel', 'mod', 'ban'],
usage: 'modpanel user ID or server ID `',
examples: ['mp 123456789012345678', 'mod 123456789012345678'],
aliases: ['bl', 'mp', 'moderate', 'modactions', 'modpanel', 'mod'],
dbPermission: false,
requiredArgs: 1,
};
Expand All @@ -39,7 +35,7 @@ export default class BlacklistPrefixCommand extends BasePrefixCommand {
return;
}

const modPanel = await modActionsPanel.buildMessage(message, originalMessage);
const modPanel = await buildModPanel(message, originalMessage);
await message.reply({ embeds: [modPanel.embed], components: modPanel.buttons });
}
private async getOriginalMessage(messageId: string) {
Expand Down
9 changes: 6 additions & 3 deletions src/commands/slash/Main/hub/announce.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { emojis } from '#utils/Constants.js';
import db from '#main/utils/Db.js';
import { InfoEmbed } from '#main/utils/EmbedUtils.js';
import { isHubManager, sendToHub } from '#main/utils/hub/utils.js';
import { fetchHub, isHubManager, sendToHub } from '#main/utils/hub/utils.js';
import {
ActionRowBuilder,
ChatInputCommandInteraction,
EmbedBuilder,
ModalBuilder,
ModalSubmitInteraction,
TextInputBuilder,
Expand Down Expand Up @@ -51,12 +51,15 @@ export default class AnnounceCommand extends HubCommand {
await interaction.reply(`${emojis.loading} Sending announcement to all connected servers...`);
const [hubId] = CustomID.parseCustomId(interaction.customId).args;
const announcement = interaction.fields.getTextInputValue('announcement');
const hub = await fetchHub(hubId);

await sendToHub(hubId, {
avatarURL: hub?.iconUrl,
embeds: [
new InfoEmbed()
new EmbedBuilder()
.setTitle('📢 Official Hub Announcement')
.setDescription(announcement)
.setColor('#3b82f6')
.setTimestamp(),
],
});
Expand Down
Loading
Loading