/** * Logs an action to the modlog channel for the given message. * * @param avaire The main AvaIre application instance. * @param message The message that triggered the modlog action. * @param action The action that should be logged to the modlog. * @return Possibly-null, the case ID if the modlog was logged successfully, * otherwise <code>null</code> will be returned. */ @Nullable public static String log(AvaIre avaire, Message message, ModlogAction action) { return log(avaire, message.getGuild(), action); }
private String asKey(Message message) { return message.getGuild().getId() + ":" + name; } }
private List<Role> getRoleRewards(Message message, GuildTransformer guild, long level) { List<Role> roles = new ArrayList<>(); for (Map.Entry<Integer, String> entry : guild.getLevelRoles().entrySet()) { if (entry.getKey() <= level) { Role role = message.getGuild().getRoleById(entry.getValue()); if (role != null) { roles.add(role); } } } return roles; }
/** * Gets the role from the mentioned roles list, if no roles was mentions * the role will be fetch from the guilds role list by name instead, * if no roles was found null is returned. * * @param message The JDA message object for the current guild. * @param roleName The name of the role that should be fetched if no role was mentioned. * @return Possibly-null, if a role was mentioned the role will be returned, otherwise the role will be fetched from the guilds role list. */ public static Role getRoleFromMentionsOrName(@Nonnull Message message, @Nonnull String roleName) { if (!message.getMentionedRoles().isEmpty()) { return message.getMentionedRoles().get(0); } List<Role> roles = message.getGuild().getRolesByName(roleName, true); return roles.isEmpty() ? null : roles.get(0); }
private String parseContent(String content) { String[] parts = content.split(" "); if (!isMentionableCommand()) { return String.join(" ", Arrays.copyOfRange(parts, 1, parts.length)); } int nameSize = (isGuildMessage() ? message.getGuild().getSelfMember().getEffectiveName() : message.getJDA().getSelfUser().getName() ).split(" ").length + 1; return String.join(" ", Arrays.copyOfRange(parts, nameSize, parts.length)); }
public CommandMessage(CommandContainer container, DatabaseEventHolder databaseEventHolder, Message message, boolean mentionableCommand, String[] aliasArguments) { if (container != null) { setI18nCommandPrefix(container); } this.message = message; this.guild = message.getGuild(); this.member = message.getMember(); this.channel = message.getTextChannel(); this.databaseEventHolder = databaseEventHolder; this.mentionableCommand = mentionableCommand; this.aliasArguments = aliasArguments.length == 0 ? null : String.join(" ", aliasArguments); }
/** * 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()); }
static String toGuild(Message message, String string) { if (!message.getChannelType().isGuild() || string == null) return string; return parseGuild(message.getGuild(), string); }
private VoiceConnectStatus canConnectToChannel(Message message, VoiceChannel channel) { List<Permission> permissions = message.getGuild().getMember(message.getJDA().getSelfUser()).getPermissions(channel); if (!permissions.contains(Permission.VOICE_CONNECT)) { return VoiceConnectStatus.MISSING_PERMISSIONS; } if (channel.getUserLimit() > 0 && !permissions.contains(Permission.VOICE_MOVE_OTHERS) && channel.getUserLimit() <= channel.getMembers().size()) { return VoiceConnectStatus.USER_LIMIT; } return null; }
/** * 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); }
public void setLastNPMessage(Message m) { lastNP.put(m.getGuild().getIdLong(), new Pair<>(m.getTextChannel().getIdLong(), m.getIdLong())); }
public static void deleteMessage(@Nonnull Message message, int delay, TimeUnit timeUnit) { if (message.getJDA().getSelfUser().getId().equals(message.getAuthor().getId())) { handleDeleteMessage(message, delay, timeUnit); } else if (message.getGuild() != null && message.getGuild().getSelfMember().hasPermission(message.getTextChannel(), Permission.MESSAGE_MANAGE)) { handleDeleteMessage(message, delay, timeUnit); } }
/** * 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())); }
@Override public boolean canTalk() { if (!isGuildMessage()) { return true; } return message.getGuild().getSelfMember().hasPermission(message.getTextChannel(), Permission.MESSAGE_WRITE, Permission.MESSAGE_READ, Permission.MESSAGE_EMBED_LINKS ); }
@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; } }); }
public String getPrefix(@Nonnull Message message) { if (isGlobal) { return getPrefix(); } if (message.getGuild() == null) { return getPrefix(); } return (String) CacheUtil.getUncheckedUnwrapped(cache, asKey(message), () -> { GuildTransformer transformer = GuildController.fetchGuild(avaire, message); return transformer == null ? getPrefix() : transformer.getPrefixes().getOrDefault( getName().toLowerCase(), getPrefix() ); }); }
private void updateGuildCategories(Message context, GuildTransformer transformer) throws SQLException { avaire.getDatabase().newQueryBuilder(Constants.GUILD_TABLE_NAME) .where("id", context.getGuild().getId()) .update(statement -> { statement.set("modules", AvaIre.gson.toJson(transformer.getCategories())); }); }
public void addReaction(Message message) { if (!(message.getChannel().getType() == ChannelType.TEXT && message.getGuild().getSelfMember() .hasPermission(message.getTextChannel(), Permission.MESSAGE_HISTORY))) { message.getChannel().sendMessage("I can't add buttons due to not having the `Message History` permission!").queue(); return; } this.message = message; if (unicode != null) message.addReaction(unicode).queue(); else { try { message.addReaction(Getters.getEmoteById(emoteId)).queue(); } catch (IllegalArgumentException ignored) {} } }