@Override public String toJSONString() { final JSONObject o = new JSONObject(); o.put("name", name); o.put("type", type.getId()); if (topic != null) o.put("topic", topic); if (nsfw != null) o.put("nsfw", nsfw); if (bitrate != null) o.put("bitrate", bitrate); if (userlimit != null) o.put("user_limit", userlimit); if (position != null) o.put("position", position); if (!overrides.isEmpty()) o.put("permission_overwrites", overrides); return o.toString(); } }
@Override public boolean isGuildMessage() { return message.getChannelType().isGuild(); }
public void addReactionListener(long guildId, Message message, CommandReactionListener<?> handler) { if (handler == null) { return; } if (message.getChannelType().equals(ChannelType.TEXT)) { if (!PermissionUtil.checkPermission(message.getTextChannel(), message.getGuild().getSelfMember(), Permission.MESSAGE_ADD_REACTION)) { return; } } if (!reactions.containsKey(guildId)) { reactions.put(guildId, new ConcurrentHashMap<>()); } if (!reactions.get(guildId).containsKey(message.getIdLong())) { for (String emote : handler.getEmotes()) { message.addReaction(emote).complete(); } reactions.get(guildId).put(message.getIdLong(), handler); } }
static String parse(PlaceholderType type, Object object, String message) { switch (type) { case ALL: if (object instanceof Message && ((Message) object).getChannelType().isGuild()) { Message jdaMessage = (Message) object; if (object instanceof Message && ((Message) object).getChannelType().isGuild()) { return parseGuild(((Message) object).getGuild(), message); if (object instanceof Message && ((Message) object).getChannelType().equals(ChannelType.TEXT)) { return parseChannel(((Message) object).getTextChannel(), message);
private void handleChannelCreate(GuildWrapper wrapper, Channel channel) { if (cannotHandle(wrapper, ModlogEvent.CHANNEL_CREATE)) return; AuditLogEntry entry = wrapper.getGuild().getAuditLogs().complete().get(0); EmbedBuilder builder = new EmbedBuilder() .addField("Type", channel.getType().name().toLowerCase(), true) .addField("Name", channel.getName(), true); if (channel.getParent() != null) { builder.addField("Category", channel.getParent().getName(), true); } ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.CHANNEL_CREATE, entry.getUser(), builder); }
private void createGuildChannel(GuildImpl guildObj, JSONObject channelData) { final ChannelType channelType = ChannelType.fromId(channelData.getInt("type")); switch (channelType) { case TEXT: createTextChannel(guildObj, channelData, guildObj.getIdLong()); break; case VOICE: createVoiceChannel(guildObj, channelData, guildObj.getIdLong()); break; case CATEGORY: createCategory(guildObj, channelData, guildObj.getIdLong()); break; default: throw new IllegalArgumentException("Cannot create channel for type " + channelData.getInt("type")); } }
/** * Static accessor for retrieving a channel type based on its Discord id key. * * @param id * The id key of the requested channel type. * * @return The ChannelType that is referred to by the provided key. If the id key is unknown, {@link #UNKNOWN} is returned. */ public static ChannelType fromId(int id) { for (ChannelType type : values()) { if (type.id == id) return type; } return UNKNOWN; } }
@Override public boolean handle(@Nonnull Message message, @Nonnull MiddlewareStack stack, String... args) { return !message.getChannelType().isGuild() && stack.next(); } }
public String formatGuild(MessageChannel channel, Object... vars) { if (channel.getType().equals(ChannelType.TEXT)) { return formatFull(((TextChannel) channel).getGuild().getIdLong(), false, vars); } return formatFull(0, false, vars); }
private void handleChannelDelete(GuildWrapper wrapper, Channel channel) { if (wrapper == null) return; if (cannotHandle(wrapper, ModlogEvent.CHANNEL_DELETE)) return; AuditLogEntry entry = wrapper.getGuild().getAuditLogs().complete().get(0); EmbedBuilder builder = new EmbedBuilder() .addField("Type", channel.getType().name().toLowerCase(), true) .addField("Name", channel.getName(), true); if (channel.getParent() != null) { builder.addField("Category", channel.getParent().getName(), true); } ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.CHANNEL_DELETE, entry.getUser(), builder); }
ChannelType type = ChannelType.fromId(chan.getInt("type"));
/** * Fetches the guild transformer from the cache, if it doesn't exist in the * cache it will be loaded into the cache and then returned afterwords. * * @param avaire The avaire instance, used to talking to the database. * @param message The JDA message instance for the current message. * @return Possibly null, the guild transformer instance for the current guild, or null. */ @CheckReturnValue public static GuildTransformer fetchGuild(AvaIre avaire, Message message) { if (!message.getChannelType().isGuild()) { return null; } return fetchGuild(avaire, message.getGuild()); }
if (channel.getType().equals(ChannelType.TEXT) && !PermissionUtil.checkPermission((TextChannel) channel, ((TextChannel) channel).getGuild().getSelfMember(), Permission.MESSAGE_ATTACH_FILES)) { return Templates.permission_missing.formatGuild(channel, "MESSAGE_ATTACH_FILES");
@Override protected Long handleInternally(JSONObject content) ChannelType type = ChannelType.fromId(content.getInt("type")); if (type == ChannelType.GROUP)
@Override protected RequestBody finalizeData() { JSONObject object = new JSONObject(); object.put("name", name); object.put("type", type.getId()); object.put("permission_overwrites", new JSONArray(overrides)); switch (type) { case VOICE: if (bitrate != null) object.put("bitrate", bitrate.intValue()); if (userlimit != null) object.put("user_limit", userlimit.intValue()); break; case TEXT: if (topic != null && !topic.isEmpty()) object.put("topic", topic); if (nsfw != null) object.put("nsfw", nsfw); if (slowmode != null) object.put("rate_limit_per_user", slowmode); } if (type != ChannelType.CATEGORY && parent != null) object.put("parent_id", parent.getId()); return getRequestBody(object); }
/** * Fetches a collection of reaction roles/messages for the server the message was * sent in, if the server doesn't have any reaction roles an empty collection * will be returned instead, if the message was not sent in a server then * {@code NULL} will be returned. * * @param avaire The avaire instance, used to talking to the database. * @param message The JDA message instance for the current message. * @return Possibly null, the reaction collections for the current guild, or null. */ @CheckReturnValue public static Collection fetchReactions(AvaIre avaire, Message message) { if (!message.getChannelType().isGuild()) { return null; } return fetchReactions(avaire, message.getGuild()); }
@Override public boolean onCommand(CommandMessage context, String[] args) { if (args.length == 0) { return sendErrorMessage(context, context.i18n("missingArgument")); } Channel channel = MentionableUtil.getChannel(context.getMessage(), args); if (channel == null) { return handleSlowmode(context, context.getChannel(), args); } if (!channel.getType().equals(ChannelType.TEXT)) { return sendErrorMessage(context, "invalidTextChannel", channel.getName()); } return handleSlowmode(context, (TextChannel) channel, Arrays.copyOfRange(args, 1, args.length)); }