Skip to content

Commit 2db7897

Browse files
committed
More tests for annotated commands.
1 parent cfa4ab1 commit 2db7897

File tree

4 files changed

+67
-51
lines changed

4 files changed

+67
-51
lines changed

src/test/java/com/github/thiagotgm/modular_commands/TestBot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void main( String[] args ) {
4646
in.close();
4747
IDiscordClient client = new ClientBuilder().withToken( token ).build();
4848
ModuleLoader loader = client.getModuleLoader();
49-
loader.loadModule( new TestModule() );
49+
loader.loadModule( new ModularCommandsModule() );
5050
loader.loadModule( new TestModuleModule() );
5151
loader.loadModule( new TestPrefixModule() );
5252
loader.loadModule( new BuilderCommandsModule() );

src/test/java/com/github/thiagotgm/modular_commands/TestModule.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/test/java/com/github/thiagotgm/modular_commands/annotation/AnnotatedCommands.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
1+
/*
2+
* This file is part of ModularCommands.
3+
*
4+
* ModularCommands is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* ModularCommands is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with ModularCommands. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
118
package com.github.thiagotgm.modular_commands.annotation;
219

320
import com.github.thiagotgm.modular_commands.api.CommandContext;
421
import com.github.thiagotgm.modular_commands.command.annotation.MainCommand;
522
import com.github.thiagotgm.modular_commands.command.annotation.SubCommand;
623
import com.github.thiagotgm.modular_commands.command.annotation.SuccessHandler;
724

25+
/**
26+
* Annotation-based commands.
27+
*
28+
* @version 1.0
29+
* @author ThiagoTGM
30+
* @since 2017-07-21
31+
*/
832
public class AnnotatedCommands {
933

1034
@MainCommand(
@@ -59,5 +83,22 @@ public void success( CommandContext context ) {
5983
context.getReplyBuilder().withContent( "Success!" ).build();
6084

6185
}
86+
87+
@MainCommand(
88+
name = "Incorrect main command",
89+
aliases = { "wrong" }
90+
)
91+
public void wrong( CommandContext context, boolean thing ) { }
92+
93+
@MainCommand(
94+
name = "Prefixed annotated command",
95+
aliases = { "king" },
96+
prefix = ">-<|"
97+
)
98+
public void kingKong( CommandContext context ) {
99+
100+
context.getReplyBuilder().withContent( "kong!" ).build();
101+
102+
}
62103

63104
}

src/test/java/com/github/thiagotgm/modular_commands/annotation/AnnotationModule.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1+
/*
2+
* This file is part of ModularCommands.
3+
*
4+
* ModularCommands is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* ModularCommands is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with ModularCommands. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
118
package com.github.thiagotgm.modular_commands.annotation;
219

320
import com.github.thiagotgm.modular_commands.api.CommandRegistry;
4-
import com.github.thiagotgm.modular_commands.api.ICommand;
5-
import com.github.thiagotgm.modular_commands.command.annotation.AnnotationParser;
6-
721
import sx.blah.discord.api.IDiscordClient;
822
import sx.blah.discord.modules.IModule;
923

10-
24+
/**
25+
* Module for testing annotated commands.
26+
*
27+
* @version 1.0
28+
* @author ThiagoTGM
29+
* @since 2017-07-21
30+
*/
1131
public class AnnotationModule implements IModule {
1232

1333
@Override
1434
public boolean enable( IDiscordClient client ) {
1535

1636
CommandRegistry reg = CommandRegistry.getRegistry( client ).getSubRegistry( this );
17-
for ( ICommand command : new AnnotationParser( new AnnotatedCommands() ).parse() ) {
18-
reg.registerCommand( command );
19-
}
37+
reg.registerAnnotatedCommands( new AnnotatedCommands() );
2038
return true;
2139
}
2240

0 commit comments

Comments
 (0)