|
|
|
@ -6,62 +6,66 @@ import { |
|
|
|
|
AutocompleteInteraction, |
|
|
|
|
ChatInputCommandInteraction, |
|
|
|
|
Collection, |
|
|
|
|
} from "discord.js" |
|
|
|
|
import {CharacterCommand} from "./character/index" |
|
|
|
|
import {autocompleteNotImplementedError, CommandData} from "./types" |
|
|
|
|
import {BotCommand} from "./bot/index" |
|
|
|
|
import {UserTable} from "../database/users.js" |
|
|
|
|
} from "discord.js"; |
|
|
|
|
import { CharacterCommand } from "./character"; |
|
|
|
|
import { autocompleteNotImplementedError, CommandData } from "./types"; |
|
|
|
|
import { BotCommand } from "./bot"; |
|
|
|
|
import { UserTable } from "../database/users.js"; |
|
|
|
|
import { UsersManager } from "../managers/users"; |
|
|
|
|
|
|
|
|
|
export const invalidCommandError = "No command by that name exists." |
|
|
|
|
export const invalidCommandError = "No command by that name exists."; |
|
|
|
|
|
|
|
|
|
export class Commands { |
|
|
|
|
readonly all: CommandData[] |
|
|
|
|
readonly character: CharacterCommand |
|
|
|
|
readonly bot: BotCommand |
|
|
|
|
readonly definitions: ApplicationCommandDataResolvable[] |
|
|
|
|
private readonly _nameCache: Record<string, CommandData> |
|
|
|
|
readonly all: CommandData[]; |
|
|
|
|
readonly character: CharacterCommand; |
|
|
|
|
readonly bot: BotCommand; |
|
|
|
|
readonly definitions: ApplicationCommandDataResolvable[]; |
|
|
|
|
private readonly _nameCache: Record<string, CommandData>; |
|
|
|
|
|
|
|
|
|
constructor({users, cleanUp}: { users: UserTable, cleanUp: () => Promise<void> }) { |
|
|
|
|
this.character = new CharacterCommand({users}) |
|
|
|
|
this.bot = new BotCommand({users, cleanUp}) |
|
|
|
|
this.all = [ |
|
|
|
|
this.character, |
|
|
|
|
this.bot, |
|
|
|
|
] |
|
|
|
|
this.definitions = this.all.map((c) => c.definition) |
|
|
|
|
constructor({ |
|
|
|
|
users, |
|
|
|
|
cleanUp, |
|
|
|
|
}: { |
|
|
|
|
users: UsersManager; |
|
|
|
|
cleanUp: () => Promise<void>; |
|
|
|
|
}) { |
|
|
|
|
this.character = new CharacterCommand({ users }); |
|
|
|
|
this.bot = new BotCommand({ users, cleanUp }); |
|
|
|
|
this.all = [this.character, this.bot]; |
|
|
|
|
this.definitions = this.all.map((c) => c.definition); |
|
|
|
|
this._nameCache = Object.fromEntries( |
|
|
|
|
this.all.map((c) => [c.definition.name, c]), |
|
|
|
|
) |
|
|
|
|
this.all.map((c) => [c.definition.name, c]) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setCache(data: Collection<string, ApplicationCommand>) { |
|
|
|
|
for (const command of data.values()) { |
|
|
|
|
if (this._nameCache.hasOwnProperty(command.name)) { |
|
|
|
|
this._nameCache[command.name].setCached(command) |
|
|
|
|
this._nameCache[command.name].setCached(command); |
|
|
|
|
} else { |
|
|
|
|
console.log("No such command when caching commands: " + command.name) |
|
|
|
|
console.log("No such command when caching commands: " + command.name); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async execute(ev: ChatInputCommandInteraction) { |
|
|
|
|
const name = ev.commandName |
|
|
|
|
const name = ev.commandName; |
|
|
|
|
if (!this._nameCache.hasOwnProperty(name)) { |
|
|
|
|
throw invalidCommandError |
|
|
|
|
throw invalidCommandError; |
|
|
|
|
} |
|
|
|
|
await this._nameCache[name].execute(ev) |
|
|
|
|
await this._nameCache[name].execute(ev); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async autocomplete(ev: AutocompleteInteraction) { |
|
|
|
|
const name = ev.commandName |
|
|
|
|
const name = ev.commandName; |
|
|
|
|
if (this._nameCache.hasOwnProperty(name)) { |
|
|
|
|
const command = this._nameCache[name] |
|
|
|
|
const command = this._nameCache[name]; |
|
|
|
|
if (command.autocomplete) { |
|
|
|
|
await command.autocomplete(ev) |
|
|
|
|
return |
|
|
|
|
await command.autocomplete(ev); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
throw autocompleteNotImplementedError |
|
|
|
|
throw autocompleteNotImplementedError; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -74,12 +78,14 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "difficulty", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Alters or displays the reformation difficulty of your currently selected character.", |
|
|
|
|
description: |
|
|
|
|
"Alters or displays the reformation difficulty of your currently selected character.", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "preference", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Alters or displays the pred/prey preference of your currently selected character.", |
|
|
|
|
description: |
|
|
|
|
"Alters or displays the pred/prey preference of your currently selected character.", |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
@ -91,12 +97,14 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "join", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Leaves the current team, if any, and requests to join the same team (and battle) as another player.", |
|
|
|
|
description: |
|
|
|
|
"Leaves the current team, if any, and requests to join the same team (and battle) as another player.", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "leave", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Leaves the current team, if any, and strikes it out alone.", |
|
|
|
|
description: |
|
|
|
|
"Leaves the current team, if any, and strikes it out alone.", |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
@ -138,7 +146,8 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "target", |
|
|
|
|
type: ApplicationCommandOptionType.String, |
|
|
|
|
description: "The target to use the skill on, if there are multiple options. Omit to see a list.", |
|
|
|
|
description: |
|
|
|
|
"The target to use the skill on, if there are multiple options. Omit to see a list.", |
|
|
|
|
autocomplete: true, |
|
|
|
|
required: false, |
|
|
|
|
}, |
|
|
|
@ -159,7 +168,8 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "target", |
|
|
|
|
type: ApplicationCommandOptionType.String, |
|
|
|
|
description: "The target to use the item on, if there are multiple options. Omit to see a list.", |
|
|
|
|
description: |
|
|
|
|
"The target to use the item on, if there are multiple options. Omit to see a list.", |
|
|
|
|
autocomplete: true, |
|
|
|
|
required: false, |
|
|
|
|
}, |
|
|
|
@ -168,7 +178,8 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "vore", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Devours your opponent. Requires your opponent to be at low Confidence.", |
|
|
|
|
description: |
|
|
|
|
"Devours your opponent. Requires your opponent to be at low Confidence.", |
|
|
|
|
options: [ |
|
|
|
|
{ |
|
|
|
|
name: "style", |
|
|
|
@ -182,17 +193,20 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "rest", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Takes a breather, recovering your Confidence and Energy at a faster-than-normal rate for this turn.", |
|
|
|
|
description: |
|
|
|
|
"Takes a breather, recovering your Confidence and Energy at a faster-than-normal rate for this turn.", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "escape", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Tries to escape from a battle or stomach. Requires your opponent to be at low Confidence.", |
|
|
|
|
description: |
|
|
|
|
"Tries to escape from a battle or stomach. Requires your opponent to be at low Confidence.", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "surrender", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Lets your opponent do as they will with you by reducing your Confidence or Health to 0.", |
|
|
|
|
description: |
|
|
|
|
"Lets your opponent do as they will with you by reducing your Confidence or Health to 0.", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "prey", |
|
|
|
@ -207,7 +221,8 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "squish", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Squishes your prey, ending the combat. Can only be performed when the prey is at or below 0% Health.", |
|
|
|
|
description: |
|
|
|
|
"Squishes your prey, ending the combat. Can only be performed when the prey is at or below 0% Health.", |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
@ -221,7 +236,8 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "exit", |
|
|
|
|
type: ApplicationCommandOptionType.SubcommandGroup, |
|
|
|
|
description: "Exits battle(s) and reverts its/their effects on you. To flee in-character, use /battle escape.", |
|
|
|
|
description: |
|
|
|
|
"Exits battle(s) and reverts its/their effects on you. To flee in-character, use /battle escape.", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "block", |
|
|
|
@ -231,18 +247,21 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "add", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Prevents a user or character from challenging you or joining battles you're in.", |
|
|
|
|
description: |
|
|
|
|
"Prevents a user or character from challenging you or joining battles you're in.", |
|
|
|
|
options: [ |
|
|
|
|
{ |
|
|
|
|
name: "user", |
|
|
|
|
type: ApplicationCommandOptionType.User, |
|
|
|
|
description: "The user to block from challenging you or joining battles you're in.", |
|
|
|
|
description: |
|
|
|
|
"The user to block from challenging you or joining battles you're in.", |
|
|
|
|
required: false, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "character", |
|
|
|
|
type: ApplicationCommandOptionType.String, |
|
|
|
|
description: "The character to block from challenging you or joining battles you're in.", |
|
|
|
|
description: |
|
|
|
|
"The character to block from challenging you or joining battles you're in.", |
|
|
|
|
required: false, |
|
|
|
|
autocomplete: true, |
|
|
|
|
}, |
|
|
|
@ -251,18 +270,21 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "remove", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Allows a user or character to challenge you and join battles you're in once more.", |
|
|
|
|
description: |
|
|
|
|
"Allows a user or character to challenge you and join battles you're in once more.", |
|
|
|
|
options: [ |
|
|
|
|
{ |
|
|
|
|
name: "user", |
|
|
|
|
type: ApplicationCommandOptionType.User, |
|
|
|
|
description: "The user to allow to challenge you and join battles you're in once more.", |
|
|
|
|
description: |
|
|
|
|
"The user to allow to challenge you and join battles you're in once more.", |
|
|
|
|
required: false, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "character", |
|
|
|
|
type: ApplicationCommandOptionType.String, |
|
|
|
|
description: "The character to allow to challenge you and join battles you're in once more.", |
|
|
|
|
description: |
|
|
|
|
"The character to allow to challenge you and join battles you're in once more.", |
|
|
|
|
required: false, |
|
|
|
|
autocomplete: true, |
|
|
|
|
}, |
|
|
|
@ -278,23 +300,27 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "kick", |
|
|
|
|
type: ApplicationCommandOptionType.SubcommandGroup, |
|
|
|
|
description: "Manages the list of users kicked from the current battle.", |
|
|
|
|
description: |
|
|
|
|
"Manages the list of users kicked from the current battle.", |
|
|
|
|
options: [ |
|
|
|
|
{ |
|
|
|
|
name: "add", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Removes a user or character from the current battle and prevents them from rejoining.", |
|
|
|
|
description: |
|
|
|
|
"Removes a user or character from the current battle and prevents them from rejoining.", |
|
|
|
|
options: [ |
|
|
|
|
{ |
|
|
|
|
name: "user", |
|
|
|
|
type: ApplicationCommandOptionType.User, |
|
|
|
|
description: "The user to remove from the current battle and prevent from rejoining.", |
|
|
|
|
description: |
|
|
|
|
"The user to remove from the current battle and prevent from rejoining.", |
|
|
|
|
required: false, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "character", |
|
|
|
|
type: ApplicationCommandOptionType.String, |
|
|
|
|
description: "The character to remove from the current battle and prevent from rejoining.", |
|
|
|
|
description: |
|
|
|
|
"The character to remove from the current battle and prevent from rejoining.", |
|
|
|
|
required: false, |
|
|
|
|
autocomplete: true, |
|
|
|
|
}, |
|
|
|
@ -303,7 +329,8 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "remove", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Allows a user or character to rejoin the current battle.", |
|
|
|
|
description: |
|
|
|
|
"Allows a user or character to rejoin the current battle.", |
|
|
|
|
options: [ |
|
|
|
|
{ |
|
|
|
|
name: "user", |
|
|
|
@ -323,7 +350,8 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "list", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Displays the list of users forbidden from rejoining the current battle.", |
|
|
|
|
description: |
|
|
|
|
"Displays the list of users forbidden from rejoining the current battle.", |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
@ -335,12 +363,14 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "add", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Bans a user from participating in battles in the current server and kicks them from any they're in.", |
|
|
|
|
description: |
|
|
|
|
"Bans a user from participating in battles in the current server and kicks them from any they're in.", |
|
|
|
|
options: [ |
|
|
|
|
{ |
|
|
|
|
name: "user", |
|
|
|
|
type: ApplicationCommandOptionType.User, |
|
|
|
|
description: "The user to ban from participating in battles in the current server.", |
|
|
|
|
description: |
|
|
|
|
"The user to ban from participating in battles in the current server.", |
|
|
|
|
required: true, |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
@ -348,12 +378,14 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "remove", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "Allows a user to resume participating in battles in the current server.", |
|
|
|
|
description: |
|
|
|
|
"Allows a user to resume participating in battles in the current server.", |
|
|
|
|
options: [ |
|
|
|
|
{ |
|
|
|
|
name: "user", |
|
|
|
|
type: ApplicationCommandOptionType.User, |
|
|
|
|
description: "The user to allow to participate in battles in the current server once more.", |
|
|
|
|
description: |
|
|
|
|
"The user to allow to participate in battles in the current server once more.", |
|
|
|
|
required: true, |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
@ -368,13 +400,15 @@ const otherCommands: ApplicationCommandDataResolvable[] = [ |
|
|
|
|
{ |
|
|
|
|
name: "delete", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "PERMANENTLY deletes a character, exiting any battles they were part of. See also /character archive.", |
|
|
|
|
description: |
|
|
|
|
"PERMANENTLY deletes a character, exiting any battles they were part of. See also /character archive.", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
name: "wipe", |
|
|
|
|
type: ApplicationCommandOptionType.Subcommand, |
|
|
|
|
description: "PERMANENTLY deletes ALL data about you in the system, erasing you from the system's knowledge.", |
|
|
|
|
description: |
|
|
|
|
"PERMANENTLY deletes ALL data about you in the system, erasing you from the system's knowledge.", |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
] |
|
|
|
|
]; |
|
|
|
|