Skip to content
This repository was archived by the owner on Oct 1, 2019. It is now read-only.

Commit 2bfdee8

Browse files
committed
Release 2.6.0: Major changes to module and command framework
2 parents a7bcc7b + 829b0f1 commit 2bfdee8

19 files changed

+832
-561
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ tasks.withType(JavaCompile) {
3131
options.encoding = "UTF-8"
3232
}
3333

34-
version = '2.5.1'
34+
version = '2.6.0'
3535
sourceCompatibility = 1.8
3636
mainClassName = 'de.nikos410.discordbot.DiscordBot'
3737

src/main/java/de/nikos410/discordbot/DiscordBot.java

+273-236
Large diffs are not rendered by default.

src/main/java/de/nikos410/discordbot/framework/Command.java

-39
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package de.nikos410.discordbot.framework;
2+
3+
import de.nikos410.discordbot.DiscordBot;
4+
5+
public abstract class CommandModule {
6+
protected DiscordBot bot = null;
7+
8+
/**
9+
* @return Specify the name of this module that is seen by the public. (e.g. when listing commands)
10+
*/
11+
public abstract String getDisplayName();
12+
13+
/**
14+
* @return Provide a brief description of what the module does.
15+
*/
16+
public abstract String getDescription();
17+
18+
/**
19+
* @return Specify whether to register the module with the bot's {@link sx.blah.discord.api.events.EventDispatcher}.
20+
* Set this to true if this module is using {@link sx.blah.discord.api.events.EventSubscriber}s.
21+
*/
22+
public boolean hasEvents() {
23+
return false;
24+
}
25+
26+
/**
27+
* Set the bot field to the current bot instance.
28+
*
29+
* @param bot The bot instance.
30+
*/
31+
public void setBot(final DiscordBot bot) {
32+
this.bot = bot;
33+
}
34+
35+
/**
36+
* Gets called when the module is initialized.
37+
*/
38+
public void init() {}
39+
40+
/**
41+
* Gets called when the module is initialized and the bot is ready.
42+
*/
43+
public void initWhenReady() {}
44+
45+
/**
46+
* Gets called when the module is disabled or the bot is shut down
47+
*/
48+
public void shutdown() {}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package de.nikos410.discordbot.framework;
2+
3+
import java.lang.reflect.Method;
4+
5+
/**
6+
* Wrapper class containing the properties for a bot command.
7+
*/
8+
public class CommandWrapper {
9+
private final String name;
10+
private final String help;
11+
private final ModuleWrapper module;
12+
private final Method method;
13+
private final boolean pmAllowed;
14+
private final PermissionLevel permissionLevel;
15+
private final int expectedParameterCount;
16+
private final boolean passContext;
17+
private final boolean ignoreParameterCount;
18+
19+
/**
20+
* Create a new command wrapper.
21+
*
22+
* @param name The name of this command.
23+
* @param help The help for this command.
24+
* @param module The name of module that contains the command.
25+
* @param method The method that should be invoked to execute the command.
26+
* @param pmAllowed Set whether the command should be available in private messages.
27+
* @param permissionLevel Which permission level is necessary to execute the command.
28+
* @param expectedParameterCount The number of parameters the command accepts.
29+
* @param passContext Set whether to append additional parameters or to ignore them.
30+
* @param ignoreParameterCount Don't check if enough parameters are given when executing.
31+
*/
32+
public CommandWrapper(final String name,
33+
final String help,
34+
final ModuleWrapper module,
35+
final Method method,
36+
final boolean pmAllowed,
37+
final PermissionLevel permissionLevel,
38+
final int expectedParameterCount,
39+
final boolean passContext,
40+
final boolean ignoreParameterCount) {
41+
this.name = name;
42+
this.help = help;
43+
this.module = module;
44+
this.method = method;
45+
this.pmAllowed = pmAllowed;
46+
this.permissionLevel = permissionLevel;
47+
this.expectedParameterCount = expectedParameterCount;
48+
this.passContext = passContext;
49+
this.ignoreParameterCount = ignoreParameterCount;
50+
}
51+
52+
/**
53+
* @return The name of this command.
54+
*/
55+
public String getName() {
56+
return name;
57+
}
58+
59+
/**
60+
* @return The help for this command.
61+
*/
62+
public String getHelp() {
63+
return help;
64+
}
65+
66+
/**
67+
* @return The name of the module that contains this command.
68+
*/
69+
public ModuleWrapper getModule() {
70+
return module;
71+
}
72+
73+
/**
74+
* @return The method that should be invoked to execute the command.
75+
*/
76+
public Method getMethod() {
77+
return method;
78+
}
79+
80+
/**
81+
* @return True if the command should be available in private messages.
82+
*/
83+
public boolean isPmAllowed() {
84+
return pmAllowed;
85+
}
86+
87+
/**
88+
* @return The permission level that is necessary to execute the command.
89+
*/
90+
public PermissionLevel getPermissionLevel() {
91+
return permissionLevel;
92+
}
93+
94+
/**
95+
* @return The number of parameters the command accepts.
96+
*/
97+
public int getExpectedParameterCount() {
98+
return expectedParameterCount;
99+
}
100+
101+
/**
102+
* @return True if additional parameters should be appended to the last one or ignored.
103+
*/
104+
public boolean isPassContext() {
105+
return passContext;
106+
}
107+
108+
/**
109+
* @return True if the parameter count check should be ignored.
110+
*/
111+
public boolean isIgnoreParameterCount() {
112+
return ignoreParameterCount;
113+
}
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package de.nikos410.discordbot.framework;
2+
3+
import java.util.List;
4+
5+
/**
6+
* Wrapper class containing a bot module's instance and a list of all commands in this module.
7+
*/
8+
public class ModuleWrapper {
9+
private final Class<? extends CommandModule> moduleClass;
10+
private final String name;
11+
12+
private String displayName;
13+
private String description;
14+
private CommandModule instance;
15+
private List<CommandWrapper> commands;
16+
private ModuleStatus status;
17+
18+
public ModuleWrapper(final Class<? extends CommandModule> moduleClass) {
19+
this.moduleClass = moduleClass;
20+
this.name = moduleClass.getSimpleName();
21+
}
22+
23+
public Class<? extends CommandModule> getModuleClass() {
24+
return moduleClass;
25+
}
26+
27+
public String getName() {
28+
return name;
29+
}
30+
31+
public String getDisplayName() {
32+
return displayName;
33+
}
34+
35+
public void setDisplayName(final String displayName) {
36+
this.displayName = displayName;
37+
}
38+
39+
public String getDescription() {
40+
return description;
41+
}
42+
43+
public void setDescription(String description) {
44+
this.description = description;
45+
}
46+
47+
public CommandModule getInstance() {
48+
return instance;
49+
}
50+
51+
public void setInstance(final CommandModule instance) {
52+
this.instance = instance;
53+
}
54+
55+
public List<CommandWrapper> getCommands() {
56+
return commands;
57+
}
58+
59+
public void setCommands(final List<CommandWrapper> commands) {
60+
this.commands = commands;
61+
}
62+
63+
public ModuleStatus getStatus() {
64+
return status;
65+
}
66+
67+
public void setStatus(final ModuleStatus status) {
68+
this.status = status;
69+
}
70+
71+
/**
72+
* Enum for specifying the current status of a module.
73+
*/
74+
public enum ModuleStatus {
75+
/**
76+
* The module is loaded, it's features are available.
77+
*/
78+
ACTIVE,
79+
80+
/**
81+
* The module is not loaded, it's features are not available.
82+
*/
83+
INACTIVE,
84+
85+
/**
86+
* The module could not be loaded.
87+
*/
88+
FAILED,
89+
}
90+
}

src/main/java/de/nikos410/discordbot/framework/annotations/CommandModule.java

-24
This file was deleted.

src/main/java/de/nikos410/discordbot/framework/annotations/CommandSubscriber.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import de.nikos410.discordbot.framework.PermissionLevel;
44

5-
import java.lang.annotation.Target;
65
import java.lang.annotation.ElementType;
76
import java.lang.annotation.Retention;
87
import java.lang.annotation.RetentionPolicy;
8+
import java.lang.annotation.Target;
99

1010
@Target(ElementType.METHOD)
1111
@Retention(RetentionPolicy.RUNTIME)

0 commit comments

Comments
 (0)