use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class AnnounceCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Matcher m = getMatcher(message);
m.find();
Language lg = Translator.getLanguageFrom(message.getChannel());
String text = m.group(2).trim();
if (m.group(1) != null) {
for (IGuild guild : ClientConfig.DISCORD().getGuilds()) try {
if (guild.getDefaultChannel().getModifiedPermissions(ClientConfig.DISCORD().getOurUser()).contains(Permissions.SEND_MESSAGES))
Message.sendText(guild.getDefaultChannel(), text);
else
Message.sendText(guild.getOwner().getOrCreatePMChannel(), text);
} catch (DiscordException e) {
LOG.warn("onReady", "Impossible de contacter l'administrateur de la guilde [" + guild.getName() + "].");
} catch (Exception e2) {
LOG.warn("onReady", e2);
}
Message.sendText(message.getChannel(), Translator.getLabel(lg, "announce.request.1") + " " + ClientConfig.DISCORD().getGuilds().size() + " " + Translator.getLabel(lg, "announce.request.2") + (ClientConfig.DISCORD().getGuilds().size() > 1 ? "s" : "") + ".");
} else
Message.sendText(message.getChannel(), text);
return true;
}
return false;
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class AboutCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
IUser author = ClientConfig.DISCORD().getApplicationOwner();
EmbedBuilder builder = new EmbedBuilder();
Language lg = Translator.getLanguageFrom(message.getChannel());
builder.withTitle(Translator.getLabel(lg, "about.title").replace("{name}", Constants.name).replace("{version}", Constants.version)).withDesc(Translator.getLabel(lg, "about.desc").replace("{game}", Constants.game)).withColor(new Random().nextInt(16777216)).withThumbnail(ClientConfig.DISCORD().getApplicationIconURL()).withAuthorName(author.getName()).withAuthorIcon(author.getAvatarURL()).withImage(Constants.changelog);
;
builder.appendField(Translator.getLabel(lg, "about.invite.title"), Translator.getLabel(lg, "about.invite.desc").replace("{name}", Constants.name).replace("{invite}", Constants.invite), true).appendField(Translator.getLabel(lg, "about.support.title"), Translator.getLabel(lg, "about.support.desc").replace("{name}", Constants.name).replace("{discordInvite}", Constants.discordInvite), true).appendField(Translator.getLabel(lg, "about.twitter.title"), Translator.getLabel(lg, "about.twitter.desc").replace("{name}", Constants.name).replace("{twitter}", Constants.twitterAccount), true).appendField(Translator.getLabel(lg, "about.opensource.title"), Translator.getLabel(lg, "about.opensource.desc").replace("{git}", Constants.git), true).appendField(Translator.getLabel(lg, "about.free.title"), Translator.getLabel(lg, "about.free.desc").replace("{paypal}", Constants.paypal), true);
StringBuilder st = new StringBuilder();
for (Donator donator : Donator.values()) st.append(donator.getName()).append(", ");
st.setLength(st.length() - 2);
builder.appendField(Translator.getLabel(lg, "about.donators.title"), st.toString() + ".", true);
Message.sendEmbed(message.getChannel(), builder.build());
return true;
}
return false;
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class AlignmentCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Language lg = Translator.getLanguageFrom(message.getChannel());
Matcher m = getMatcher(message);
m.matches();
String content = m.group(1).trim();
// Initialisation du Filtre
City city;
Order order;
IUser user = message.getAuthor();
ServerDofus server = Guild.getGuild(message.getGuild()).getServerDofus();
List<ServerDofus> servers;
// Consultation filtré par niveau
if ((m = Pattern.compile(">\\s+(\\d{1,3})(\\s+.+)?").matcher(content)).matches()) {
Message.sendText(message.getChannel(), "Consultation filtré par niveau");
// TODO
} else {
// L'utilisateur concerné est-il l'auteur de la commande ?
if (Pattern.compile("^<@[!|&]?\\d+>").matcher(content).find()) {
content = content.replaceFirst("<@[!|&]?\\d+>", "").trim();
user = message.getMentions().get(0);
}
// Consultation des données filtrés par utilisateur
if (!(servers = findServer(content)).isEmpty() && (m = Pattern.compile("(.+)").matcher(content)).matches() || content.isEmpty()) {
Message.sendText(message.getChannel(), "Consultation des données utilisateur");
// TODO
} else // Enregistrement des données
if ((m = Pattern.compile("(\\p{L}+)\\s+(\\p{L}+)\\s+(\\d{1,3})(\\s+.+)?").matcher(content)).matches()) {
if (user == message.getAuthor() || user != message.getAuthor() && isUserHasEnoughRights(message)) {
// Parsing des données et traitement des divers exceptions
List<City> cities = findCity(m.group(1), lg);
if (!checkData(cities, tooMuchCities, notFoundCity, message, lg))
return false;
city = cities.get(0);
List<Order> orders = findOrder(m.group(2), lg);
if (!checkData(orders, tooMuchOrders, notFoundOrder, message, lg))
return false;
order = orders.get(0);
int level = Integer.parseInt(m.group(3));
if (m.group(4) != null) {
servers = findServer(m.group(4));
if (!checkData(servers, tooMuchServers, notFoundServer, message, lg))
return false;
server = servers.get(0);
} else if (server == null) {
notFoundGuildServer.throwException(message, this, lg);
return false;
}
if (OrderUser.getOrders().containsKey(Quadruple.of(user.getLongID(), server, city, order)))
OrderUser.getOrders().get(Quadruple.of(user.getLongID(), server, city, order)).setLevel(level);
else
new OrderUser(user.getLongID(), server, city, order, level).addToDatabase();
if (level != 0)
Message.sendText(message.getChannel(), "align.save");
else
Message.sendText(message.getChannel(), "align.reset");
} else
noEnoughRights.throwException(message, this, lg);
} else // Consultation filtré par cité et/ou par ordre
if ((m = Pattern.compile("(\\p{L}+)(\\s+\\p{L}+)?(\\s+[\\p{L}|\\W]+)?").matcher(content)).matches()) {
Message.sendText(message.getChannel(), "Consultation filtré par cité et/ou par ordre");
// TODO
} else
badUse.throwException(message, this, lg);
}
}
return false;
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class AlmanaxCommand method request.
@Override
public boolean request(IMessage message) {
if (super.request(message)) {
Language lg = Translator.getLanguageFrom(message.getChannel());
try {
Date date = new Date();
Matcher m = getMatcher(message);
m.find();
if (m.group(1) != null && (m.group(1).matches("\\s+true") || m.group(1).matches("\\s+0") || m.group(1).matches("\\s+on") || m.group(1).matches("\\s+false") || m.group(1).matches("\\s+1") || m.group(1).matches("\\s+off"))) {
if (!message.getChannel().isPrivate()) {
if (isUserHasEnoughRights(message)) {
if (m.group(1).matches("\\s+true") || m.group(1).matches("\\s+0") || m.group(1).matches("\\s+on"))
if (!AlmanaxCalendar.getAlmanaxCalendars().containsKey(message.getChannel().getStringID())) {
new AlmanaxCalendar(message.getGuild().getStringID(), message.getChannel().getStringID()).addToDatabase();
Message.sendText(message.getChannel(), Translator.getLabel(lg, "almanax.request.1"));
} else
Message.sendText(message.getChannel(), Translator.getLabel(lg, "almanax.request.2"));
else if (m.group(1).matches("\\s+false") || m.group(1).matches("\\s+1") || m.group(1).matches("\\s+off"))
if (AlmanaxCalendar.getAlmanaxCalendars().containsKey(message.getChannel().getStringID())) {
AlmanaxCalendar.getAlmanaxCalendars().get(message.getChannel().getStringID()).removeToDatabase();
Message.sendText(message.getChannel(), Translator.getLabel(lg, "almanax.request.3"));
} else
Message.sendText(message.getChannel(), Translator.getLabel(lg, "almanax.request.4"));
} else
noEnoughRights.throwException(message, this, lg);
} else
notUsableInMp.throwException(message, this, lg);
} else if (m.group(1) != null && m.group(1).matches("\\s+\\+\\d")) {
int number = Integer.parseInt(m.group(1).replaceAll("\\s+\\+", ""));
Message.sendEmbed(message.getChannel(), Almanax.getGroupedObject(lg, new Date(), number));
} else {
if (m.group(1) != null && m.group(1).matches("\\s+\\d{2}/\\d{2}/\\d{4}"))
date = Almanax.discordToBot.parse(m.group(1));
Almanax almanax = Almanax.get(lg, date);
Message.sendEmbed(message.getChannel(), almanax.getMoreEmbedObject(lg));
}
} catch (ParseException e) {
incorrectDateFormat.throwException(message, this, lg);
return false;
} catch (IOException e) {
ExceptionManager.manageIOException(e, message, this, lg, notFound);
} catch (Exception e) {
ExceptionManager.manageException(e, message, this, lg);
}
}
return false;
}
use of ai.elimu.model.v2.enums.Language in project KaellyBot by Kaysoro.
the class AlmanaxCalendar method start.
public static void start() {
if (!isStarted) {
isStarted = true;
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
long firstDelay = LocalDateTime.now().until(LocalDate.now().plusDays(1).atStartOfDay().plusMinutes(1), ChronoUnit.MINUTES);
long period = TimeUnit.DAYS.toMinutes(1);
scheduler.scheduleAtFixedRate(() -> {
boolean success = false;
Map<Language, Almanax> almanax = new HashMap<>();
while (!success) try {
almanax.clear();
for (Language lg : Language.values()) almanax.put(lg, Almanax.get(lg, new Date()));
success = true;
} catch (IOException e) {
ExceptionManager.manageSilentlyIOException(e);
try {
// 5min
Thread.sleep(300000);
} catch (InterruptedException e1) {
LOG.error("start", e1);
}
}
for (AlmanaxCalendar calendar : getAlmanaxCalendars().values()) try {
IChannel chan = ClientConfig.DISCORD().getChannelByID(Long.parseLong(calendar.getChan()));
Language lg = Translator.getLanguageFrom(chan);
if (chan != null && !chan.isDeleted())
Message.sendEmbed(chan, almanax.get(lg).getMoreEmbedObject(lg));
} catch (Exception e) {
LOG.error("AlmanaxCalendar", e);
}
}, firstDelay, period, TimeUnit.MINUTES);
}
}
Aggregations