feat: added permission check to SendPlannerExtension

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-06-05 13:22:22 +02:00
parent 6d99022bda
commit 414c48708f

View file

@ -23,7 +23,9 @@ import com.kotlindiscord.kord.extensions.commands.converters.impl.int
import com.kotlindiscord.kord.extensions.extensions.Extension import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import com.kotlindiscord.kord.extensions.types.respond import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.hasPermission
import dev.kord.common.Color import dev.kord.common.Color
import dev.kord.common.entity.Permission
import dev.kord.core.behavior.channel.createMessage import dev.kord.core.behavior.channel.createMessage
import dev.kord.rest.builder.message.create.actionRow import dev.kord.rest.builder.message.create.actionRow
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@ -46,13 +48,19 @@ class SendPlannerExtension : Extension() {
name = "sendplanner" name = "sendplanner"
description = "Send the planner for the current and x next weeks" description = "Send the planner for the current and x next weeks"
this.action { this.action {
if (this.arguments.weeks == 0 || !this.member!!.asMember(this.guild!!.id)
.hasPermission(Permission.Administrator)
) {
val res = this.respond {
this.content = "no."
}
res.delete()
return@action
}
val res = this.respond { val res = this.respond {
this.content = "OK." this.content = "OK."
} }
res.delete() res.delete()
if (this.arguments.weeks == 0) {
return@action
}
val c = this.getChannel().asChannel() val c = this.getChannel().asChannel()
var then = var then =
ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withDayOfMonth(getMondayDayOfMonth()).withHour(4) ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withDayOfMonth(getMondayDayOfMonth()).withHour(4)