public TextChannel getTextChannel(Guild guild) { return guild == null ? null : guild.getTextChannelById(textId); }
public TextChannel getModlogChannel(Guild guild) { return guild.getTextChannelById(modlogChannelId); } }
? guild.getTextChannelById(this.channel.getIdLong()) : guild.getVoiceChannelById(this.channel.getIdLong());
@Override public String toDisplay(Guild guild, String value) { if (value == null || value.isEmpty() || !value.matches("\\d{10,}")) { return Emojibet.X; } TextChannel channel = guild.getTextChannelById(value); if (channel != null) { return channel.getName(); } return Emojibet.X; } }
/** * Check if the passed channel ID is a "valid", this means that the channel ID belongs to that guild and that it * still is a valid channel. * * @param wrapper GuildWrapper that needs to be checked * @param channelId The channel ID that should belong to that guild. * @return If the channel ID is valid and belongs to the associated Guild. */ private boolean isValidChannelId(GuildWrapper wrapper, long channelId) { return wrapper.getGuild().getTextChannelById(channelId) != null; }
@Override public boolean validate(Guild guild, String value) { if (allowNull && (value == null || value.isEmpty() || value.equalsIgnoreCase("false"))) { return true; } if (DisUtil.isChannelMention(value)) { return guild.getTextChannelById(DisUtil.mentionToId(value)) != null; } return DisUtil.findChannel(guild, value) != null; }
public void reportError(String message) { DiscordBot shard = getShardFor(BotConfig.BOT_GUILD_ID); Guild guild = shard.getJda().getGuildById(BotConfig.BOT_GUILD_ID); if (guild == null) { LOGGER.warn("Can't find BOT_GUILD_ID " + BotConfig.BOT_GUILD_ID); return; } TextChannel channel = guild.getTextChannelById(BotConfig.BOT_ERROR_CHANNEL_ID); if (channel == null) { LOGGER.warn("Can't find BOT_ERROR_CHANNEL_ID " + BotConfig.BOT_ERROR_CHANNEL_ID); return; } shard.queue.add(channel.sendMessage(message.length() > BotConfig.MAX_MESSAGE_SIZE ? message.substring(0, BotConfig.MAX_MESSAGE_SIZE - 1) : message)); }
private String getBlacklistedChannels(GuildWrapper wrapper) { if (wrapper.getSettings().getChannelBlacklist().isEmpty()) return "No blacklisted channels!"; return wrapper.getSettings().getChannelBlacklist().stream().map(channelId -> { TextChannel tc = wrapper.getGuild().getTextChannelById(channelId); if (tc == null) { wrapper.getSettings().getChannelBlacklist().remove(channelId); return ""; } return tc.getAsMention(); }).collect(Collectors.joining(", ")); }
/** * Gets a {@link TextChannel} from a string. Not case sensitive. * The string can eater be the channel name, it's id, or it being mentioned. * * @param channelArg The string to get the channel from * @param wrapper The Guild wrapper for the {@link Guild} that you want to get the channel from * @return null if the channel couldn't be found otherwise a {@link TextChannel} */ public static TextChannel getChannel(String channelArg, GuildWrapper wrapper) { try { long channelId = Long.parseLong(channelArg.replaceAll("[^0-9]", "")); return wrapper != null ? wrapper.getGuild().getTextChannelById(channelId) : Getters.getChannelById(channelId); } catch (NumberFormatException e) { if (wrapper != null) { List<TextChannel> tcs = wrapper.getGuild().getTextChannelsByName(channelArg, true); if (!tcs.isEmpty()) { return tcs.get(0); } } return null; } }
private TextChannel getTextChannel(CommandMessage context) { String channel = context.getGuildTransformer().getMusicChannelText(); if (channel == null) { return null; } return context.getGuild().getTextChannelById(channel); }
@Override public String fromInput(Guild guild, String value) { if (allowNull && (value == null || value.isEmpty() || value.equalsIgnoreCase("false"))) { return ""; } if (DisUtil.isChannelMention(value)) { TextChannel textChannel = guild.getTextChannelById(DisUtil.mentionToId(value)); if (textChannel != null) { return textChannel.getId(); } } TextChannel channel = DisUtil.findChannel(guild, value); if (channel != null) { return channel.getId(); } return ""; }
/** * retrieves a channel for setting * * @param guildId the guild * @param setting the channel setting * @return A text channel Or null in case it can't be found */ private synchronized TextChannel getChannelFor(long guildId, GSetting setting) { Guild guild = getJda().getGuildById(guildId); if (guild == null) { return null; } String channelId = GuildSettings.get(guild.getIdLong()).getOrDefault(setting); if (channelId.matches("\\d{12,}")) { return guild.getTextChannelById(channelId); } else if (!channelId.isEmpty() && !"false".equals(channelId)) { return DisUtil.findChannel(guild, channelId); } return null; }
private void updateText(TextChannel channel, OReactionRoleKey key) { if (key.messageId > 0 && key.channelId > 0) { TextChannel tchan = channel.getGuild().getTextChannelById(key.channelId); if (tchan != null && tchan.canTalk()) { tchan.editMessageById(String.valueOf(key.messageId), buildMessage(channel, key, CReactionRole.getReactionsForKey(key.id))).queue(); } } }
/** * Gets the level up channel from the current message event and guild * transformer, if no valid level up channel is set for the given * guild, the message text chanel will be returned instead. * * @param message The message event that should be used as a default. * @param guild The guild transformer that should be used to get the level up channel. * @return The level up channel if one is set, otherwise the text channel from the message object. */ private TextChannel getLevelUpChannel(Message message, GuildTransformer guild) { String levelChannel = guild.getLevelChannel(); if (levelChannel == null) { return message.getTextChannel(); } TextChannel channel = message.getGuild().getTextChannelById(levelChannel); return channel == null ? message.getTextChannel() : channel; }
public void reportStatus(int shardId, JDA.Status oldStatus, JDA.Status status) { DiscordBot shard = getShardFor(BotConfig.BOT_GUILD_ID); if (shard == null || shard.getJda() == null) { return; } Guild guild = shard.getJda().getGuildById(BotConfig.BOT_GUILD_ID); if (guild == null) { LOGGER.warn("Can't find BOT_GUILD_ID " + BotConfig.BOT_GUILD_ID); return; } TextChannel channel = guild.getTextChannelById(BotConfig.BOT_STATUS_CHANNEL_ID); if (channel == null) { LOGGER.warn("Can't find BOT_STATUS_CHANNEL_ID " + BotConfig.BOT_STATUS_CHANNEL_ID); return; } if (channel.getJDA().getStatus() == JDA.Status.CONNECTED) { int length = 1 + (int) Math.floor(Math.log10(shards.length)); shard.queue.add(channel.sendMessage( String.format(Emojibet.SHARD_ICON + " `%0" + length + "d/%0" + length + "d` | ~~%s~~ -> %s", shardId, shards.length, oldStatus.toString(), status.toString()))); } }
/** * This will get the TextChannel of a certain event, this could also return null in two cases.<br> * <ol> * <li>They don't have a channel set for the event</li> * <li>The channel set is in another guild.</li> * </ol> * * @param wrapper GuildWrapper of the desired guild to check. * @param event The event to check. * @return The TextChannel of the desired event in the desired guild or null in the two cases listed above. */ public TextChannel getModlogChannel(GuildWrapper wrapper, ModlogEvent event) { for (ModlogAction modlogAction : wrapper.getModConfig().getEnabledActions()) if (modlogAction.getEvent() == event) return wrapper.getGuild().getTextChannelById(modlogAction.getModlogChannelId()); return null; }
private boolean sendDisabledChannels(CommandMessage context, GuildTransformer guildTransformer) { if (guildTransformer.getLevelExemptChannels().isEmpty()) { return sendErrorMessage(context, context.i18n("noChannelsWithRewardsDisabled"), generateCommandTrigger(context.getMessage()) ); } List<String> channels = new ArrayList<>(); for (Long channelId : guildTransformer.getLevelExemptChannels()) { TextChannel textChannel = context.getGuild().getTextChannelById(channelId); if (textChannel != null) { channels.add(textChannel.getAsMention()); } } context.makeInfo(context.i18n("listChannels")) .set("channels", String.join(", ", channels)) .setTitle(context.i18n("listChannelsTitle", guildTransformer.getLevelExemptChannels().size() )) .queue(); return true; }
private PlaceholderMessage sendModlogChannel(CommandMessage context, GuildTransformer transformer) { if (transformer.getModlog() == null) { return context.makeWarning(context.i18n("disabled")); } TextChannel modlogChannel = context.getGuild().getTextChannelById(transformer.getModlog()); if (modlogChannel == null) { try { updateModlog(transformer, context, null); } catch (SQLException ex) { AvaIre.getLogger().error(ex.getMessage(), ex); } return context.makeInfo(context.i18n("disabled")); } return context.makeSuccess(context.i18n("enabled")) .set("modlog", modlogChannel.getAsMention()); }
private String editReason(DiscordBot bot, Guild guild, Member moderator, MessageChannel feedbackChannel, String caseId, String reason) { OModerationCase oCase; if (caseId.equalsIgnoreCase("last")) { oCase = CModerationCase.findLastFor(CGuild.getCachedId(guild.getIdLong()), CUser.getCachedId(moderator.getUser().getIdLong())); } else { oCase = CModerationCase.findById(Misc.parseInt(caseId, -1)); } if (oCase.id == 0 || oCase.guildId != CGuild.getCachedId(guild.getIdLong())) { return Templates.command.case_not_found.formatGuild(guild.getIdLong(), oCase.id); } oCase.reason = reason; CModerationCase.update(oCase); TextChannel channel = guild.getTextChannelById(GuildSettings.get(guild).getOrDefault(GSetting.BOT_CHANNEL)); if (channel == null) { return Templates.config.modlog_not_found.formatGuild(guild.getIdLong()); } bot.queue.add(channel.getMessageById(oCase.messageId), msg -> { if (msg != null) { bot.queue.add(msg.editMessage(new MessageBuilder().setEmbed(CModerationCase.buildCase(guild, oCase)).build())); } else { bot.queue.add(feedbackChannel.sendMessage(Templates.command.case_reason_modified.formatGuild(channel))); } }); return ""; } }
private void displayMessage(DiscordBot bot, TextChannel channel, OReactionRoleKey key) { if (key.channelId > 0 && key.messageId > 0) { TextChannel tchan = channel.getGuild().getTextChannelById(key.channelId); if (tchan != null && tchan.canTalk()) { tchan.deleteMessageById(key.messageId).queue(); } } List<OReactionRoleMessage> reactions = CReactionRole.getReactionsForKey(key.id); channel.sendMessage(buildMessage(channel, key, reactions)).queue(message -> { key.messageId = message.getIdLong(); key.channelId = channel.getIdLong(); CReactionRole.update(key); bot.roleReactionHandler.initGuild(message.getGuild().getIdLong(), true); for (OReactionRoleMessage reaction : reactions) { if (reaction.isNormalEmote) { message.addReaction(reaction.emoji).queue(); } else { message.addReaction(message.getJDA().getEmoteById(reaction.emoji)).queue(); } } }); } }