Skip to content

Commit

Permalink
Update Discord4J, add /yarn /mcp /mmi /mms and fix RunTrickCommand re…
Browse files Browse the repository at this point in the history
…quiring the args

Signed-off-by: shedaniel <[email protected]>
  • Loading branch information
shedaniel committed Jan 12, 2022
1 parent e977a41 commit 08dd3a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dependencies {
implementation("me.shedaniel:linkie-core:1.0.92") {
exclude module: "korio"
}
discord_apiImplementation("com.github.Discord4J.Discord4J:discord4j-core:c25f7e1") {
discord_apiImplementation("com.github.Discord4J.Discord4J:discord4j-core:c8b1738") {
force = true
}
// compile("com.github.shadorc.discord4j:discord4j-core:217336e") {
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/me/shedaniel/linkie/discord/LinkieBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fun registerCommands(commands: CommandManager) {
commands.registerCommand(false, QueryMappingsCommand(null, MappingsEntryType.METHOD), "m", "method")
commands.registerCommand(false, QueryMappingsCommand(null, MappingsEntryType.FIELD), "f", "field")

commands.registerCommand(false, QueryMappingsCommand(Namespaces["yarn"], *MappingsEntryType.values()), "y", "yarn")
commands.registerCommand(QueryMappingsCommand(Namespaces["yarn"], *MappingsEntryType.values()), listOf("y", "yarn"), listOf("yarn"))
commands.registerCommand(false, QueryMappingsCommand(Namespaces["yarn"], MappingsEntryType.CLASS), "yc", "yarnc")
commands.registerCommand(false, QueryMappingsCommand(Namespaces["yarn"], MappingsEntryType.METHOD), "ym", "yarnm")
commands.registerCommand(false, QueryMappingsCommand(Namespaces["yarn"], MappingsEntryType.FIELD), "yf", "yarnf")
Expand All @@ -224,7 +224,7 @@ fun registerCommands(commands: CommandManager) {
commands.registerCommand(false, QueryMappingsCommand(Namespaces["yarrn"], MappingsEntryType.METHOD), "yrm", "yarrnm")
commands.registerCommand(false, QueryMappingsCommand(Namespaces["yarrn"], MappingsEntryType.FIELD), "yrf", "yarnrf")

commands.registerCommand(false, QueryMappingsCommand(Namespaces["mcp"], *MappingsEntryType.values()), "mcp")
commands.registerCommand(QueryMappingsCommand(Namespaces["mcp"], *MappingsEntryType.values()), "mcp")
commands.registerCommand(false, QueryMappingsCommand(Namespaces["mcp"], MappingsEntryType.CLASS), "mcpc")
commands.registerCommand(false, QueryMappingsCommand(Namespaces["mcp"], MappingsEntryType.METHOD), "mcpm")
commands.registerCommand(false, QueryMappingsCommand(Namespaces["mcp"], MappingsEntryType.FIELD), "mcpf")
Expand All @@ -236,12 +236,12 @@ fun registerCommands(commands: CommandManager) {
commands.registerCommand(false, QueryMappingsCommand(Namespaces["plasma"], MappingsEntryType.METHOD), "plasmam", "plm")
commands.registerCommand(false, QueryMappingsCommand(Namespaces["plasma"], MappingsEntryType.FIELD), "plasmaf", "plf")

commands.registerCommand(false, QueryMappingsCommand(Namespaces["mojang"], *MappingsEntryType.values()), "mmi", "mojmapi")
commands.registerCommand(QueryMappingsCommand(Namespaces["mojang"], *MappingsEntryType.values()), listOf("mmi", "mojmapi"), listOf("mmi"))
commands.registerCommand(false, QueryMappingsCommand(Namespaces["mojang"], MappingsEntryType.CLASS), "mmic", "mojmapic")
commands.registerCommand(false, QueryMappingsCommand(Namespaces["mojang"], MappingsEntryType.METHOD), "mmim", "mojmapim")
commands.registerCommand(false, QueryMappingsCommand(Namespaces["mojang"], MappingsEntryType.FIELD), "mmif", "mojmapim")

commands.registerCommand(false, QueryMappingsCommand(Namespaces["mojang_srg"], *MappingsEntryType.values()), "mms", "mojmaps")
commands.registerCommand(QueryMappingsCommand(Namespaces["mojang_srg"], *MappingsEntryType.values()), listOf("mms", "mojmaps"), listOf("mms"))
commands.registerCommand(false, QueryMappingsCommand(Namespaces["mojang_srg"], MappingsEntryType.CLASS), "mmsc", "mojmapsc")
commands.registerCommand(false, QueryMappingsCommand(Namespaces["mojang_srg"], MappingsEntryType.METHOD), "mmsm", "mojmapsm")
commands.registerCommand(false, QueryMappingsCommand(Namespaces["mojang_srg"], MappingsEntryType.FIELD), "mmsf", "mojmapsm")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ open class QueryMappingsCommand(
) : Command {
override suspend fun SlashCommandBuilderInterface.buildCommand(slash: Boolean) {
if (slash) {
(sequenceOf("all") + MappingsEntryType.values().asSequence().map { it.name.toLowerCase() }).forEach { type ->
subGroup(type, "Queries mappings for the '$type' type") {
buildNamespaces(slash, if (type == "all") MappingsEntryType.values() else arrayOf(MappingsEntryType.valueOf(type.toUpperCase())))
if (namespace == null) {
(sequenceOf("all") + MappingsEntryType.values().asSequence().map { it.name.toLowerCase() }).forEach { type ->
subGroup(type, "Queries mappings for the '$type' type") {
buildNamespaces(slash, if (type == "all") MappingsEntryType.values() else arrayOf(MappingsEntryType.valueOf(type.toUpperCase())))
}
}
} else {
buildNamespaces(false, types)
}
} else {
buildNamespaces(slash, types)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import me.shedaniel.linkie.discord.Command
import me.shedaniel.linkie.discord.scommands.SlashCommandBuilderInterface
import me.shedaniel.linkie.discord.scommands.args
import me.shedaniel.linkie.discord.scommands.opt
import me.shedaniel.linkie.discord.scommands.optNullable
import me.shedaniel.linkie.discord.scommands.string
import me.shedaniel.linkie.discord.scripting.ContextExtensions
import me.shedaniel.linkie.discord.scripting.EvalContext
Expand All @@ -33,7 +34,7 @@ object RunTrickCommand : Command {
override suspend fun SlashCommandBuilderInterface.buildCommand(slash: Boolean) {
val trickName = string("trick_name", "Name of the trick")
val args = args(required = false)
executeCommandWithGetter { ctx, options -> execute(ctx, options.opt(trickName), options.opt(args)) }
executeCommandWithGetter { ctx, options -> execute(ctx, options.opt(trickName), options.optNullable(args) ?: mutableListOf()) }
}

suspend fun execute(ctx: CommandContext, trickName: String, args: MutableList<String>) {
Expand Down

0 comments on commit 08dd3a6

Please sign in to comment.