Skip to content

Commit

Permalink
Merge pull request #359 from Sayrix/fix
Browse files Browse the repository at this point in the history
Fixed discord.js latest breaking change
  • Loading branch information
zhiyan114 authored May 11, 2024
2 parents b52dc72 + 75fae62 commit dd3bb86
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 83 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"@types/node": "^20.8.6",
"@types/pg": "^8.10.7",
"@types/websocket": "^1.0.8",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"eslint": "^8.51.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.0.0",
Expand Down
162 changes: 81 additions & 81 deletions src/commands/add.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
import {BaseCommand, ExtendedClient} from "../structure";
import {CommandInteraction, SlashCommandBuilder, TextChannel} from "discord.js";
import {log} from "../utils/logs";

/*
Copyright 2023 Sayrix (github.com/Sayrix)
Licensed under the Creative Commons Attribution 4.0 International
please check https://creativecommons.org/licenses/by/4.0 for more informations.
*/

export default class AddCommand extends BaseCommand {
public static data: SlashCommandBuilder = <SlashCommandBuilder>new SlashCommandBuilder()
.setName("add")
.setDescription("Add someone to the ticket")
.addUserOption((input) => input.setName("user").setDescription("The user to add").setRequired(true));
constructor(client: ExtendedClient) {
super(client);
}

async execute(interaction: CommandInteraction) {

const added = interaction.options.getUser("user", true);
const ticket = await this.client.prisma.tickets.findUnique({
select: {
id: true,
invited: true,
},
where: {
channelid: interaction.channel?.id
}
});

if (!ticket) return interaction.reply({ content: "Ticket not found", ephemeral: true }).catch((e) => console.log(e));

const invited = JSON.parse(ticket.invited) as string[];
if (invited.includes(added.id)) return interaction.reply({ content: "User already added", ephemeral: true }).catch((e) => console.log(e));

if (invited.length >= 25)
return interaction.reply({ content: "You can't add more than 25 users", ephemeral: true }).catch((e) => console.log(e));

invited.push(added.id);
await this.client.prisma.tickets.update({
data: {
invited: JSON.stringify(invited)
},
where: {
channelid: interaction.channel?.id
}
});

await (interaction.channel as TextChannel | null)?.permissionOverwrites
.edit(added, {
SendMessages: true,
AddReactions: true,
ReadMessageHistory: true,
AttachFiles: true,
ViewChannel: true,
});

await interaction.reply({ content: `> Added <@${added.id}> to the ticket` }).catch((e) => console.log(e));

log(
{
LogType: "userAdded",
user: interaction.user,
ticketId: ticket.id.toString(),
ticketChannelId: interaction.channel?.id,
target: added,
},
this.client
);
}
}

/*
Copyright 2023 Sayrix (github.com/Sayrix)
Licensed under the Creative Commons Attribution 4.0 International
please check https://creativecommons.org/licenses/by/4.0 for more informations.
*/
import {BaseCommand, ExtendedClient} from "../structure";
import {CommandInteraction, SlashCommandBuilder, TextChannel, User} from "discord.js";
import {log} from "../utils/logs";

/*
Copyright 2023 Sayrix (github.com/Sayrix)
Licensed under the Creative Commons Attribution 4.0 International
please check https://creativecommons.org/licenses/by/4.0 for more informations.
*/

export default class AddCommand extends BaseCommand {
public static data: SlashCommandBuilder = <SlashCommandBuilder>new SlashCommandBuilder()
.setName("add")
.setDescription("Add someone to the ticket")
.addUserOption((input) => input.setName("user").setDescription("The user to add").setRequired(true));
constructor(client: ExtendedClient) {
super(client);
}

async execute(interaction: CommandInteraction) {

const added = interaction.options.get("user", true).user as User;
const ticket = await this.client.prisma.tickets.findUnique({
select: {
id: true,
invited: true,
},
where: {
channelid: interaction.channel?.id
}
});

if (!ticket) return interaction.reply({ content: "Ticket not found", ephemeral: true }).catch((e) => console.log(e));

const invited = JSON.parse(ticket.invited) as string[];
if (invited.includes(added.id)) return interaction.reply({ content: "User already added", ephemeral: true }).catch((e) => console.log(e));

if (invited.length >= 25)
return interaction.reply({ content: "You can't add more than 25 users", ephemeral: true }).catch((e) => console.log(e));

invited.push(added.id);
await this.client.prisma.tickets.update({
data: {
invited: JSON.stringify(invited)
},
where: {
channelid: interaction.channel?.id
}
});

await (interaction.channel as TextChannel | null)?.permissionOverwrites
.edit(added, {
SendMessages: true,
AddReactions: true,
ReadMessageHistory: true,
AttachFiles: true,
ViewChannel: true,
});

await interaction.reply({ content: `> Added <@${added.id}> to the ticket` }).catch((e) => console.log(e));

log(
{
LogType: "userAdded",
user: interaction.user,
ticketId: ticket.id.toString(),
ticketChannelId: interaction.channel?.id,
target: added,
},
this.client
);
}
}

/*
Copyright 2023 Sayrix (github.com/Sayrix)
Licensed under the Creative Commons Attribution 4.0 International
please check https://creativecommons.org/licenses/by/4.0 for more informations.
*/

0 comments on commit dd3bb86

Please sign in to comment.