@Override default void formatTo(Formatter formatter, int flags, int width, int precision) { boolean leftJustified = (flags & FormattableFlags.LEFT_JUSTIFY) == FormattableFlags.LEFT_JUSTIFY; boolean upper = (flags & FormattableFlags.UPPERCASE) == FormattableFlags.UPPERCASE; boolean alt = (flags & FormattableFlags.ALTERNATE) == FormattableFlags.ALTERNATE; String out; if (alt) out = "#" + (upper ? getName().toUpperCase(formatter.locale()) : getName()); else out = getAsMention(); MiscUtil.appendTo(formatter, width, precision, leftJustified, out); } }
tmp = tmp.replace(mentionedChannel.getAsMention(), '#' + mentionedChannel.getName());
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(", ")); }
.replace("%channel%", (guild == null) ? "Private" : channel.getName()) .replace("%channel-id%", (guild == null) ? "0" : channel.getId()) .replace("%channel-mention%", (guild == null) ? "Private" : ((TextChannel) channel).getAsMention()); if (guild == null) { return output.replace("\u0013", "%");
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 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 boolean sendChannelStatus(CommandMessage context, TextChannel textChannel) { context.makeInfo(context.i18n("message")) .set("textChannel", textChannel.getAsMention()) .set("status", context.i18n("status." + (textChannel.isNSFW() ? "enabled" : "disabled"))) .queue(); return false; } }
private boolean updateChannelStatus(CommandMessage context, TextChannel textChannel, boolean status) { textChannel.getManager().setNSFW(status).queue(aVoid -> { context.makeSuccess(context.i18n("updated")) .set("textChannel", textChannel.getAsMention()) .set("status", context.i18n("status." + (status ? "enabled" : "disabled"))) .queue(); }, throwable -> { context.makeError("Something went wrong while trying to update the channel status: " + throwable.getLocalizedMessage()) .queue(); }); return true; }
@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); } }
tc.getGuild().getOwner().getUser().openPrivateChannel().queue(pc -> { pc.sendMessage("Please give me permission to read message, write messages and embed links in the modlog channel: " + tc.getAsMention() + " or set the modlog channel to one I have access to!").queue(); });
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()); }
ModlogType.PURGE, context.getAuthor(), null, context.i18n("messagesDeletedIn", messages.size(), context.getChannel().getAsMention()) messages.size(), String.join(", ", users), context.getChannel().getAsMention()
.set("channel", channel.getAsMention()) .set("status", context.i18n(isEnabled ? "status.enabled" : "status.disabled")) .queue();
.set("textChannel", channel.getAsMention()) .queue(); .set("textChannel", channel.getAsMention()) .set("slowmode", slowmode) .queue(); .set("textChannel", channel.getAsMention()) .set("slowmode", slowmode) .queue(); }, error -> { context.makeError(context.i18n("failedToUpdate")) .set("textChannel", channel.getAsMention()) .set("message", error.getMessage()) .queue();
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; }
@Override public boolean onCommand(CommandMessage context, String[] args) { GuildTransformer transformer = context.getGuildTransformer(); if (transformer == null) { return sendErrorMessage(context, "errors.errorOccurredWhileLoading", "server settings"); } if (args.length == 0) { sendModlogChannel(context, transformer).queue(); return true; } if (ComparatorUtil.isFuzzyFalse(args[0])) { return disableModlog(context, transformer); } Channel channel = MentionableUtil.getChannel(context.getMessage(), args); if (channel == null || !(channel instanceof TextChannel)) { return sendErrorMessage(context, context.i18n("mustMentionTextChannel")); } if (!((TextChannel) channel).canTalk() || !context.getGuild().getSelfMember().hasPermission(channel, Permission.MESSAGE_EMBED_LINKS)) { return sendErrorMessage(context, context.i18n("cantSendEmbedMessages", ((TextChannel) channel).getAsMention())); } try { updateModlog(transformer, context, channel.getId()); context.makeSuccess(context.i18n("enable")) .set("modlog", ((TextChannel) channel).getAsMention()) .queue(); } catch (SQLException ex) { AvaIre.getLogger().error(ex.getMessage(), ex); } return true; }
private void updateDatabase(CommandMessage context, Type type, Channel value) { try { avaire.getDatabase().newQueryBuilder(Constants.GUILD_TABLE_NAME) .useAsync(true) .where("id", context.getGuild().getId()) .update(statement -> statement.set(type.getField(), value == null ? null : value.getId())); String status = null; if (value != null) { status = (value instanceof TextChannel) ? ((TextChannel) value).getAsMention() : value.getName(); } context.makeSuccess(context.i18n("updated")) .set("type", type.name().toLowerCase()) .set("status", value == null ? context.i18n("status.disabled") : context.i18n("status.enabled", status) ) .queue(); } catch (SQLException ignored) { // Since we're running the query as async we won't really need to // check for errors since that is handled by the database thread. } }
"music.internal.musicChannel", "You can only use music commands in the :channel channel." )).set("channel", textChannelById.getAsMention()).queue( musicMessage -> musicMessage.delete().queueAfter(30, TimeUnit.SECONDS, null, RestActionUtil.ignore), RestActionUtil.ignore
@Override @SuppressWarnings("ConstantConditions") public boolean onCommand(CommandMessage context, String[] args) { GuildTransformer guildTransformer = context.getGuildTransformer(); if (guildTransformer == null || !guildTransformer.isLevels()) { return sendErrorMessage( context, "errors.requireLevelFeatureToBeEnabled", CommandHandler.getCommand(LevelCommand.class) .getCommand().generateCommandTrigger(context.getMessage()) ); } if (args.length == 0 || NumberUtil.parseInt(args[0], -1) > 0) { return sendDisabledChannels(context, guildTransformer); } Channel channel = MentionableUtil.getChannel(context.getMessage(), args); if (channel == null || !(channel instanceof TextChannel)) { return sendErrorMessage(context, context.i18n("invalidChannel")); } TextChannel textChannel = (TextChannel) channel; if (!textChannel.canTalk()) { return sendErrorMessage(context, context.i18n("cantTalkInChannel", textChannel.getAsMention() )); } if (args.length > 1) { return handleToggleChannel(context, textChannel, ComparatorUtil.getFuzzyType(args[1])); } return handleToggleChannel(context, textChannel, ComparatorUtil.ComparatorType.UNKNOWN); }
event.replyInDm(event.getClient().getError()+" You can only use that command in "+tchannel.getAsMention()+"!"); return;