Skip to content

Commit

Permalink
fix: fix mark resolved button error
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Nov 8, 2024
1 parent c20a85e commit 0c08167
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 37 deletions.
27 changes: 27 additions & 0 deletions src/commands/prefix/disconnect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import BasePrefixCommand, { CommandData } from '#main/core/BasePrefixCommand.js';
import { Message } from 'discord.js';

export default class BlacklistPrefixCommand extends BasePrefixCommand {
public readonly data: CommandData = {
name: 'disconnect',
description: 'Connect to a random chat group',
category: 'Moderation',
usage: 'connect',
examples: ['disconnect', 'dc', 'hangup'],
aliases: ['hangup', 'dc', 'disconn'],
dbPermission: false,
requiredArgs: 0,
};

protected async run(message: Message<true>) {
const { chatService } = message.client;
const alreadyConnected = await chatService.getChannelGroup(message.channelId);
if (!alreadyConnected) {
await message.reply('This channel is not connected to a chat group!');
return;
}

await chatService.disconnectChannel(message.channelId);
await message.reply('Disconnected from chat group!');
}
}
58 changes: 36 additions & 22 deletions src/interactions/MarkResolvedButton.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@
import { RegisterInteractionHandler } from '#main/decorators/RegisterInteractionHandler.js';
import { CustomID } from '#main/utils/CustomID.js';
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle } from 'discord.js';
import { handleError } from '#main/utils/Utils.js';
import {
ActionRowBuilder,
ButtonBuilder,
ButtonInteraction,
ButtonStyle,
MessageActionRowComponentBuilder,
} from 'discord.js';

export const markResolvedButton = () =>
new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId(new CustomID().setIdentifier('markResolved').toString())
.setStyle(ButtonStyle.Success)
.setLabel('Mark as Resolved'),
);
new ButtonBuilder()
.setCustomId(new CustomID().setIdentifier('markResolved').toString())
.setStyle(ButtonStyle.Success)
.setLabel('Mark Resolved');

export default class MarkResolvedButton {
@RegisterInteractionHandler('markResolved')
async handler(interaction: ButtonInteraction): Promise<void> {
await interaction.deferUpdate();
const { components } = interaction.message;
if (!components) return;
try {
await interaction.deferUpdate();
const components = interaction.message.components;
if (!components) return;

const rows = components.map((row) => new ActionRowBuilder(row));
const rows = components.map(
(row) => ActionRowBuilder.from(row),
) as ActionRowBuilder<MessageActionRowComponentBuilder>[];

rows.forEach((row) => {
row.components.forEach((component) => {
if (
component instanceof ButtonBuilder &&
component.data.style === ButtonStyle.Success &&
component.data.custom_id === interaction.customId
) {
component.setDisabled(true);
}
rows.forEach((row) => {
row.components.forEach((component) => {
if (
component instanceof ButtonBuilder &&
component.data.style === ButtonStyle.Success &&
component.data.custom_id === interaction.customId
) {
component.setLabel(`Resolved by @${interaction.user.username}`);
component.setDisabled(true);
}
});
});
});

await interaction.editReply({ components });
await interaction.editReply({ components: rows });
}
catch (e) {
e.message = `Failed to mark the message as resolved: ${e.message}`;
handleError(e, interaction);
}
}
}
20 changes: 9 additions & 11 deletions src/interactions/ShowModPanelButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ import { InfoEmbed } from '#main/utils/EmbedUtils.js';
import { fetchHub, isStaffOrHubMod } from '#main/utils/hub/utils.js';
import modActionsPanel from '#main/utils/moderation/modActions/modActionsPanel.js';
import { findOriginalMessage, getOriginalMessage } from '#main/utils/network/messageUtils.js';
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle } from 'discord.js';
import { ButtonBuilder, ButtonInteraction, ButtonStyle } from 'discord.js';

export const modPanelButton = (targetMsgId: string, label = 'Take Action') => new ActionRowBuilder<ButtonBuilder>()
.addComponents(
new ButtonBuilder()
.setCustomId(
new CustomID().setIdentifier('showModPanel').addArgs(targetMsgId).toString(),
)
.setStyle(ButtonStyle.Danger)
.setLabel(label)
.setEmoji(emojis.blobFastBan),
);
export const modPanelButton = (targetMsgId: string, label = 'Take Action') =>
new ButtonBuilder()
.setCustomId(
new CustomID().setIdentifier('showModPanel').addArgs(targetMsgId).toString(),
)
.setStyle(ButtonStyle.Danger)
.setLabel(label)
.setEmoji(emojis.blobFastBan);

export default class ModActionsButton {
@RegisterInteractionHandler('showModPanel')
Expand Down
3 changes: 2 additions & 1 deletion src/managers/VoteManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ export class VoteManager {
if (!userInGuild?.roles.includes(roleId)) return;

const method = type === 'add' ? 'put' : 'delete';
return await this.rest[method](
await this.rest[method](
Routes.guildMemberRole(Constants.SupportServerId, userId, roleId),
);
return;
}

async addVoterRole(userId: string) {
Expand Down
9 changes: 6 additions & 3 deletions src/utils/hub/logger/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import db from '#utils/Db.js';
import { resolveEval } from '#utils/Utils.js';
import { stripIndents } from 'common-tags';
import {
ActionRowBuilder,
ButtonBuilder,
EmbedBuilder,
messageLink,
roleMention,
Expand Down Expand Up @@ -126,11 +128,12 @@ export const sendHubReport = async (
});

const mentionRole = reportsRoleId ? roleMention(reportsRoleId) : undefined;
const button = modPanelButton(evidence.messageId).toJSON();
const resolveButton = markResolvedButton().toJSON(); // anyone can use this button, it's on mods to set proper permissions for reports channel
const button = modPanelButton(evidence.messageId);
const resolveButton = markResolvedButton(); // anyone can use this button, it's on mods to set proper permissions for reports channel
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(button, resolveButton);

await sendLog(client.cluster, reportsChannelId, embed, {
content: mentionRole,
components: [button, resolveButton],
components: [row.toJSON()],
});
};

0 comments on commit 0c08167

Please sign in to comment.