Search in sources :

Example 1 with IChannel

use of sx.blah.discord.handle.obj.IChannel 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);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) IChannel(sx.blah.discord.handle.obj.IChannel) HashMap(java.util.HashMap) Almanax(data.Almanax) IOException(java.io.IOException) Date(java.util.Date) LocalDate(java.time.LocalDate) IOException(java.io.IOException) SQLException(java.sql.SQLException) Language(enums.Language)

Example 2 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project KaellyBot by Kaysoro.

the class RSSFinder method getRSSFinders.

public static synchronized Map<String, RSSFinder> getRSSFinders() {
    if (rssFinders == null) {
        rssFinders = new ConcurrentHashMap<>();
        Connexion connexion = Connexion.getInstance();
        Connection connection = connexion.getConnection();
        try {
            PreparedStatement query = connection.prepareStatement("SELECT id_guild, id_chan, last_update FROM RSS_Finder");
            ResultSet resultSet = query.executeQuery();
            while (resultSet.next()) {
                String idChan = resultSet.getString("id_chan");
                String idGuild = resultSet.getString("id_guild");
                long lastUpdate = resultSet.getLong("last_update");
                IChannel chan = ClientConfig.DISCORD().getChannelByID(Long.parseLong(idChan));
                if (chan != null && !chan.isDeleted())
                    rssFinders.put(chan.getStringID(), new RSSFinder(chan.getGuild().getStringID(), chan.getStringID(), lastUpdate));
                else {
                    new RSSFinder(idGuild, idChan).removeToDatabase();
                    LOG.info("Chan deleted : " + idChan);
                }
            }
        } catch (SQLException e) {
            Reporter.report(e);
            LOG.error("getRSSFinders", e);
        }
    }
    return rssFinders;
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 3 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project KaellyBot by Kaysoro.

the class TwitterFinder method getTwitterChannels.

public static synchronized Map<Long, TwitterFinder> getTwitterChannels() {
    if (twitterChannels == null) {
        twitterChannels = new ConcurrentHashMap<>();
        Connexion connexion = Connexion.getInstance();
        Connection connection = connexion.getConnection();
        try {
            PreparedStatement query = connection.prepareStatement("SELECT id_guild, id_chan FROM Twitter");
            ResultSet resultSet = query.executeQuery();
            while (resultSet.next()) {
                long idChan = Long.parseLong(resultSet.getString("id_chan"));
                long idGuild = Long.parseLong(resultSet.getString("id_guild"));
                IChannel chan = ClientConfig.DISCORD().getChannelByID(idChan);
                if (chan != null && !chan.isDeleted())
                    twitterChannels.put(chan.getLongID(), new TwitterFinder(idGuild, idChan));
                else {
                    new TwitterFinder(idGuild, idChan).removeToDatabase();
                    LOG.info("Chan deleted : " + idChan);
                }
            }
        } catch (SQLException e) {
            Reporter.report(e);
            LOG.error("getTwitterChannels", e);
        }
    }
    return twitterChannels;
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Connexion(util.Connexion)

Example 4 with IChannel

use of sx.blah.discord.handle.obj.IChannel 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)

Example 5 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project DisCal-Discord-Bot by NovaFox161.

the class DevCommand method moduleEval.

@SuppressWarnings("all")
private void moduleEval(MessageReceivedEvent event) {
    IGuild guild = event.getGuild();
    IUser user = event.getAuthor();
    IMessage message = event.getMessage();
    IDiscordClient client = event.getClient();
    IChannel channel = event.getChannel();
    String input = message.getContent().substring(message.getContent().indexOf("eval") + 5).replaceAll("`", "");
    Object o = null;
    factory.put("guild", guild);
    factory.put("channel", channel);
    factory.put("user", user);
    factory.put("message", message);
    factory.put("command", this);
    factory.put("client", client);
    factory.put("builder", new EmbedBuilder());
    factory.put("cUser", client.getOurUser());
    try {
        o = factory.eval(input);
    } catch (Exception ex) {
        EmbedBuilder em = new EmbedBuilder();
        em.withAuthorIcon(guild.getIconURL());
        em.withAuthorName("Error");
        em.withDesc(ex.getMessage());
        em.withFooterText("Eval failed");
        em.withColor(56, 138, 237);
        Message.sendMessage(em.build(), channel);
        return;
    }
    EmbedBuilder em = new EmbedBuilder();
    em.withAuthorIcon(guild.getIconURL());
    em.withAuthorName("Success!");
    em.withColor(56, 138, 237);
    em.withTitle("Evaluation output.");
    em.withDesc(o == null ? "No output, object is null" : o.toString());
    em.appendField("Input", "```java\n" + input + "\n```", false);
    em.withFooterText("Eval successful!");
    Message.sendMessage(em.build(), channel);
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IChannel(sx.blah.discord.handle.obj.IChannel) IMessage(sx.blah.discord.handle.obj.IMessage) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild) IDiscordClient(sx.blah.discord.api.IDiscordClient) DiscordException(sx.blah.discord.util.DiscordException)

Aggregations

IChannel (sx.blah.discord.handle.obj.IChannel)44 IGuild (sx.blah.discord.handle.obj.IGuild)7 IRole (sx.blah.discord.handle.obj.IRole)7 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)7 SQLException (java.sql.SQLException)6 IUser (sx.blah.discord.handle.obj.IUser)6 ProfileObject (com.github.vaerys.objects.ProfileObject)5 SplitFirstObject (com.github.vaerys.objects.SplitFirstObject)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)4 CommandObject (com.github.vaerys.commands.CommandObject)3 ChannelSetting (com.github.vaerys.enums.ChannelSetting)3 StringHandler (com.github.vaerys.handlers.StringHandler)3 UserObject (com.github.vaerys.masterobjects.UserObject)3 CCommandObject (com.github.vaerys.objects.CCommandObject)3 XEmbedBuilder (com.github.vaerys.objects.XEmbedBuilder)3 IOException (java.io.IOException)3 DBGuild (me.shadorc.shadbot.data.db.DBGuild)3