You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.9 KiB
67 lines
2.9 KiB
import {CommandContext, CommandOptionType, SlashCommand, SlashCreator} from "slash-create";
|
|
import {ChannelManager} from "../../queries/ChannelManager.js";
|
|
import {Snowflake} from "discord-api-types";
|
|
import {checkGameCommandAndRun} from "../permissions/ChannelPermissions.js";
|
|
import {UserManager} from "../../queries/UserManager.js";
|
|
|
|
export class JoinCommand extends SlashCommand {
|
|
readonly channelManager: ChannelManager
|
|
readonly userManager: UserManager
|
|
|
|
constructor(creator: SlashCreator, {channelManager, userManager, gameGuildIds, genders}: {
|
|
channelManager: ChannelManager,
|
|
userManager: UserManager,
|
|
gameGuildIds: Snowflake[],
|
|
genders: { id: string, name: string }[],
|
|
}) {
|
|
super(creator, {
|
|
name: "join",
|
|
guildIDs: gameGuildIds,
|
|
description: "Allows a new player to join the game.",
|
|
options: [
|
|
{
|
|
name: "name",
|
|
description: "Your alias for the purposes of this game. Purely cosmetic. You can change it at any time.",
|
|
required: true,
|
|
type: CommandOptionType.STRING,
|
|
},
|
|
{
|
|
name: "gender",
|
|
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) => ({
|
|
name: item.name,
|
|
value: item.id,
|
|
})),
|
|
}
|
|
]
|
|
});
|
|
|
|
this.channelManager = channelManager
|
|
this.userManager = userManager
|
|
}
|
|
|
|
async run(ctx: CommandContext): Promise<any> {
|
|
return checkGameCommandAndRun(ctx, this.channelManager, async () => {
|
|
const result = await this.userManager.registerOrReregisterUserFromDiscord({
|
|
discordId: ctx.user.id,
|
|
username: ctx.user.username,
|
|
discriminator: ctx.user.discriminator,
|
|
name: ctx.options.name ?? "Anonymous",
|
|
genderId: ctx.options.gender ?? "x",
|
|
})
|
|
if (result.created) {
|
|
return ctx.send({
|
|
content: `You got it! Welcome aboard, ${result.user.name}! I have you down in my records as ${result.user.gender.name}. If you ever want to change your name or gender, just /join again!`,
|
|
ephemeral: true,
|
|
})
|
|
} else {
|
|
return ctx.send({
|
|
content: `Duly noted! I've updated your deets to have you down as ${result.user.name}, who is ${result.user.gender.name}. If you ever want to change your name or gender, just /join again!`,
|
|
ephemeral: true,
|
|
})
|
|
}
|
|
})
|
|
}
|
|
} |