use of de.nikos410.discordBot.util.modular.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.
the class DiscordBot method makeCommandMap.
private void makeCommandMap() {
this.commands.clear();
for (final String key : this.loadedModules.keySet()) {
Object module = this.loadedModules.get(key);
for (Method method : module.getClass().getMethods()) {
if (method.isAnnotationPresent(CommandSubscriber.class)) {
final CommandSubscriber[] annotations = method.getDeclaredAnnotationsByType(CommandSubscriber.class);
final String command = annotations[0].command();
final String help = annotations[0].help();
final boolean pmAllowed = annotations[0].pmAllowed();
final int permissionLevel = annotations[0].permissionLevel();
final int parameterCount = method.getParameterCount();
final boolean passContext = annotations[0].passContext();
// Mindestens 1 (message), max 6 (message + 5 parameter)
if (parameterCount > 0 && parameterCount <= 6) {
final Command cmd = new Command(module, method, help, pmAllowed, permissionLevel, parameterCount - 1, passContext);
this.commands.put(command.toLowerCase(), cmd);
} else {
System.err.println("Ungültige Anzahl Parameter bei Befehl " + command);
}
}
}
final CommandModule moduleAnnotation = module.getClass().getDeclaredAnnotationsByType(CommandModule.class)[0];
if (!moduleAnnotation.commandOnly()) {
try {
this.client.getDispatcher().registerListener(module);
} catch (NullPointerException e) {
System.err.println("[Error] Could not get EventDispatcher: ");
Util.error(e);
}
}
}
}
use of de.nikos410.discordBot.util.modular.annotations.CommandSubscriber in project de-DiscordBot by DACH-Discord.
the class GeneralCommands method command_Uptime.
@CommandSubscriber(command = "uptime", help = "Zeigt seit wann der Bot online ist")
public void command_Uptime(final IMessage message) {
final DateTimeFormatter timeStampFormatter = DateTimeFormatter.ofPattern("dd.MM. | HH:mm");
Util.sendMessage(message.getChannel(), "Online seit: " + startupTimestamp.format(timeStampFormatter));
}
Aggregations