use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class MapCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Language lg = Translator.getLanguageFrom(message.getChannel());
List<String> classicMaps = new ArrayList<>();
for (int i = 1; i < 18; i++) classicMaps.add(String.valueOf(i));
List<String> maps = new ArrayList<>();
Matcher m = getMatcher(message);
m.find();
if (m.group(1) == null && m.group(2) == null)
maps.addAll(classicMaps);
else if (m.group(2) != null) {
String[] text = m.group(2).trim().toUpperCase().split("\\s+");
for (String value : text) {
value = getNumberValue(value);
if (value != null)
maps.add(value);
}
} else {
new BadUseCommandDiscordException().throwException(message, this, lg);
return false;
}
if (m.group(1) == null && maps.isEmpty()) {
new BadUseCommandDiscordException().throwException(message, this, lg);
return false;
} else if (m.group(1) != null) {
classicMaps.removeAll(maps);
maps = classicMaps;
}
String number = maps.get(new Random().nextInt(maps.size()));
String url = Constants.turnamentMapImg.replace("{number}", number);
String[] punchlines = Translator.getLabel(lg, "map.punchline").split(";");
String punchline = punchlines[new Random().nextInt(punchlines.length)];
EmbedBuilder builder = new EmbedBuilder();
builder.withTitle(Translator.getLabel(lg, "map.embed.title") + " " + numberToRoman(number));
builder.withDescription(punchline);
builder.withImage(url);
builder.withColor(new Random().nextInt(16777216));
builder.withImage(url);
Message.sendEmbed(message.getChannel(), builder.build());
}
return false;
}
use of ai.elimu.model.v2.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 ai.elimu.model.v2.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 ai.elimu.model.v2.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 ai.elimu.model.v2.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;
}
Aggregations