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());
}
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());
}
}
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;
}
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;
}
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);
}
}
Aggregations