switch (message.getChannelType())
switch (message.getChannelType())
@Override public boolean isGuildMessage() { return message.getChannelType().isGuild(); }
@Override public boolean handle(@Nonnull Message message, @Nonnull MiddlewareStack stack, String... args) { return !message.getChannelType().isGuild() && stack.next(); } }
/** * 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()); }
/** * 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()); }
static String toGuild(Message message, String string) { if (!message.getChannelType().isGuild() || string == null) return string; return parseGuild(message.getGuild(), string); }
/** * Converts the message object to a guild object and parses the guild * and string to the {@link #parseGuild(Guild, String)} method. * * @param message The message that the guild should be retrieved from. * @param string The original string that should be parsed. * @return The parsed string if the given message contains a valid guild instance, * otherwise it will just return the original unchanged string. */ private static String toGuild(Message message, String string) { if (!message.getChannelType().isGuild()) { return string; } return parseGuild(message.getGuild(), string); }
private String generateServer(Message message) { if (!message.getChannelType().isGuild()) { return "PRIVATE"; } return String.format(propertyOutput, message.getGuild().getName(), message.getGuild().getId() ); }
private CharSequence generateChannel(Message message) { if (!message.getChannelType().isGuild()) { return "PRIVATE"; } return String.format(propertyOutput, message.getChannel().getName(), message.getChannel().getId() ); }
private String generateServer(Message message) { if (!message.getChannelType().isGuild()) { return ConsoleColor.GREEN + "PRIVATE"; } return String.format(propertyOutput, message.getGuild().getName(), message.getGuild().getId() ); }
private CharSequence generateChannel(Message message) { if (!message.getChannelType().isGuild()) { return ConsoleColor.GREEN + "PRIVATE"; } return String.format(propertyOutput, message.getChannel().getName(), message.getChannel().getId() ); }
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); } }
/** * Checks if the author of the message, of the message was * sent in a guild, that the guild is on the blacklist. * * @param message The message that should be checked. * @return <code>True</code> if either the user, or the entire * server is blacklisted, <code>False</code> otherwise. */ public boolean isBlacklisted(@Nonnull Message message) { return isBlacklisted(message.getAuthor()) || (message.getChannelType().isGuild() && isBlacklisted(message.getGuild())); }
private boolean isServerVIP(MiddlewareStack stack, Message message) { if (!message.getChannelType().isGuild()) { return false; } GuildTransformer transformer = stack.getDatabaseEventHolder().getGuild(); return transformer != null && !transformer.getType().isDefault(); } }
@Override public boolean handle(@Nonnull Message message, @Nonnull MiddlewareStack stack, String... args) { if (!message.getChannelType().isGuild()) { return stack.next(); } if (args.length > 0) { DJGuildLevel level = DJGuildLevel.fromName(args[0]); if (level != null && AudioHandler.getDefaultAudioHandler().canRunDJAction(avaire, message, level)) { return stack.next(); } return sendErrorMessage(message, stack); } if (AudioHandler.getDefaultAudioHandler().canRunDJAction(avaire, message, DJGuildLevel.NORMAL)) { return stack.next(); } return sendErrorMessage(message, stack); }
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)); }
@CheckReturnValue public static Collection fetchPlaylists(AvaIre avaire, Message message) { if (!message.getChannelType().isGuild()) { return null; } return (Collection) CacheUtil.getUncheckedUnwrapped(cache, message.getGuild().getIdLong(), () -> { try { return avaire.getDatabase().newQueryBuilder(Constants.MUSIC_PLAYLIST_TABLE_NAME) .selectAll().where("guild_id", message.getGuild().getId()) .get(); } catch (Exception e) { AvaIre.getLogger().error("Failed to fetch playlists for server " + message.getGuild().getId(), e); return null; } }); }
private void sendTagInformationMessage(MessageReceivedEvent event) { String author = "**Senither#0001**"; if (event.getMessage().getChannelType().isGuild() && event.getGuild().getMemberById(88739639380172800L) != null) { author = "<@88739639380172800>"; } MessageFactory.makeEmbeddedMessage(event.getMessage().getChannel(), Color.decode("#E91E63"), String.format(mentionMessage, avaire.getSelfUser().getName(), author, CommandHandler.getLazyCommand("help").getCommand().generateCommandTrigger(event.getMessage()), AppInfo.getAppInfo().version )) .setFooter("This message will be automatically deleted in one minute.") .queue(message -> message.delete().queueAfter(1, TimeUnit.MINUTES, null, RestActionUtil.ignore)); }
@Override public void onIntent(CommandMessage context, AIResponse response) { String nickname = context.getAuthor().getName(); if (context.getMessage().getChannelType().isGuild()) { nickname = context.getMember().getEffectiveName(); } context.makeInfo(StringReplacementUtil.replaceAll( response.getResult().getFulfillment().getSpeech(), "%nick%", nickname )).queue(); } }