fix: custom ID overflow with Create from message (closes #494)

This commit is contained in:
Isaac 2024-11-08 23:17:29 +00:00
parent f9a7f0cbd9
commit b0d77c1af6
No known key found for this signature in database
GPG Key ID: 17700D08381EA590
3 changed files with 13 additions and 14 deletions

View File

@ -18,6 +18,6 @@ module.exports = class CreateMessageCommand extends MessageCommand {
* @param {import("discord.js").MessageContextMenuCommandInteraction} interaction * @param {import("discord.js").MessageContextMenuCommandInteraction} interaction
*/ */
async run(interaction) { async run(interaction) {
await useGuild(this.client, interaction, { referencesMessage: interaction.targetMessage.channelId + '/' + interaction.targetId }); await useGuild(this.client, interaction, { referencesMessageId: interaction.targetId });
} }
}; };

View File

@ -155,7 +155,7 @@ module.exports = class TicketManager {
* @param {string?} [data.topic] * @param {string?} [data.topic]
*/ */
async create({ async create({
categoryId, interaction, topic, referencesMessage, referencesTicketId, categoryId, interaction, topic, referencesMessageId, referencesTicketId,
}) { }) {
categoryId = Number(categoryId); categoryId = Number(categoryId);
const category = await this.getCategory(categoryId); const category = await this.getCategory(categoryId);
@ -276,7 +276,7 @@ module.exports = class TicketManager {
.setCustomId(JSON.stringify({ .setCustomId(JSON.stringify({
action: 'questions', action: 'questions',
categoryId, categoryId,
referencesMessage, referencesMessageId,
referencesTicketId, referencesTicketId,
})) }))
.setTitle(category.name) .setTitle(category.name)
@ -324,7 +324,7 @@ module.exports = class TicketManager {
.setCustomId(JSON.stringify({ .setCustomId(JSON.stringify({
action: 'topic', action: 'topic',
categoryId, categoryId,
referencesMessage, referencesMessageId,
referencesTicketId, referencesTicketId,
})) }))
.setTitle(category.name) .setTitle(category.name)
@ -346,7 +346,7 @@ module.exports = class TicketManager {
await this.postQuestions({ await this.postQuestions({
categoryId, categoryId,
interaction, interaction,
referencesMessage, referencesMessageId,
referencesTicketId, referencesTicketId,
topic, topic,
}); });
@ -360,7 +360,7 @@ module.exports = class TicketManager {
* @param {string?} [data.topic] * @param {string?} [data.topic]
*/ */
async postQuestions({ async postQuestions({
action, categoryId, interaction, topic, referencesMessage, referencesTicketId, action, categoryId, interaction, topic, referencesMessageId, referencesTicketId,
}) { }) {
const [, category] = await Promise.all([ const [, category] = await Promise.all([
interaction.deferReply({ ephemeral: true }), interaction.deferReply({ ephemeral: true }),
@ -540,14 +540,13 @@ module.exports = class TicketManager {
/** @type {import("discord.js").Message|undefined} */ /** @type {import("discord.js").Message|undefined} */
let message; let message;
if (referencesMessage) { if (referencesMessageId) {
referencesMessage = referencesMessage.split('/');
/** @type {import("discord.js").Message} */ /** @type {import("discord.js").Message} */
message = await (await this.client.channels.fetch(referencesMessage[0]))?.messages.fetch(referencesMessage[1]); message = await interaction.channel.messages.fetch(referencesMessageId);
if (message) { if (message) {
// not worth the effort of making system messages work atm // not worth the effort of making system messages work atm
if (message.system) { if (message.system) {
referencesMessage = null; referencesMessageId = null;
message = null; message = null;
} else { } else {
if (!message.member) { if (!message.member) {

View File

@ -12,7 +12,7 @@ module.exports = {
* @param {import("discord.js").ButtonInteraction|import("discord.js").SelectMenuInteraction} interaction * @param {import("discord.js").ButtonInteraction|import("discord.js").SelectMenuInteraction} interaction
*/ */
async useGuild(client, interaction, { async useGuild(client, interaction, {
referencesMessage, referencesMessageId,
referencesTicketId, referencesTicketId,
topic, topic,
}) { }) {
@ -41,7 +41,7 @@ module.exports = {
await client.tickets.create({ await client.tickets.create({
categoryId: settings.categories[0].id, categoryId: settings.categories[0].id,
interaction, interaction,
referencesMessage, referencesMessageId,
referencesTicketId, referencesTicketId,
topic, topic,
}); });
@ -53,7 +53,7 @@ module.exports = {
new StringSelectMenuBuilder() new StringSelectMenuBuilder()
.setCustomId(JSON.stringify({ .setCustomId(JSON.stringify({
action: 'create', action: 'create',
referencesMessage, referencesMessageId,
referencesTicketId, referencesTicketId,
topic, topic,
})) }))