Skip to content

Commit

Permalink
fix: custom ID overflow with Create from message (closes #494)
Browse files Browse the repository at this point in the history
  • Loading branch information
eartharoid committed Nov 8, 2024
1 parent f9a7f0c commit b0d77c1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/commands/message/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ module.exports = class CreateMessageCommand extends MessageCommand {
* @param {import("discord.js").MessageContextMenuCommandInteraction} interaction
*/
async run(interaction) {
await useGuild(this.client, interaction, { referencesMessage: interaction.targetMessage.channelId + '/' + interaction.targetId });
await useGuild(this.client, interaction, { referencesMessageId: interaction.targetId });
}
};
};
17 changes: 8 additions & 9 deletions src/lib/tickets/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ module.exports = class TicketManager {
* @param {string?} [data.topic]
*/
async create({
categoryId, interaction, topic, referencesMessage, referencesTicketId,
categoryId, interaction, topic, referencesMessageId, referencesTicketId,
}) {
categoryId = Number(categoryId);
const category = await this.getCategory(categoryId);
Expand Down Expand Up @@ -276,7 +276,7 @@ module.exports = class TicketManager {
.setCustomId(JSON.stringify({
action: 'questions',
categoryId,
referencesMessage,
referencesMessageId,
referencesTicketId,
}))
.setTitle(category.name)
Expand Down Expand Up @@ -324,7 +324,7 @@ module.exports = class TicketManager {
.setCustomId(JSON.stringify({
action: 'topic',
categoryId,
referencesMessage,
referencesMessageId,
referencesTicketId,
}))
.setTitle(category.name)
Expand All @@ -346,7 +346,7 @@ module.exports = class TicketManager {
await this.postQuestions({
categoryId,
interaction,
referencesMessage,
referencesMessageId,
referencesTicketId,
topic,
});
Expand All @@ -360,7 +360,7 @@ module.exports = class TicketManager {
* @param {string?} [data.topic]
*/
async postQuestions({
action, categoryId, interaction, topic, referencesMessage, referencesTicketId,
action, categoryId, interaction, topic, referencesMessageId, referencesTicketId,
}) {
const [, category] = await Promise.all([
interaction.deferReply({ ephemeral: true }),
Expand Down Expand Up @@ -540,14 +540,13 @@ module.exports = class TicketManager {

/** @type {import("discord.js").Message|undefined} */
let message;
if (referencesMessage) {
referencesMessage = referencesMessage.split('/');
if (referencesMessageId) {
/** @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) {
// not worth the effort of making system messages work atm
if (message.system) {
referencesMessage = null;
referencesMessageId = null;
message = null;
} else {
if (!message.member) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/tickets/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
* @param {import("discord.js").ButtonInteraction|import("discord.js").SelectMenuInteraction} interaction
*/
async useGuild(client, interaction, {
referencesMessage,
referencesMessageId,
referencesTicketId,
topic,
}) {
Expand Down Expand Up @@ -41,7 +41,7 @@ module.exports = {
await client.tickets.create({
categoryId: settings.categories[0].id,
interaction,
referencesMessage,
referencesMessageId,
referencesTicketId,
topic,
});
Expand All @@ -53,7 +53,7 @@ module.exports = {
new StringSelectMenuBuilder()
.setCustomId(JSON.stringify({
action: 'create',
referencesMessage,
referencesMessageId,
referencesTicketId,
topic,
}))
Expand Down

0 comments on commit b0d77c1

Please sign in to comment.