Skip to content

Commit

Permalink
feat(supportposts): add resolved button
Browse files Browse the repository at this point in the history
  • Loading branch information
almostSouji committed Jul 11, 2023
1 parent 77da9f3 commit fb2d5ad
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
67 changes: 62 additions & 5 deletions src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { transformInteraction, kCommands, type CommandMap, logger } from "@yuudachi/framework";
import type { Event } from "@yuudachi/framework/types";
import { ApplicationCommandType, Events, Client } from "discord.js";
import { ApplicationCommandType, Events, Client, PermissionFlagsBits, ButtonStyle, ComponentType } from "discord.js";
import { injectable, inject } from "tsyringe";
import { CUSTOM_ID_SEPARATOR } from "../util/constants.js";

@injectable()
export default class implements Event {
Expand All @@ -13,6 +14,66 @@ export default class implements Event {

public execute() {
this.client.on(this.event, async (interaction) => {
if (!interaction.inCachedGuild()) {
return;
}

if (interaction.isButton()) {
try {
const [idPrefix] = interaction.customId.split(CUSTOM_ID_SEPARATOR);
switch (idPrefix) {
case "solved": {
const { channel, member, channelId } = interaction;
if (!channel?.isThread()) {
return;
}

if (
channel.ownerId !== interaction.user.id &&
!member.permissionsIn(channelId).has(PermissionFlagsBits.ManageMessages)
) {
await interaction.reply({
ephemeral: true,
content: "Only the original poster or support staff can close a thread!",
});
return;
}

await interaction.update({
components: [
{
type: ComponentType.ActionRow,
components: [
{
type: ComponentType.Button,
customId: "solved",
style: ButtonStyle.Secondary,
label: "Marked as resolved",
emoji: "🔒",
disabled: true,
},
],
},
],
});

await channel.edit({
locked: true,
archived: true,
});

break;
}

default:
break;
}
} catch (error_) {
const error = error_ as Error;
logger.error(error, error.message);
}
}

if (
!interaction.isCommand() &&
!interaction.isUserContextMenuCommand() &&
Expand All @@ -22,10 +83,6 @@ export default class implements Event {
return;
}

if (!interaction.inCachedGuild()) {
return;
}

const command = this.commands.get(interaction.commandName.toLowerCase());
if (command) {
try {
Expand Down
17 changes: 16 additions & 1 deletion src/events/threadCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setTimeout as wait } from "node:timers/promises";
import { logger } from "@yuudachi/framework";
import type { Event } from "@yuudachi/framework/types";
import type { ThreadChannel } from "discord.js";
import { Events, Client } from "discord.js";
import { Events, Client, ComponentType, ButtonStyle } from "discord.js";
import { injectable } from "tsyringe";
import { ASSISTCHANNELS } from "../util/constants.js";

Expand All @@ -30,7 +30,22 @@ export default class implements Event {
"- Show your code!",
"- Explain what exactly your issue is.",
"- Not a discord.js issue? Check out <#237743386864517122>.",
"- Issue solved? Press the button!",
].join("\n"),
components: [
{
type: ComponentType.ActionRow,
components: [
{
type: ComponentType.Button,
customId: "solved",
style: ButtonStyle.Secondary,
label: "Solved",
emoji: "✅",
},
],
},
],
});
} catch (error_) {
const error = error_ as Error;
Expand Down
2 changes: 2 additions & 0 deletions src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ export const TAB = "\u200B \u200B \u200B" as const;
export const EMOJI_NEWBIE = "<:newbie:962332319623049226>" as const;
export const ASSISTCHANNELS = ["986520997006032896", "998942774994927646"];

export const CUSTOM_ID_SEPARATOR = ":" as const;

export const URL_REGEX =
/(?<url>https?:\/\/(?:www\.|(?!www))[\dA-Za-z][\dA-Za-z-]+[\dA-Za-z]\.\S{2,}|www\.[\dA-Za-z][\dA-Za-z-]+[\dA-Za-z]\.\S{2,}|https?:\/\/(?:www\.|(?!www))[\dA-Za-z]+\.\S{2,}|www\.[\dA-Za-z]+\.\S{2,})/g;

0 comments on commit fb2d5ad

Please sign in to comment.