Skip to content

Commit

Permalink
Merge pull request #7 from TNCT-Mechatech/feature/where-ojt-command
Browse files Browse the repository at this point in the history
Feature/where ojt command
  • Loading branch information
testusuke authored Oct 1, 2023
2 parents d16ed34 + ee74fc3 commit a13e4a6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/kotlin/dev/t7e/mechatechkt/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import dev.kord.gateway.PrivilegedIntent
import dev.t7e.mechatechkt.commands.CreateOJTChannelCommand
import dev.t7e.mechatechkt.commands.CreatePrivateChannelCommand
import dev.t7e.mechatechkt.commands.ProgressReportCommand
import dev.t7e.mechatechkt.commands.WhereOJTChannelCommand
import dev.t7e.mechatechkt.config.BotConfig
import dev.t7e.mechatechkt.config.BotStatus
import dev.t7e.mechatechkt.unit.ProgressReport
Expand All @@ -28,7 +29,8 @@ suspend fun main(args: Array<String>) {
val commands = mapOf(
"mentoring" to CreatePrivateChannelCommand,
"shinchoku" to ProgressReportCommand,
"create-ojt" to CreateOJTChannelCommand
"create-ojt" to CreateOJTChannelCommand,
"ojt" to WhereOJTChannelCommand
)

client.createGlobalApplicationCommands {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package dev.t7e.mechatechkt.commands

import dev.kord.core.behavior.interaction.respondEphemeral
import dev.kord.core.entity.interaction.ApplicationCommandInteraction
import dev.kord.rest.builder.interaction.GlobalMultiApplicationCommandBuilder
import dev.kord.rest.builder.interaction.user
import kotlinx.coroutines.flow.toList

/**
* Created by testusuke on 2023/10/01
* @author testusuke
*/
object WhereOJTChannelCommand : CommandHandler {
override suspend fun handle(interaction: ApplicationCommandInteraction) {
val guild = interaction.channel.getGuildOrNull()!!
// get all channel
val channels = guild.channels.toList()

// arguments
val userId = interaction.getOptionSnowflake("user")!!

// get ojt channel
val channel = channels.find {
val description = it.data.topic.value ?: return@find false
description.contains(userId.toString())
}

if (channel == null) {
interaction.respondEphemeral { content = "OJTチャンネルが見つかりませんでした" }
return
}

interaction.respondEphemeral { content = channel.mention }
}

override fun register(builder: GlobalMultiApplicationCommandBuilder) {
builder.input("ojt", "OJTチャンネルを検索します") {
dmPermission = false

user("user", "ユーザー") {
required = true
}
}
}
}

0 comments on commit a13e4a6

Please sign in to comment.