use of enums.Language in project KaellyBot by Kaysoro.
the class RandomCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Language lg = Translator.getLanguageFrom(message.getChannel());
Matcher m = getMatcher(message);
m.find();
if (m.group(1) == null) {
boolean value = new Random().nextBoolean();
Message.sendText(message.getChannel(), value ? Translator.getLabel(lg, "random.request.1") : Translator.getLabel(lg, "random.request.2") + " !");
} else if (m.group(1).matches("\\s+-?\\d+")) {
try {
int limit = Integer.parseInt(m.group(1).trim());
if (limit > 0)
Message.sendText(message.getChannel(), new Random().nextInt(limit) + " !");
else
Message.sendText(message.getChannel(), Translator.getLabel(lg, "random.request.3"));
} catch (NumberFormatException e) {
Message.sendText(message.getChannel(), Translator.getLabel(lg, "random.request.4") + " " + Integer.MAX_VALUE + ").");
}
} else {
String value = m.group(1).trim();
String[] values = value.split("\\s+");
Message.sendText(message.getChannel(), values[new Random().nextInt(values.length)] + " !");
}
}
return false;
}
use of enums.Language in project KaellyBot by Kaysoro.
the class AdminCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
String prefixe = getPrefixMdEscaped(message);
Language lg = Translator.getLanguageFrom(message.getChannel());
Matcher m = getMatcher(message);
m.find();
StringBuilder st = new StringBuilder();
boolean argumentFound = m.group(1) != null && m.group(1).replaceAll("^\\s+", "").length() > 0;
for (Command command : CommandManager.getCommands()) if (command.isAdmin()) {
if (!argumentFound)
st.append(command.help(lg, prefixe)).append("\n");
else if (command.getName().equals(m.group(1).trim())) {
st.append(command.helpDetailed(lg, prefixe));
break;
}
}
if (argumentFound && st.length() == 0)
notFound.throwException(message, this, lg);
else
Message.sendText(message.getChannel(), st.toString());
return true;
}
return false;
}
use of enums.Language in project KaellyBot by Kaysoro.
the class AvailableCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Matcher m = getMatcher(message);
m.find();
Language lg = Translator.getLanguageFrom(message.getChannel());
List<Command> potentialCmds = new ArrayList<>();
String commandName = m.group(1).trim();
for (Command command : CommandManager.getCommands()) if (!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 AvailableCommand || command instanceof AboutCommand) {
Message.sendText(message.getChannel(), Translator.getLabel(lg, "announce.request.1"));
return false;
}
if (value.matches("false") || value.matches("1") || value.matches("off")) {
if (command.isPublic()) {
command.setPublic(false);
Message.sendText(message.getChannel(), Translator.getLabel(lg, "announce.request.2") + " *" + commandName + "* " + Translator.getLabel(lg, "announce.request.3"));
} else
forbiddenCmdFound.throwException(message, this, lg);
} else if (value.matches("true") || value.matches("0") || value.matches("on")) {
if (!command.isPublic()) {
command.setPublic(true);
Message.sendText(message.getChannel(), Translator.getLabel(lg, "announce.request.2") + "*" + commandName + "* " + Translator.getLabel(lg, "announce.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);
}
return false;
}
use of enums.Language in project KaellyBot by Kaysoro.
the class StatCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Matcher m = getMatcher(message);
m.find();
Language lg = Translator.getLanguageFrom(message.getChannel());
int totalUser = 0;
for (IGuild guild : ClientConfig.DISCORD().getGuilds()) totalUser += guild.getUsers().size();
String answer = Translator.getLabel(lg, "stat.request").replace("{guilds.size}", String.valueOf(ClientConfig.DISCORD().getGuilds().size())).replace("{users.size}", String.valueOf(ClientConfig.DISCORD().getUsers().size())).replace("{users_max.size}", String.valueOf(totalUser));
Message.sendText(message.getChannel(), answer);
}
return false;
}
use of enums.Language in project KaellyBot by Kaysoro.
the class TalkCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Language lg = Translator.getLanguageFrom(message.getChannel());
Matcher m = getMatcher(message);
m.find();
String text = m.group(2).trim();
if (m.group(1) != null) {
long value = Long.parseLong(m.group(1).trim());
lastChan = ClientConfig.DISCORD().getChannelByID(value);
}
if (lastChan == null) {
notFoundChan.throwException(message, this, lg);
return false;
}
if (lastChan.getModifiedPermissions(ClientConfig.DISCORD().getOurUser()).contains(Permissions.SEND_MESSAGES))
Message.sendText(lastChan, text);
else
noSendTextPermission.throwException(message, this, lg);
return true;
}
return false;
}
Aggregations