/** * Sets the system {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} of this {@link net.dv8tion.jda.core.entities.Guild Guild}. * * @param systemChannel * The new system channel for this {@link net.dv8tion.jda.core.entities.Guild Guild} * or {@code null} to reset * * @throws IllegalArgumentException * If the provided channel is not from this guild * * @return GuildManager for chaining convenience */ @CheckReturnValue public GuildManager setSystemChannel(TextChannel systemChannel) { Checks.check(systemChannel == null || systemChannel.getGuild().equals(getGuild()), "Channel must be from the same guild"); this.systemChannel = systemChannel == null ? null : systemChannel.getId(); set |= SYSTEM_CHANNEL; return this; }
/** * Sets the {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} of the selected {@link net.dv8tion.jda.core.entities.Webhook Webhook}. * * <p>A webhook channel <b>must not</b> be {@code null} and <b>must</b> be in the same {@link net.dv8tion.jda.core.entities.Guild Guild}! * * @param channel * The new {@link net.dv8tion.jda.core.entities.TextChannel TextChannel} * for the selected {@link net.dv8tion.jda.core.entities.Webhook Webhook} * * @throws net.dv8tion.jda.core.exceptions.InsufficientPermissionException * If the currently logged in account does not have the Permission {@link net.dv8tion.jda.core.Permission#MANAGE_WEBHOOKS MANAGE_WEBHOOKS} * in the specified TextChannel * @throws IllegalArgumentException * If the provided channel is {@code null} or from a different Guild * * @return WebhookManager for chaining convenience */ @CheckReturnValue public WebhookManager setChannel(TextChannel channel) { Checks.notNull(channel, "Channel"); Checks.check(channel.getGuild().equals(getGuild()), "Channel is not from the same guild"); this.channel = channel.getId(); set |= CHANNEL; return this; }
public static String listOfTChannels(List<TextChannel> list, String query) { String out = " Multiple text channels found matching \""+query+"\":"; for(int i=0; i<6 && i<list.size(); i++) out+="\n - "+list.get(i).getName()+" (<#"+list.get(i).getId()+">)"; if(list.size()>6) out+="\n**And "+(list.size()-6)+" more...**"; return out; }
/** * Sends a message to the provided {@link TextChannel} * * @param channel The channel to send the message * @param message The message that should be sent */ public void sendMessageToChannel(TextChannel channel, String message) { DiscordHandler.sendMessageToChannel(channel.getId(), message); }
/** * Sends a message to the provided {@link TextChannel} using a {@link WebhookContent} * * @param channel The channel to send the message * @param content The {@link WebhookContent} containing the avatar URL, webhook name and message */ public void sendMessageToChannel(TextChannel channel, WebhookContent content) { Webhooking.sendWebhook(channel.getId(), content); }
public static String buildChannelData(List<TextChannel> textChannels) { List<Map<String, Object>> channels = new ArrayList<>(); for (TextChannel channel : textChannels) { Map<String, Object> item = new HashMap<>(); item.put("id", channel.getId()); item.put("name", channel.getName()); item.put("position", channel.getPosition()); channels.add(item); } return AvaIre.gson.toJson(channels); }
private boolean isInPlayMode(User user, TextChannel channel) { return usersInPlayMode.containsKey(user.getIdLong()) && usersInPlayMode.get(user.getIdLong()).getChannelId().equals(channel.getId()); }
@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 ""; }
private void enterPlayMode(TextChannel channel, User player) { usersInPlayMode.put(player.getIdLong(), new PlayData(player.getId(), channel.getId())); }
public boolean createChannelTransformer(TextChannel channel) { return createChannelTransformer(channel.getGuild().getId(), channel.getId()); }
@Override public boolean onCommand(CommandMessage context, String[] args) { TextChannel channel = context.getChannel(); if (!context.getMentionedChannels().isEmpty()) { channel = context.getMentionedChannels().get(0); } context.makeSuccess(context.i18n("message")) .set("targetChannel", channel.getId()) .queue(); return true; } }
private void handleTextChannelDeleteReactionsRoles(TextChannelDeleteEvent event) { Collection collection = ReactionController.fetchReactions(avaire, event.getGuild()); if (collection == null) { return; } if (collection.where("channel_id", event.getChannel().getId()).isEmpty()) { return; } try { avaire.getDatabase().newQueryBuilder(Constants.REACTION_ROLES_TABLE_NAME) .where("channel_id", event.getChannel().getId()) .delete(); ReactionController.forgetCache(event.getGuild().getIdLong()); } catch (SQLException e) { log.error("Failed to delete reaction roles from {} for channel ID {}, error: {}", event.getGuild().getId(), event.getChannel().getId(), e.getMessage(), e ); } }
private static String parseChannel(TextChannel channel, String message) { message = StringReplacementUtil.replaceAll(message, ":channelname", channel.getName()); message = StringReplacementUtil.replaceAll(message, ":channelid", channel.getId()); message = StringReplacementUtil.replaceAll(message, ":channel", channel.getAsMention()); return message; }
private void handleTextChannelDeleteGuildSettings(TextChannelDeleteEvent event) { GuildTransformer transformer = GuildController.fetchGuild(avaire, event.getGuild()); if (transformer == null) { return; } if (transformer.getModlog() != null && transformer.getModlog().equalsIgnoreCase(event.getChannel().getId())) { setDatabaseColumnToNull(event.getGuild().getId(), "modlog"); } if (transformer.getLevelChannel() != null && transformer.getLevelChannel().equals(event.getChannel().getId())) { setDatabaseColumnToNull(event.getGuild().getId(), "level_channel"); } if (transformer.getMusicChannelText() != null && transformer.getMusicChannelText().equals(event.getChannel().getId())) { setDatabaseColumnToNull(event.getGuild().getId(), "music_channel_text"); } }
public void editBlocking(Message msg, String newContent) { if (!msg.getChannelType().equals(ChannelType.TEXT)) { return; } TextChannel channel = botInstance.getJda().getTextChannelById(msg.getTextChannel().getId()); if (channel == null) { return; } botInstance.queue.add(channel.editMessageById(msg.getId(), newContent)); }
@Override public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) { if (args.length == 1 && ARGS_PATTERN.matcher(args[0]).matches()) { if (args[0].equalsIgnoreCase("here")) { guild.setMusicAnnounceChannelId(channel.getId()); channel.sendMessage(MessageUtils.getEmbed(sender) .setDescription("Set music announcements to appear in " + channel .getAsMention()).build()).queue(); } else { guild.setMusicAnnounceChannelId(null); channel.sendMessage(MessageUtils.getEmbed(sender) .setDescription(String .format("Disabled announcements for `%s`", channel.getGuild() .getName())) .build()).queue(); } } else { MessageUtils.sendUsage(this, channel, sender, args); } }
@Override protected void execute(CommandEvent event) { if(event.getArgs().isEmpty()) { event.reply(event.getClient().getError()+" Please include a text channel or NONE"); return; } Settings s = event.getClient().getSettingsFor(event.getGuild()); if(event.getArgs().equalsIgnoreCase("none")) { s.setTextChannel(null); event.reply(event.getClient().getSuccess()+" Music commands can now be used in any channel"); } else { List<TextChannel> list = FinderUtil.findTextChannels(event.getArgs(), event.getGuild()); if(list.isEmpty()) event.reply(event.getClient().getWarning()+" No Text Channels found matching \""+event.getArgs()+"\""); else if (list.size()>1) event.reply(event.getClient().getWarning()+FormatUtil.listOfTChannels(list, event.getArgs())); else { s.setTextChannel(list.get(0)); event.reply(event.getClient().getSuccess()+" Music commands can now only be used in <#"+list.get(0).getId()+">"); } } }
private boolean displayCurrentChannels(CommandMessage context) { TextChannel textChannel = getTextChannel(context); VoiceChannel voiceChannel = getVoiceChannel(context); context.makeInfo(context.i18n("field.message")) .setTitle(context.i18n("field.title")) .set("text", textChannel == null ? "Disabled" : textChannel.getAsMention() + " (ID: " + textChannel.getId() + ")") .set("voice", voiceChannel == null ? "Disabled" : voiceChannel.getName() + " (ID: " + voiceChannel.getId() + ")") .queue(); return true; }
private void onMessageUpdate(MessageUpdateEvent event, @Nonnull GuildWrapper wrapper) { if (cannotHandle(wrapper, ModlogEvent.MESSAGE_EDIT)) return; if (event.getAuthor().isBot()) return; if (!RedisController.exists(event.getMessageId())) return; RedisMessage old = GeneralUtils.toRedisMessage(RedisController.get(event.getMessageId())); ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.MESSAGE_EDIT, event.getAuthor(), new MessageEmbed.Field("Old Message", FormatUtils.truncate(1024, old.getContent(), true), false), new MessageEmbed.Field("New Message", FormatUtils.truncate(1024, event.getMessage().getContentDisplay(), true), false), new MessageEmbed.Field("Channel", event.getTextChannel().getName() + " (" + event.getTextChannel().getId() + ")", true)); RedisController.set(event.getMessageId(), GeneralUtils.getRedisMessageJson(event.getMessage()), "xx", "ex", 61200); }