diff --git a/.gitignore b/.gitignore index 3f6e9d8..657d16c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Project exclude paths /.gradle/ /.idea/ -/.build/ \ No newline at end of file +/.build/ +/build/ \ No newline at end of file diff --git a/build.gradle b/build.gradle index 27fb756..1f213a1 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 compileJava.options.encoding 'UTF-8' group 'me.dkim19375' -version '2.2.5' +version '2.2.6' //noinspection GrUnresolvedAccess compileKotlin.kotlinOptions { diff --git a/src/main/java/me/dkim19375/dkim19375jdautils/data/Whitelist.kt b/src/main/java/me/dkim19375/dkim19375jdautils/data/Whitelist.kt new file mode 100644 index 0000000..6418d52 --- /dev/null +++ b/src/main/java/me/dkim19375/dkim19375jdautils/data/Whitelist.kt @@ -0,0 +1,43 @@ +package me.dkim19375.dkim19375jdautils.data + +import me.dkim19375.dkim19375jdautils.util.hasPermission +import net.dv8tion.jda.api.JDA +import net.dv8tion.jda.api.Permission +import net.dv8tion.jda.api.entities.GuildChannel +import net.dv8tion.jda.api.entities.Member +import net.dv8tion.jda.api.entities.User + +data class Whitelist( + val jda: JDA, + val permissions: Set = emptySet(), + val whitelist: Set? = null, + val blacklist: Set = emptySet(), + val ignoreWhitelist: Set = emptySet(), + val ignoreWhitelistBots: Boolean = true, + val ignoreWhitelistSelf: Boolean = true +) { + fun hasAccess( + user: User, + member: Member? = null, + channel: GuildChannel? = null + ): Boolean { + if (member != null) { + if (!member.hasPermission(permissions, channel)) { + return false + } + } + if ( + whitelist != null + && (!ignoreWhitelist.contains(user.idLong)) + && (!(user.isBot && ignoreWhitelistBots)) + && (user.idLong == jda.selfUser.idLong && !ignoreWhitelistSelf) + && (!whitelist.contains(user.idLong)) + ) { + return false + } + if (blacklist.contains(user.idLong)) { + return false + } + return true + } +} \ No newline at end of file