Skip to content

Commit

Permalink
Merge pull request #160 from utarwyn/issue-56-custom-command-option-name
Browse files Browse the repository at this point in the history
GH-56: Customize option name for slash command
  • Loading branch information
utarwyn authored Jan 24, 2022
2 parents c526a21 + d66464a commit c17d275
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"language": "en",
"command": "!ttt",
"slashCommand": "tictactoe",
"slashCommandOptionName": "opponent",
"allowedChannelIds": [],
"allowedRoleIds": [],
"requestExpireTime": 60,
Expand Down
6 changes: 5 additions & 1 deletion src/bot/TicTacToeBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export default class TicTacToeBot {
public attachToClient(client: Client): void {
// Handle slash command if enabled
if (this.configuration.slashCommand) {
const register = new AppCommandRegister(client, this.configuration.slashCommand);
const register = new AppCommandRegister(
client,
this.configuration.slashCommand,
this.configuration.slashCommandOptionName ?? 'opponent'
);
client.on('message', register.handleDeployMessage.bind(register));
client.ws.on('INTERACTION_CREATE' as WSEventType, interaction =>
this.command.handleInteraction(client, interaction)
Expand Down
13 changes: 10 additions & 3 deletions src/bot/command/AppCommandRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,27 @@ export default class AppCommandRegister {
*/
private readonly client: Client;
/**
* Name of the application command to rregister
* Name of the application command to register
* @private
*/
private readonly name: string;
/**
* Name of the option to mention another user
* @private
*/
private readonly optionName: string;

/**
* Constructs application command registration handler.
*
* @param client discord.js client instance
* @param name application name to register
* @param optionName name of the option to mention another user
*/
constructor(client: Client, name: string) {
constructor(client: Client, name: string, optionName: string) {
this.client = client;
this.name = name;
this.optionName = optionName;
}

/**
Expand Down Expand Up @@ -69,7 +76,7 @@ export default class AppCommandRegister {
options: [
{
type: 6,
name: 'opponent',
name: this.optionName,
description: localize.__('command.option-user')
}
]
Expand Down
4 changes: 4 additions & 0 deletions src/config/CommandConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ export default interface CommandConfig {
* Slash command used to start a new game.
*/
slashCommand?: string;
/**
* Name of slash command option to request a duel against another user.
*/
slashCommandOptionName?: string;
}
1 change: 1 addition & 0 deletions src/config/ConfigProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default class ConfigProvider implements Config {

public command = '!ttt';
public slashCommand = undefined;
public slashCommandOptionName = 'opponent';

public allowedChannelIds = [];
public allowedRoleIds = [];
Expand Down

0 comments on commit c17d275

Please sign in to comment.