Search in sources :

Example 1 with TwitterFinder

use of finders.TwitterFinder in project KaellyBot by Kaysoro.

the class TwitterCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Language lg = Translator.getLanguageFrom(message.getChannel());
        // On check si la personne a bien les droits pour exécuter cette commande
        if (isUserHasEnoughRights(message)) {
            Matcher m = getMatcher(message);
            m.find();
            String value = m.group(1);
            if (value.matches("\\s+true") || value.matches("\\s+0") || value.matches("\\s+on")) {
                if (!TwitterFinder.getTwitterChannels().containsKey(message.getChannel().getLongID())) {
                    new TwitterFinder(message.getGuild().getLongID(), message.getChannel().getLongID()).addToDatabase();
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "twitter.request.1").replace("{twitter.name}", Translator.getLabel(lg, "twitter.name")));
                } else
                    twitterFound.throwException(message, this, lg);
            } else if (value.matches("\\s+false") || value.matches("\\s+1") || value.matches("\\s+off")) {
                if (TwitterFinder.getTwitterChannels().containsKey(message.getChannel().getLongID())) {
                    TwitterFinder.getTwitterChannels().get(message.getChannel().getLongID()).removeToDatabase();
                    Message.sendText(message.getChannel(), Translator.getLabel(lg, "twitter.request.2").replace("{twitter.name}", Translator.getLabel(lg, "twitter.name")));
                } else
                    twitterNotFound.throwException(message, this, lg);
            } else
                new BadUseCommandDiscordException().throwException(message, this, lg);
        } else
            noEnoughRights.throwException(message, this, lg);
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) TwitterFinder(finders.TwitterFinder)

Example 2 with TwitterFinder

use of finders.TwitterFinder 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

TwitterFinder (finders.TwitterFinder)2 Language (enums.Language)1 AlmanaxCalendar (finders.AlmanaxCalendar)1 RSSFinder (finders.RSSFinder)1 Matcher (java.util.regex.Matcher)1 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)1 IChannel (sx.blah.discord.handle.obj.IChannel)1