@@ -82,9 +82,9 @@ class RoleSelector: Extension() {
8282 rsl[" name" ] as String ,
8383 rsl[" channel" ] as Long ,
8484 rsl[" autoRemoveOnLimit" , false ] as Boolean ,
85- rsl.getOrDefault( " attachment" , " " ) as String ,
86- ( rsl.getOrDefault( " limit" , - 1 ) as Long ).toInt() ,
87- rsl.getOrDefault( " removable" , true ) as Boolean ,
85+ rsl[ " attachment" , " " ] as String ,
86+ rsl[ " limit" , - 1 ] as Long ,
87+ rsl[ " removable" , true ] as Boolean ,
8888 rsl[" role" ] as TomlArray ?
8989 )
9090 }
@@ -143,13 +143,13 @@ class RoleSelector: Extension() {
143143 }
144144
145145 private suspend fun roleLimitCheck (
146- limit : Int ,
146+ limit : Long ,
147147 autoRemoveOnLimit : Boolean ,
148148 member : MemberBehavior ,
149149 selectorRoles : List <RoleBehavior >,
150150 context : PublicInteractionButtonContext ,
151151 ): String? {
152- if (limit == - 1 ) return " "
152+ if (limit == - 1L ) return " "
153153 val conflictingRoles = member.asMember().roles.filter(selectorRoles::contains)
154154 if (conflictingRoles.count() < limit) return " "
155155 return if (autoRemoveOnLimit) {
@@ -167,11 +167,12 @@ class RoleSelector: Extension() {
167167 }
168168
169169 private suspend fun roleIncompatibleWithCheck (
170- incompatibleWith : Collection <RoleBehavior >,
170+ incompatibleWith : Collection <RoleBehavior >? ,
171171 roleBehavior : RoleBehavior ,
172172 member : MemberBehavior ,
173173 context : PublicInteractionButtonContext ,
174174 ): String? {
175+ incompatibleWith ? : return " "
175176 val incompatible = member.asMember().getAnyRole(incompatibleWith)
176177 return if (incompatible != null ) {
177178 context.interactionResponse.followUpEphemeral {
@@ -205,7 +206,7 @@ class RoleSelector: Extension() {
205206 channel : Long ,
206207 autoRemoveOnLimit : Boolean ,
207208 attachment : String ,
208- limit : Int ,
209+ limit : Long ,
209210 removable : Boolean ,
210211 roles : TomlArray ? ,
211212 ) {
@@ -219,12 +220,17 @@ class RoleSelector: Extension() {
219220 val selectorRoles = roles.map { RoleBehavior (GUILD_ID , Snowflake ((it as TomlTable )[" roleId" ] as Long ), kord) }
220221
221222 for (role in roles.asList() as List <TomlTable >) {
222- val roleBehavior = selectorRoles.first { it.id.value.toLong() == role[" roleId" ] as Long }
223+ val roleName: String = role[" name" ] as String
224+ val roleEmoji: String? = role[" emoji" ] as ? String
225+ val roleRoleId: Long = role[" roleId" ] as Long
226+ val roleRequiredRoleId: Long? = role[" requiredRoleId" ] as ? Long
227+ val roleIncompatibleWith: TomlArray ? = role[" incompatibleWith" ] as ? TomlArray
228+ val roleBehavior = selectorRoles.first { it.id.value.toLong() == roleRoleId }
223229
224230 publicButton {
225- label = role[ " name " ] as String
226- if ((role[ " emoji " ] as String ).isNotEmpty ()) {
227- val emoji = (role[ " emoji " ] as String ) .split(' :' , limit = 3 )
231+ label = roleName
232+ if (! roleEmoji.isNullOrBlank ()) {
233+ val emoji = roleEmoji .split(' :' , limit = 3 )
228234
229235 partialEmoji = DiscordPartialEmoji .dsl {
230236 id = Snowflake (emoji[0 ])
@@ -234,7 +240,7 @@ class RoleSelector: Extension() {
234240 }
235241 style = ButtonStyle .Secondary
236242
237- val incompatibleWith = (role[ " incompatibleWith " ] as TomlArray ) .map {
243+ val incompatibleWith = roleIncompatibleWith? .map {
238244 RoleBehavior (GUILD_ID , Snowflake (it.toString()), kord)
239245 }
240246
@@ -264,7 +270,7 @@ class RoleSelector: Extension() {
264270 ) ? : return @action
265271
266272 requiredRoleCheck(
267- role[ " requiredRoleId " ] as ? Long ,
273+ roleRequiredRoleId ,
268274 member,
269275 this
270276 ) ? : return @action
@@ -278,15 +284,6 @@ class RoleSelector: Extension() {
278284 }
279285}
280286
281- fun Member.hasAnyRole (roles : Collection <RoleBehavior >): Boolean {
282- return if (roles.isEmpty()) {
283- true
284- } else {
285- val ids = roles.map { it.id }
286- roleIds.any { ids.contains(id) }
287- }
288- }
289-
290287fun Member.getAnyRole (roles : Collection <RoleBehavior >): RoleBehavior ? {
291288 return if (roles.isEmpty()) {
292289 null
0 commit comments