Skip to content

Commit f5ac055

Browse files
committed
3.0.5: Check permissions for slash commands too.
1 parent 05594c6 commit f5ac055

File tree

4 files changed

+21
-26
lines changed

4 files changed

+21
-26
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group 'me.devoxin'
8-
version '3.0.4'
8+
version '3.0.5'
99

1010
repositories {
1111
maven {

src/main/kotlin/me/devoxin/flight/api/CommandClient.kt

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,24 +224,21 @@ class CommandClient(
224224
}
225225

226226
if (ctx.isFromGuild) {
227-
if (ctx is MessageContext) {
228-
if (props.userPermissions.isNotEmpty()) {
229-
val userCheck =
230-
props.userPermissions.filterNot { ctx.member!!.hasPermission(ctx.guildChannel!!, it) }
231-
232-
if (userCheck.isNotEmpty()) {
233-
dispatchSafely { it.onUserMissingPermissions(ctx.asMessageContext!!, cmd, userCheck) }
234-
return false
235-
}
227+
if (props.userPermissions.isNotEmpty()) {
228+
val userCheck = props.userPermissions.filterNot { ctx.member!!.hasPermission(ctx.guildChannel!!, it) }
229+
230+
if (userCheck.isNotEmpty()) {
231+
dispatchSafely { it.onUserMissingPermissions(ctx, cmd, userCheck) }
232+
return false
236233
}
234+
}
237235

238-
if (props.botPermissions.isNotEmpty()) {
239-
val botCheck = props.botPermissions.filterNot { ctx.guild!!.selfMember.hasPermission(ctx.guildChannel!!, it) }
236+
if (props.botPermissions.isNotEmpty()) {
237+
val botCheck = props.botPermissions.filterNot { ctx.guild!!.selfMember.hasPermission(ctx.guildChannel!!, it) }
240238

241-
if (botCheck.isNotEmpty()) {
242-
dispatchSafely { it.onBotMissingPermissions(ctx.asMessageContext!!, cmd, botCheck) }
243-
return false
244-
}
239+
if (botCheck.isNotEmpty()) {
240+
dispatchSafely { it.onBotMissingPermissions(ctx, cmd, botCheck) }
241+
return false
245242
}
246243
}
247244

src/main/kotlin/me/devoxin/flight/api/hooks/CommandEventAdapter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ interface CommandEventAdapter {
8181
/**
8282
* Invoked when a user lacks permissions to execute a command
8383
*/
84-
fun onUserMissingPermissions(ctx: MessageContext, command: CommandFunction, permissions: List<Permission>)
84+
fun onUserMissingPermissions(ctx: Context, command: CommandFunction, permissions: List<Permission>)
8585

8686
/**
8787
* Invoked when the bot lacks permissions to execute a command
8888
*/
89-
fun onBotMissingPermissions(ctx: MessageContext, command: CommandFunction, permissions: List<Permission>)
89+
fun onBotMissingPermissions(ctx: Context, command: CommandFunction, permissions: List<Permission>)
9090
}

src/main/kotlin/me/devoxin/flight/api/hooks/DefaultCommandEventAdapter.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import net.dv8tion.jda.api.Permission
99
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
1010

1111
open class DefaultCommandEventAdapter : CommandEventAdapter {
12-
override fun onCheckFailed(ctx: Context, command: CommandFunction, checkType: CheckType) {
13-
}
12+
override fun onCheckFailed(ctx: Context, command: CommandFunction, checkType: CheckType) = Unit
1413

1514
override fun onBadArgument(ctx: Context, command: CommandFunction, error: BadArgument) {
1615
error.printStackTrace()
@@ -20,7 +19,7 @@ open class DefaultCommandEventAdapter : CommandEventAdapter {
2019
error.printStackTrace()
2120
}
2221

23-
override fun onCommandPostInvoke(ctx: Context, command: CommandFunction, failed: Boolean) {}
22+
override fun onCommandPostInvoke(ctx: Context, command: CommandFunction, failed: Boolean) = Unit
2423

2524
override fun onCommandPreInvoke(ctx: Context, command: CommandFunction) = true
2625

@@ -32,12 +31,11 @@ open class DefaultCommandEventAdapter : CommandEventAdapter {
3231
error.printStackTrace()
3332
}
3433

35-
override fun onCommandCooldown(ctx: Context, command: CommandFunction, cooldown: Long) {}
34+
override fun onCommandCooldown(ctx: Context, command: CommandFunction, cooldown: Long) = Unit
3635

37-
override fun onBotMissingPermissions(ctx: MessageContext, command: CommandFunction, permissions: List<Permission>) {}
36+
override fun onBotMissingPermissions(ctx: Context, command: CommandFunction, permissions: List<Permission>) = Unit
3837

39-
override fun onUserMissingPermissions(ctx: MessageContext, command: CommandFunction, permissions: List<Permission>) {}
38+
override fun onUserMissingPermissions(ctx: Context, command: CommandFunction, permissions: List<Permission>) = Unit
4039

41-
override fun onUnknownCommand(event: MessageReceivedEvent, command: String, args: List<String>) {
42-
}
40+
override fun onUnknownCommand(event: MessageReceivedEvent, command: String, args: List<String>) = Unit
4341
}

0 commit comments

Comments
 (0)