Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-56: Customize option name for slash command #160

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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