Skip to content

Commit

Permalink
update gitignore to add Whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
dkim19375 committed May 16, 2021
1 parent 6722229 commit a1752b0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Project exclude paths
/.gradle/
/.idea/
/.build/
/.build/
/build/
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/me/dkim19375/dkim19375jdautils/data/Whitelist.kt
Original file line number Diff line number Diff line change
@@ -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<Permission> = emptySet(),
val whitelist: Set<Long>? = null,
val blacklist: Set<Long> = emptySet(),
val ignoreWhitelist: Set<Long> = 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
}
}

0 comments on commit a1752b0

Please sign in to comment.