Skip to content

Commit

Permalink
Bump discord.js from 14.13.0 to 14.14.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlul committed Jan 8, 2024
1 parent c59f93d commit 4e58bbc
Show file tree
Hide file tree
Showing 5 changed files with 573 additions and 477 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"async-mutex": "^0.4.0",
"coveralls": "link:./node_modules/.NULL",
"debug": "^4.3.4",
"discord.js": "^14.13.0",
"discord.js": "^14.14.1",
"dotenv": "^16.3.1",
"jimp": "link:./node_modules/.NULL",
"make-fetch-happen": "^13.0.0",
Expand All @@ -49,17 +49,17 @@
"@alphakretin/mocha-ecosystem": "^1.1.0",
"@types/debug": "^4.1.12",
"@types/make-fetch-happen": "^10.0.4",
"@types/node-fetch": "^2.6.7",
"@types/node-fetch": "^2.6.10",
"testcontainers": "^9.12.0"
},
"resolutions": {
"@types/node": "^20.8.9",
"better-sqlite3": "^9.0.0",
"@types/node": "^20.10.7",
"better-sqlite3": "^9.2.2",
"coveralls": "link:./node_modules/.NULL",
"jimp": "link:./node_modules/.NULL",
"string-width": "^4.2.3",
"strip-ansi": "^6.0.1",
"undici": "^5.27.0",
"undici": "^5.28.2",
"wrap-ansi": "^7.0.0"
},
"eslintConfig": {
Expand Down
16 changes: 14 additions & 2 deletions src/events/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import { InfoCommand } from "../slash/info";
import { InviteCommand } from "../slash/invite";
import { KickAllCommand } from "../slash/kickrole";
import { ListCommand } from "../slash/list";
import { OpenCommand, RegisterButtonHandler, RegisterModalHandler } from "../slash/open";
import {
OpenCommand,
RegisterButtonHandler,
RegisterModalHandler,
RenameButtonHandler,
RenameModalHandler
} from "../slash/open";
import { QueueCommand } from "../slash/queue";
import { ReportWinCommand } from "../slash/report-win";
import { StartCommand } from "../slash/start";
Expand Down Expand Up @@ -57,11 +63,17 @@ export function makeHandler({ organiserRole, timeWizard }: CommandSupport) {
];
const buttonArray = [
new RegisterButtonHandler(),
new RenameButtonHandler(),
new AcceptButtonHandler(),
new QuickAcceptButtonHandler(),
new RejectButtonHandler()
];
const messageModalArray = [new RegisterModalHandler(), new AcceptLabelModal(), new RejectReasonModal()];
const messageModalArray = [
new RegisterModalHandler(),
new RenameModalHandler(),
new AcceptLabelModal(),
new RejectReasonModal()
];
const contextArray = [new ForceDropContextCommand()];

const commands = new Map<string, SlashCommand>();
Expand Down
12 changes: 6 additions & 6 deletions src/slash/forcedrop.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ApplicationCommandType, RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10";
import {
AutocompleteInteraction,
chatInputApplicationCommandMention,
ChatInputCommandInteraction,
ContextMenuCommandBuilder,
SlashCommandBuilder,
UserContextMenuCommandInteraction
UserContextMenuCommandInteraction,
chatInputApplicationCommandMention
} from "discord.js";
import { ContextCommand } from "../ContextCommand";
import { AutocompletableCommand } from "../SlashCommand";
import { TournamentStatus } from "../database/interface";
import { ManualParticipant, ManualTournament } from "../database/orm";
import { AutocompletableCommand } from "../SlashCommand";
import { getLogger, Logger } from "../util/logger";
import { Logger, getLogger } from "../util/logger";
import { authenticateHost, autocompleteTournament, dropPlayer, tournamentOption } from "./database";

export class ForceDropSlashCommand extends AutocompletableCommand {
Expand Down Expand Up @@ -94,7 +94,7 @@ export class ForceDropContextCommand extends ContextCommand {

const players = await ManualParticipant.find({
where: {
discordId: member.id,
discordId: interaction.targetUser.id,
tournament: [{ status: TournamentStatus.PREPARING }, { status: TournamentStatus.IPR }]
},
relations: ["tournament"]
Expand Down Expand Up @@ -127,6 +127,6 @@ export class ForceDropContextCommand extends ContextCommand {
return;
}

await dropPlayer(tournament, player, member, interaction);
await dropPlayer(tournament, player, member ?? interaction.targetUser, interaction);
}
}
143 changes: 110 additions & 33 deletions src/slash/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ export class OpenCommand extends AutocompletableCommand {
.setStyle(ButtonStyle.Success)
.setEmoji("🎫");
row.addComponents(button);
if (tournament.requireFriendCode) {
row.addComponents(
new ButtonBuilder()
.setCustomId("renameButton")
.setLabel("Update friend code or in-game name")
.setStyle(ButtonStyle.Secondary)
.setEmoji("⌨")
);
}

const message = await send(interaction.client, tournament.publicChannel, {
content: `__Registration for **${tournament.name}** is now open!__\n${
Expand Down Expand Up @@ -139,7 +148,7 @@ async function registerParticipant(
`Please upload screenshots of your decklist to register, all attached to one message. \n**Important**: Please do not delete your message! You will be dropped for cheating, as this can make your decklist invisible to hosts.`
);
await interaction.reply({
content: "Please check your direct messages for next steps.",
content: `Please check your direct messages for next steps, ${interaction.user}.`,
ephemeral: true
});
if (friendCode) {
Expand Down Expand Up @@ -167,6 +176,34 @@ async function registerParticipant(
}
}

function buildRegisterModal(id: string, title: string, interaction: ButtonInteraction<"cached">): ModalBuilder {
const modal = new ModalBuilder()
.setCustomId(id)
// Max title length of 45: https://github.com/DawnbrandBots/emcee-tournament-bot/issues/521
.setTitle(title.slice(0, 45));
const friendCodeInput = new TextInputBuilder()
.setCustomId("friendCode")
.setLabel("Master Duel Friend Code")
.setStyle(TextInputStyle.Short)
.setRequired(true)
.setPlaceholder("000000000")
.setMinLength(9)
.setMaxLength(11);
const ignInput = new TextInputBuilder()
.setCustomId("ign")
.setLabel("In-game name, if different")
.setStyle(TextInputStyle.Short)
.setRequired(false)
.setPlaceholder(interaction.user.username.slice(0, 12))
.setMinLength(3)
.setMaxLength(12);
modal.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(friendCodeInput),
new ActionRowBuilder<TextInputBuilder>().addComponents(ignInput)
);
return modal;
}

export class RegisterButtonHandler implements ButtonClickHandler {
readonly buttonIds = ["registerButton"];

Expand All @@ -192,14 +229,6 @@ export class RegisterButtonHandler implements ButtonClickHandler {
});
return;
}
if (tournament.status !== TournamentStatus.PREPARING) {
// Shouldn't happen
await interaction.reply({
content: `Sorry ${interaction.user}, registration for the tournament has closed!`,
ephemeral: true
});
return;
}
if (!checkParticipantCap(tournament)) {
await interaction.reply({
content: `Sorry ${interaction.user}, the tournament is currently full!`,
Expand All @@ -222,30 +251,7 @@ export class RegisterButtonHandler implements ButtonClickHandler {
return;
}
if (tournament.requireFriendCode) {
// Max title length of 45: https://github.com/DawnbrandBots/emcee-tournament-bot/issues/521
const modal = new ModalBuilder()
.setCustomId("registerModal")
.setTitle(`Register for ${tournament.name.slice(0, 32)}`);
const friendCodeInput = new TextInputBuilder()
.setCustomId("friendCode")
.setLabel("Master Duel Friend Code")
.setStyle(TextInputStyle.Short)
.setRequired(true)
.setPlaceholder("000000000")
.setMinLength(9)
.setMaxLength(11);
const ignInput = new TextInputBuilder()
.setCustomId("ign")
.setLabel("In-game name, if different")
.setStyle(TextInputStyle.Short)
.setRequired(false)
.setPlaceholder(interaction.user.username.slice(0, 12))
.setMinLength(3)
.setMaxLength(12);
modal.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(friendCodeInput),
new ActionRowBuilder<TextInputBuilder>().addComponents(ignInput)
);
const modal = buildRegisterModal("registerModal", `Register for ${tournament.name}`, interaction);
await interaction.showModal(modal);
} else {
await registerParticipant(interaction, tournament);
Expand Down Expand Up @@ -280,3 +286,74 @@ export class RegisterModalHandler implements MessageModalSubmitHandler {
await registerParticipant(interaction, tournament, friendCode, ign);
}
}

export class RenameButtonHandler implements ButtonClickHandler {
readonly buttonIds = ["renameButton"];

async click(interaction: ButtonInteraction<"cached">): Promise<void> {
const participant = await ManualParticipant.findOne({
where: {
discordId: interaction.user.id,
tournament: [
{
owningDiscordServer: interaction.guildId,
registerMessage: interaction.message.id,
status: TournamentStatus.PREPARING
}
]
},
relations: ["tournament"]
});
if (!participant) {
await interaction.reply({
content: "You are not registered for this tournament! Click the other button if you want to register.",
ephemeral: true
});
} else {
const modal = buildRegisterModal("renameModal", `Renaming in ${participant.tournament.name}`, interaction);
await interaction.showModal(modal);
}
}
}

export class RenameModalHandler implements MessageModalSubmitHandler {
readonly modalIds = ["renameModal"];

async submit(interaction: ModalMessageModalSubmitInteraction<"cached">): Promise<void> {
const participant = await ManualParticipant.findOneOrFail({
where: {
discordId: interaction.user.id,
tournament: [
{
owningDiscordServer: interaction.guildId,
registerMessage: interaction.message.id,
status: TournamentStatus.PREPARING
}
]
},
relations: ["tournament"]
});
// Same as RegisterModalHandler
const ign = interaction.fields.getTextInputValue("ign");
const friendCodeString = interaction.fields.getTextInputValue("friendCode");
const friendCode = parseFriendCode(friendCodeString);
if (!friendCode && participant.tournament.requireFriendCode) {
await interaction.reply({
content: `This tournament requires a Master Duel friend code, and you did not enter a valid one! Please try again, ${interaction.user}!`,
ephemeral: true
});
return;
}
const oldIgn = participant.ign;

Check failure on line 347 in src/slash/open.ts

View workflow job for this annotation

GitHub Actions / test

'oldIgn' is assigned a value but never used
const oldFriendCode = participant.friendCode;

Check failure on line 348 in src/slash/open.ts

View workflow job for this annotation

GitHub Actions / test

'oldFriendCode' is assigned a value but never used
participant.ign = ign;
participant.friendCode = friendCode;
await participant.save();
await interaction.reply({
content: `Done`,
ephemeral: true
});
// ephemeral reply results
// notify hosts in private channel with before/after
}
}
Loading

0 comments on commit 4e58bbc

Please sign in to comment.