sollte funktionieren
This commit is contained in:
parent
1bc2f59e56
commit
fb97202ced
@ -6,7 +6,7 @@ package dev.jansel.feixiao
|
||||
import dev.kord.common.entity.Snowflake
|
||||
import dev.kordex.core.ExtensibleBot
|
||||
import dev.kordex.core.utils.env
|
||||
import dev.jansel.feixiao.extensions.TestExtension
|
||||
import dev.jansel.feixiao.extensions.MessageEvents
|
||||
|
||||
val TEST_SERVER_ID = Snowflake(
|
||||
env("TEST_SERVER").toLong() // Get the test server ID from the env vars or a .env file
|
||||
@ -16,23 +16,8 @@ private val TOKEN = env("TOKEN") // Get the bot' token from the env vars or a
|
||||
|
||||
suspend fun main() {
|
||||
val bot = ExtensibleBot(TOKEN) {
|
||||
chatCommands {
|
||||
defaultPrefix = "?"
|
||||
enabled = true
|
||||
|
||||
prefix { default ->
|
||||
if (guildId == TEST_SERVER_ID) {
|
||||
// For the test server, we use ! as the command prefix
|
||||
"!"
|
||||
} else {
|
||||
// For other servers, we use the configured default prefix
|
||||
default
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extensions {
|
||||
add(::TestExtension)
|
||||
add(::MessageEvents)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,46 @@
|
||||
package dev.jansel.feixiao.extensions
|
||||
|
||||
import dev.kord.common.entity.Permission
|
||||
import dev.kord.common.entity.Snowflake
|
||||
import dev.kord.core.event.message.MessageCreateEvent
|
||||
import dev.kordex.core.annotations.DoNotChain
|
||||
import dev.kordex.core.checks.anyGuild
|
||||
import dev.kordex.core.checks.isNotBot
|
||||
import dev.kordex.core.checks.notHasPermission
|
||||
import dev.kordex.core.checks.notHasRole
|
||||
import dev.kordex.core.extensions.Extension
|
||||
import dev.kordex.core.extensions.event
|
||||
import dev.kordex.core.utils.timeout
|
||||
import java.util.*
|
||||
import kotlin.time.Duration.Companion.days
|
||||
|
||||
class MessageEvents : Extension() {
|
||||
override val name = "messageevents"
|
||||
|
||||
@OptIn(DoNotChain::class)
|
||||
override suspend fun setup() {
|
||||
event<MessageCreateEvent> {
|
||||
check {
|
||||
anyGuild()
|
||||
isNotBot()
|
||||
notHasPermission(Permission.ManageMessages)
|
||||
notHasRole(Snowflake(1130937397132152852))
|
||||
}
|
||||
action {
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.time = Date()
|
||||
val hour = calendar.get(Calendar.HOUR_OF_DAY)
|
||||
val day = calendar.get(Calendar.DAY_OF_WEEK)
|
||||
if ((day == Calendar.MONDAY && hour < 6) || (day == Calendar.MONDAY && hour >= 22) ||
|
||||
(day == Calendar.TUESDAY && hour < 6) || (day == Calendar.TUESDAY && hour >= 22) ||
|
||||
(day == Calendar.WEDNESDAY && hour < 6) || (day == Calendar.WEDNESDAY && hour >= 22) ||
|
||||
(day == Calendar.THURSDAY && hour < 6) || (day == Calendar.THURSDAY && hour >= 22) ||
|
||||
(day == Calendar.FRIDAY && hour < 6) || (day == Calendar.SUNDAY && hour >= 22)
|
||||
) {
|
||||
event.message.delete()
|
||||
event.member!!.timeout(7.days, "ES HERRSCHT RUHEZEIT!")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,130 +0,0 @@
|
||||
package dev.jansel.feixiao.extensions
|
||||
|
||||
import dev.kordex.core.commands.Arguments
|
||||
import dev.kordex.core.commands.converters.impl.coalescingDefaultingString
|
||||
import dev.kordex.core.commands.converters.impl.defaultingString
|
||||
import dev.kordex.core.commands.converters.impl.user
|
||||
import dev.kordex.core.components.components
|
||||
import dev.kordex.core.components.publicButton
|
||||
import dev.kordex.core.extensions.Extension
|
||||
import dev.kordex.core.extensions.chatCommand
|
||||
import dev.kordex.core.extensions.publicSlashCommand
|
||||
import dev.kordex.core.utils.respond
|
||||
import dev.jansel.feixiao.TEST_SERVER_ID
|
||||
|
||||
class TestExtension : Extension() {
|
||||
override val name = "test"
|
||||
|
||||
override suspend fun setup() {
|
||||
chatCommand(::SlapArgs) {
|
||||
name = "slap"
|
||||
description = "Ask the bot to slap another user"
|
||||
|
||||
check { failIf(event.message.author == null) }
|
||||
|
||||
action {
|
||||
// Don't slap ourselves on request, slap the requester!
|
||||
val realTarget = if (arguments.target.id == event.kord.selfId) {
|
||||
message.author!!
|
||||
} else {
|
||||
arguments.target
|
||||
}
|
||||
|
||||
message.respond("*slaps ${realTarget.mention} with their ${arguments.weapon}*")
|
||||
}
|
||||
}
|
||||
|
||||
chatCommand {
|
||||
name = "button"
|
||||
description = "A simple example command that sends a button."
|
||||
|
||||
check { failIf(event.message.author == null) }
|
||||
|
||||
action {
|
||||
message.respond {
|
||||
components {
|
||||
publicButton {
|
||||
label = "Button!"
|
||||
|
||||
action {
|
||||
respond {
|
||||
content = "You pushed the button!"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publicSlashCommand(::SlapSlashArgs) {
|
||||
name = "slap"
|
||||
description = "Ask the bot to slap another user"
|
||||
|
||||
guild(TEST_SERVER_ID) // Otherwise it will take up to an hour to update
|
||||
|
||||
action {
|
||||
// Don't slap ourselves on request, slap the requester!
|
||||
val realTarget = if (arguments.target.id == event.kord.selfId) {
|
||||
member
|
||||
} else {
|
||||
arguments.target
|
||||
}
|
||||
|
||||
respond {
|
||||
content = "*slaps ${realTarget?.mention} with their ${arguments.weapon}*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publicSlashCommand {
|
||||
name = "button"
|
||||
description = "A simple example command that sends a button."
|
||||
|
||||
action {
|
||||
respond {
|
||||
components {
|
||||
publicButton {
|
||||
label = "Button!"
|
||||
|
||||
action {
|
||||
respond {
|
||||
content = "You pushed the button!"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class SlapArgs : Arguments() {
|
||||
val target by user {
|
||||
name = "target"
|
||||
description = "Person you want to slap"
|
||||
}
|
||||
|
||||
val weapon by coalescingDefaultingString {
|
||||
name = "weapon"
|
||||
|
||||
defaultValue = "large, smelly trout"
|
||||
description = "What you want to slap with"
|
||||
}
|
||||
}
|
||||
|
||||
inner class SlapSlashArgs : Arguments() {
|
||||
val target by user {
|
||||
name = "target"
|
||||
description = "Person you want to slap"
|
||||
}
|
||||
|
||||
// Slash commands don't support coalescing strings
|
||||
val weapon by defaultingString {
|
||||
name = "weapon"
|
||||
|
||||
defaultValue = "large, smelly trout"
|
||||
description = "What you want to slap with"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user