use of finders.AlmanaxCalendar 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 finders.AlmanaxCalendar in project KaellyBot by Kaysoro.
the class GuildLeaveListener method onReady.
@EventSubscriber
public void onReady(GuildLeaveEvent event) {
try {
Guild guild = Guild.getGuild(event.getGuild(), false);
if (guild != null) {
guild.removeToDatabase();
LOG.info("La guilde " + event.getGuild().getStringID() + " - " + event.getGuild().getName() + " a supprimé " + Constants.name);
for (RSSFinder finder : RSSFinder.getRSSFinders().values()) {
IChannel chan = event.getGuild().getChannelByID(Long.parseLong(finder.getChan()));
if (chan != null && chan.isDeleted()) {
finder.removeToDatabase();
LOG.info("RSS Chan \"" + chan.getName() + "\"");
}
}
for (TwitterFinder finder : TwitterFinder.getTwitterChannels().values()) {
IChannel chan = event.getGuild().getChannelByID(finder.getChannelId());
if (chan != null && chan.isDeleted()) {
finder.removeToDatabase();
LOG.info("Twitter Chan \"" + chan.getName() + "\"");
}
}
for (AlmanaxCalendar finder : AlmanaxCalendar.getAlmanaxCalendars().values()) {
IChannel chan = event.getGuild().getChannelByID(Long.parseLong(finder.getChan()));
if (chan != null && chan.isDeleted()) {
finder.removeToDatabase();
LOG.info("Almanax Chan \"" + chan.getName() + "\"");
}
}
}
Message.sendText(ClientConfig.DISCORD().getChannelByID(Constants.chanReportID), "[LOSE] **" + event.getGuild().getName() + "**, -" + event.getGuild().getUsers().size() + " utilisateurs");
} catch (Exception e) {
Reporter.report(e, event.getGuild());
LOG.error("onReady", e);
}
}
Aggregations