Search in sources :

Example 26 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project Shadbot by Shadorc.

the class ServerInfoCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    IGuild guild = context.getGuild();
    DBGuild dbGuild = Database.getDBGuild(guild);
    StringBuilder settingsStr = new StringBuilder();
    if (!dbGuild.getPrefix().equals(Config.DEFAULT_PREFIX)) {
        settingsStr.append(String.format("**Prefix:** %s", context.getPrefix()));
    }
    if (dbGuild.getDefaultVol() != Config.DEFAULT_VOLUME) {
        settingsStr.append(String.format("%n**Default volume:** %d%%", dbGuild.getDefaultVol()));
    }
    if (!dbGuild.getAllowedChannels().isEmpty()) {
        List<IChannel> channels = dbGuild.getAllowedChannels().stream().map(guild::getChannelByID).filter(Objects::nonNull).collect(Collectors.toList());
        settingsStr.append(String.format("%n**Allowed channels:**%n\t%s", FormatUtils.format(channels, IChannel::getName, "\n\t")));
    }
    if (!dbGuild.getBlacklistedCmd().isEmpty()) {
        settingsStr.append(String.format("%n**Blacklisted commands:**%n\t%s", FormatUtils.format(dbGuild.getBlacklistedCmd(), Object::toString, "\n\t")));
    }
    if (!dbGuild.getAutoRoles().isEmpty()) {
        List<IRole> roles = dbGuild.getAutoRoles().stream().map(guild::getRoleByID).filter(Objects::nonNull).collect(Collectors.toList());
        settingsStr.append(String.format("%n**Auto-roles:**%n\t%s", FormatUtils.format(roles, IRole::mention, "\n\t")));
    }
    String creationDate = String.format("%s%n(%s)", TimeUtils.toLocalDate(guild.getCreationDate()).format(dateFormatter), FormatUtils.formatLongDuration(guild.getCreationDate()));
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName(String.format("Info about \"%s\"", guild.getName())).withThumbnail(guild.getIconURL()).appendField("Owner", guild.getOwner().getName(), true).appendField("Server ID", Long.toString(guild.getLongID()), true).appendField("Creation date", creationDate, true).appendField("Region", guild.getRegion().getName(), true).appendField("Channels", String.format("**Voice:** %d", guild.getVoiceChannels().size()) + String.format("%n**Text:** %d", guild.getChannels().size()), true).appendField("Members", Integer.toString(guild.getTotalMemberCount()), true).appendField("Settings", settingsStr.toString(), true);
    BotUtils.sendMessage(embed.build(), context.getChannel());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) DBGuild(me.shadorc.shadbot.data.db.DBGuild) IChannel(sx.blah.discord.handle.obj.IChannel) IRole(sx.blah.discord.handle.obj.IRole) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 27 with IChannel

use of sx.blah.discord.handle.obj.IChannel in project Shadbot by Shadorc.

the class AutoMessageSetting method channel.

private void channel(Context context, Action action) throws MissingArgumentException {
    List<IChannel> channelsMentioned = context.getMessage().getChannelMentions();
    if (channelsMentioned.size() != 1) {
        throw new MissingArgumentException();
    }
    DBGuild dbGuild = Database.getDBGuild(context.getGuild());
    IChannel channel = channelsMentioned.get(0);
    if (Action.ENABLE.equals(action)) {
        dbGuild.setSetting(SettingEnum.MESSAGE_CHANNEL_ID, channel.getLongID());
        BotUtils.sendMessage(String.format(Emoji.CHECK_MARK + " %s is now the default channel for join/leave messages.", channel.mention()), context.getChannel());
    } else if (Action.DISABLE.equals(action)) {
        dbGuild.removeSetting(SettingEnum.MESSAGE_CHANNEL_ID);
        BotUtils.sendMessage(String.format(Emoji.CHECK_MARK + " Auto-messages disabled. I will no longer send automatic messages " + "until a new channel is defined.", channel.mention()), context.getChannel());
    }
}
Also used : IChannel(sx.blah.discord.handle.obj.IChannel) DBGuild(me.shadorc.shadbot.data.db.DBGuild) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException)

Example 28 with IChannel

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

the class ChannelLanguage method getChannelLanguages.

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

Example 29 with IChannel

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

the class AlmanaxCalendar method getAlmanaxCalendars.

public static synchronized Map<String, AlmanaxCalendar> getAlmanaxCalendars() {
    if (almanaxCalendar == null) {
        almanaxCalendar = new HashMap<>();
        Connexion connexion = Connexion.getInstance();
        Connection connection = connexion.getConnection();
        try {
            PreparedStatement query = connection.prepareStatement("SELECT id_guild, id_chan FROM Almanax_Calendar");
            ResultSet resultSet = query.executeQuery();
            while (resultSet.next()) {
                String idChan = resultSet.getString("id_chan");
                String idGuild = resultSet.getString("id_guild");
                IChannel chan = ClientConfig.DISCORD().getChannelByID(Long.parseLong(idChan));
                if (chan != null && !chan.isDeleted())
                    almanaxCalendar.put(chan.getStringID(), new AlmanaxCalendar(chan.getGuild().getStringID(), chan.getStringID()));
                else {
                    new RSSFinder(idGuild, idChan).removeToDatabase();
                    LOG.info("Chan deleted : " + idChan);
                }
            }
        } catch (SQLException e) {
            Reporter.report(e);
            LOG.error("getAlmanaxCalendars", e);
        }
    }
    return almanaxCalendar;
}
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 30 with IChannel

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

the class RSSFinder method start.

public static void start() {
    if (!isStarted) {
        isStarted = true;
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
        scheduler.scheduleAtFixedRate(() -> {
            Map<Language, List<RSS>> allFeeds = new HashMap<>();
            for (Language lg : Language.values()) allFeeds.put(lg, RSS.getRSSFeeds(lg));
            for (RSSFinder finder : getRSSFinders().values()) try {
                IChannel chan = ClientConfig.DISCORD().getChannelByID(Long.parseLong(finder.getChan()));
                Language lg = Translator.getLanguageFrom(chan);
                List<RSS> rssFeeds = allFeeds.get(Translator.getLanguageFrom(chan));
                long lastRSS = -1;
                for (RSS rss : rssFeeds) if (rss.getDate() > finder.getLastRSS()) {
                    Message.sendEmbed(chan, rss.getEmbedObject(lg));
                    lastRSS = rss.getDate();
                }
                if (lastRSS != -1)
                    finder.setLastRSS(lastRSS);
            } catch (Exception e) {
                LOG.error("RSSFinder", e);
            }
        }, 0, DELTA, TimeUnit.MINUTES);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) IChannel(sx.blah.discord.handle.obj.IChannel) RSS(data.RSS) Language(enums.Language) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) List(java.util.List) SQLException(java.sql.SQLException)

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