Skip to content

Commit

Permalink
Merge pull request #156 from utarwyn/issue-56-switch-slash-command
Browse files Browse the repository at this point in the history
GH-56: Use slash command as the default one
  • Loading branch information
utarwyn committed Jan 24, 2022
2 parents 9563f6a + 9197d92 commit 49e08d1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions config/config.example.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"token": "YOUR_BOT_USER_TOKEN",
"language": "en",
"command": "!ttt",
"slashCommand": "tictactoe",
"command": "tictactoe",
"textCommand": "!ttt",
"allowedChannelIds": [],
"allowedRoleIds": [],
"requestExpireTime": 60,
Expand Down
6 changes: 3 additions & 3 deletions src/bot/TicTacToeBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ export default class TicTacToeBot {
*/
public attachToClient(client: Client): void {
// Handle slash command if enabled
if (this.configuration.slashCommand) {
if (this.configuration.command) {
const register = new AppCommandRegister(
client.application!.commands,
this.configuration.slashCommand
this.configuration.command
);
client.on('messageCreate', register.handleDeployMessage.bind(register));
client.on('interactionCreate', this.command.handleInteraction.bind(this.command));
}

// Handle text command if enabled
if (this.configuration.command) {
if (this.configuration.textCommand) {
client.on('messageCreate', this.command.handleMessage.bind(this.command));
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/bot/command/GameCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export default class GameCommand {
message.member &&
!message.author.bot &&
message.channel instanceof TextChannel &&
(noTrigger || (this.config.command && message.content.startsWith(this.config.command)))
(noTrigger ||
(this.config.textCommand && message.content.startsWith(this.config.textCommand)))
) {
const tunnel = new TextMessagingTunnel(message);
const invited = message.mentions.members?.first();
Expand All @@ -65,7 +66,7 @@ export default class GameCommand {
interaction instanceof CommandInteraction &&
interaction.channel instanceof TextChannel &&
interaction.member instanceof GuildMember &&
(noTrigger || interaction.commandName === this.config.slashCommand)
(noTrigger || interaction.commandName === this.config.command)
) {
// Retrieve the inviter and create an interaction tunnel
const tunnnel = new InteractionMessagingTunnel(interaction);
Expand Down
6 changes: 3 additions & 3 deletions src/config/CommandConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/
export default interface CommandConfig {
/**
* Text command used to start a new game.
* Slash command used to start a new game.
*/
command?: string;
/**
* Slash command used to start a new game.
* Text command used to start a new game.
*/
slashCommand?: string;
textCommand?: string;
}
4 changes: 2 additions & 2 deletions src/config/ConfigProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default class ConfigProvider implements Config {
public token = '';
public language = 'en';

public command = '!ttt';
public slashCommand = undefined;
public command = 'tictactoe';
public textCommand = undefined;

public allowedChannelIds = [];
public allowedRoleIds = [];
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class TicTacToe {

if (!loginToken) {
throw new Error('Bot token needed to start Discord client.');
} else if (!this.config.command && !this.config.slashCommand) {
throw new Error('Game text or slash command needed to start Discord client.');
} else if (!this.config.command && !this.config.textCommand) {
throw new Error('Game slash or text command needed to start Discord client.');
}

const client = new Client({
Expand Down

0 comments on commit 49e08d1

Please sign in to comment.