Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/where ojt command #7

Merged
merged 2 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}
}
Loading