use of data.CommandForbidden in project KaellyBot by Kaysoro.
the class CommandCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Language lg = Translator.getLanguageFrom(message.getChannel());
if (isUserHasEnoughRights(message)) {
Guild guild = Guild.getGuild(message.getGuild());
Matcher m = getMatcher(message);
m.find();
List<Command> potentialCmds = new ArrayList<>();
String commandName = m.group(1).trim();
for (Command command : CommandManager.getCommands()) if (command.isPublic() && !command.isAdmin() && command.getName().contains(commandName))
potentialCmds.add(command);
if (potentialCmds.size() == 1) {
Command command = potentialCmds.get(0);
String value = m.group(2);
if (command instanceof CommandCommand) {
Message.sendText(message.getChannel(), Translator.getLabel(lg, "command.request.1"));
return false;
}
if (value.matches("false") || value.matches("1") || value.matches("off")) {
if (!guild.getForbiddenCommands().containsKey(command.getName())) {
new CommandForbidden(command, guild).addToDatabase();
Message.sendText(message.getChannel(), Translator.getLabel(lg, "command.request.2") + " *" + commandName + "* " + Translator.getLabel(lg, "command.request.3"));
} else
forbiddenCmdFound.throwException(message, this, lg);
} else if (value.matches("true") || value.matches("0") || value.matches("on")) {
if (guild.getForbiddenCommands().containsKey(command.getName())) {
guild.getForbiddenCommands().get(command.getName()).removeToDatabase();
Message.sendText(message.getChannel(), Translator.getLabel(lg, "command.request.2") + " *" + commandName + "* " + Translator.getLabel(lg, "command.request.4"));
} else
forbiddenCmdNotFound.throwException(message, this, lg);
} else
new BadUseCommandDiscordException().throwException(message, this, lg);
} else if (potentialCmds.isEmpty())
notFoundCmd.throwException(message, this, lg);
else
tooMuchCmds.throwException(message, this, lg);
} else
noEnoughRights.throwException(message, this, lg);
}
return false;
}
Aggregations