Search in sources :

Example 1 with AlmanaxCalendar

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;
}
Also used : AlmanaxCalendar(finders.AlmanaxCalendar) Language(enums.Language) Matcher(java.util.regex.Matcher) Almanax(data.Almanax) ParseException(java.text.ParseException) IOException(java.io.IOException) Date(java.util.Date) IOException(java.io.IOException) Exception(java.lang.Exception) ParseException(java.text.ParseException)

Example 2 with AlmanaxCalendar

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);
    }
}
Also used : AlmanaxCalendar(finders.AlmanaxCalendar) IChannel(sx.blah.discord.handle.obj.IChannel) RSSFinder(finders.RSSFinder) TwitterFinder(finders.TwitterFinder) EventSubscriber(sx.blah.discord.api.events.EventSubscriber)

Aggregations

AlmanaxCalendar (finders.AlmanaxCalendar)2 Almanax (data.Almanax)1 Language (enums.Language)1 RSSFinder (finders.RSSFinder)1 TwitterFinder (finders.TwitterFinder)1 IOException (java.io.IOException)1 Exception (java.lang.Exception)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)1 IChannel (sx.blah.discord.handle.obj.IChannel)1