use of de.nikos410.discordbot.framework.PermissionLevel in project de-DiscordBot by DACH-Discord.
the class DiscordBot method discoverCommands.
private List<CommandWrapper> discoverCommands(final ModuleWrapper moduleWrapper) {
LOG.debug("Registering command(s) for module '{}'.", moduleWrapper.getName());
final List<CommandWrapper> commands = new LinkedList<>();
final Method[] allMethods = moduleWrapper.getModuleClass().getMethods();
final List<Method> commandMethods = Arrays.stream(allMethods).filter(module -> module.isAnnotationPresent(CommandSubscriber.class)).collect(Collectors.toList());
for (final Method method : commandMethods) {
// Register methods with the @CommandSubscriber as commands
// All annotations of type CommandSubscriber declared for that Method. Should be exactly 1
final CommandSubscriber annotation = method.getDeclaredAnnotationsByType(CommandSubscriber.class)[0];
// Get command properties from annotation
final String commandName = annotation.command();
final String commandHelp = annotation.help();
final boolean pmAllowed = annotation.pmAllowed();
final PermissionLevel permissionLevel = annotation.permissionLevel();
final boolean passContext = annotation.passContext();
final boolean ignoreParameterCount = annotation.ignoreParameterCount();
final int parameterCount = method.getParameterCount() - 1;
if ((parameterCount >= 0 && parameterCount <= 5) || ignoreParameterCount) {
final CommandWrapper commandWrapper = new CommandWrapper(commandName, commandHelp, moduleWrapper, method, pmAllowed, permissionLevel, parameterCount, passContext, ignoreParameterCount);
commands.add(commandWrapper);
LOG.debug("Saved command '{}'.", commandName);
} else {
LOG.warn("Method '{}' has an invalid number of arguments. Skipping", commandName);
}
}
return commands;
}
use of de.nikos410.discordbot.framework.PermissionLevel in project de-DiscordBot by DACH-Discord.
the class Rules method command_setRegeln.
@CommandSubscriber(command = "setRegeln", help = "Regeln (deutsch) ändern", permissionLevel = PermissionLevel.ADMIN, pmAllowed = false)
public void command_setRegeln(final IMessage message, final String rulesDE) {
final IGuild guild = message.getGuild();
final JSONObject guildJSON = getJSONForGuild(guild);
guildJSON.put("rulesDE", rulesDE);
saveJSON();
DiscordIO.sendMessage(message.getChannel(), ":white_check_mark: Regeln (DE) geändert:");
DiscordIO.sendMessage(message.getChannel(), rulesDE);
LOG.info(String.format("%s changed rules. (DE)", UserUtils.makeUserString(message.getAuthor(), message.getGuild())));
}
use of de.nikos410.discordbot.framework.PermissionLevel in project de-DiscordBot by DACH-Discord.
the class Rules method command_setFooter.
@CommandSubscriber(command = "setFooter", help = "Footer der Begüßungsnachricht ändern.", permissionLevel = PermissionLevel.ADMIN, pmAllowed = false)
public void command_setFooter(final IMessage message, final String footer) {
final IGuild guild = message.getGuild();
final JSONObject guildJSON = getJSONForGuild(guild);
guildJSON.put("footer", footer);
saveJSON();
DiscordIO.sendMessage(message.getChannel(), ":white_check_mark: Begrüßungs-Footer geändert:");
DiscordIO.sendMessage(message.getChannel(), footer);
LOG.info(String.format("%s changed rules. (DE)", UserUtils.makeUserString(message.getAuthor(), message.getGuild())));
}
use of de.nikos410.discordbot.framework.PermissionLevel in project de-DiscordBot by DACH-Discord.
the class UserLog method command_userlogTest.
@CommandSubscriber(command = "userlogTest", help = "Userlog-Ausgabe testen", permissionLevel = PermissionLevel.ADMIN)
public void command_userlogTest(final IMessage message) {
final IUser user = message.getAuthor();
final IGuild guild = message.getGuild();
final JSONObject guildJSON = getJSONForGuild(guild);
if (!guildJSON.has("channel")) {
DiscordIO.sendMessage(message.getChannel(), "Fehler! Kein Kanal hinterlegt!");
return;
}
final long channelID = guildJSON.getLong("channel");
final IChannel channel = guild.getChannelByID(channelID);
if (channel != null) {
userJoinNotify(user, channel);
userLeaveNotify(user, channel);
userBanNotify(user, channel);
}
}
use of de.nikos410.discordbot.framework.PermissionLevel in project de-DiscordBot by DACH-Discord.
the class UserLog method command_disableUserlog.
@CommandSubscriber(command = "disableUserlog", help = "Userlog deaktivieren", permissionLevel = PermissionLevel.ADMIN)
public void command_disableUserlog(final IMessage message) {
final IGuild guild = message.getGuild();
final JSONObject guildJSON = getJSONForGuild(guild);
guildJSON.put("on", false);
saveUserLogJSON();
// :white_check_mark:
message.addReaction(ReactionEmoji.of("✅"));
}
Aggregations