-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from TNCT-Mechatech/feature/where-ojt-command
Feature/where ojt command
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/dev/t7e/mechatechkt/commands/WhereOJTChannelCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |