Allow null genders and update /join's description.

main
Mari 3 years ago
parent 33b084b575
commit 690b9db45b
  1. 8
      migrations/committed/000014-allow-null-gender.sql
  2. 17
      src/commands/game/JoinCommand.ts

@ -0,0 +1,8 @@
--! Previous: sha1:e7ff9a64813ea9e0a701219f6b2ba8ed88dcf240
--! Hash: sha1:2a39b3b006a8d5ec5d30ac1e5c2158d282b99acb
--! Message: allow null gender
ALTER TABLE Player
ALTER COLUMN GenderId DROP NOT NULL;
ALTER FUNCTION Command_Join(varchar, varchar, varchar, varchar, varchar, varchar, varchar) CALLED ON NULL INPUT;
ALTER FUNCTION UpdatePlayerRegistration(varchar, varchar, varchar, varchar, varchar) CALLED ON NULL INPUT;

@ -15,7 +15,7 @@ export class JoinCommand extends SlashCommand {
super(creator, {
name: "join",
guildIDs: gameGuildIds,
description: "Allows a new player to join the game.",
description: "Allows a new player to join the game or an existing player to update their registration.",
options: [
{
name: "name",
@ -28,10 +28,13 @@ export class JoinCommand extends SlashCommand {
description: "Your gender for the purposes of this game. Purely cosmetic. You can change it at any time.",
required: true,
type: CommandOptionType.STRING,
choices: genders.map((item) => ({
choices: [...genders.map((item) => ({
name: item.name,
value: item.id,
})),
})), {
name: "NULL",
value: "NULL",
}],
}
]
});
@ -41,10 +44,10 @@ export class JoinCommand extends SlashCommand {
async run(ctx: CommandContext): Promise<void> {
const name = ctx.options.name ?? "Anonymous"
const gender = ctx.options.gender ?? "nb"
const gender = ctx.options.gender === "NULL" ? null : (ctx.options.gender ?? "nb")
try {
const result =
singleRowQueryResult(await this.pool.query<{ resultid: number, newplayername: string, newgendername: string, wascreated: boolean }>({
singleRowQueryResult(await this.pool.query<{ resultid: number, newplayername: string, newgendername: string | null, wascreated: boolean }>({
text: `SELECT resultId, newPlayerName, newGenderName, wasCreated
FROM Command_Join($1, $2, $3, $4, $5, $6, $7)`,
values: [
@ -60,12 +63,12 @@ export class JoinCommand extends SlashCommand {
console.log("Unexpectedly empty Command_Join result!")
} else if (result.wascreated) {
await ctx.send({
content: `You got it! Welcome aboard, ${result.newplayername}! I have you down in my records as ${result.newgendername}. If you ever want to change your name or gender, just /join again!`,
content: `You got it! Welcome aboard, ${result.newplayername}! I have you down in my records as ${result.newgendername ?? `\`NULL\``}. If you ever want to change your name or gender, just /join again!`,
ephemeral: true,
})
} else {
await ctx.send({
content: `Duly noted! I've updated your deets to have you down as ${result.newplayername}, who is ${result.newgendername}. If you ever want to change your name or gender, just /join again!`,
content: `Duly noted! I've updated your deets to have you down as ${result.newplayername}, who is ${result.newgendername ?? `\`NULL\``}. If you ever want to change your name or gender, just /join again!`,
ephemeral: true,
})
}

Loading…
Cancel
Save